View previous topic :: View next topic |
Author |
Message |
ruth
Joined: 14 Apr 2014 Posts: 11
|
Formula for Current Transducer Model LTS 15 NP |
Posted: Mon Apr 14, 2014 7:42 am |
|
|
I'd like assistance with the formula for reading a current transducer model LTS 15NP with a PIC microcontroller. I'd like to display the results on an LCD, here is the schematic diagram:
http://imagizer.imageshack.us/v2/xq90/841/16mx.png (updated)
This is the code I am using:
Code: |
#include <18F4620.h> // PIC18F4620 HEADER FILE
#fuses HS,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING
#device adc=10 // USE 10 BIT ADC QUANTIZATION
#use delay (clock=20M) // 20 MHZ CRYSTAL
#include <lcd.c> // LCD DISPLAY HEADER FILE
#define VR_AI1 PIN_A0 // VARIABLE RESISTOR
#define LCD_E PIN_D0 // PIN E
#define LCD_RS PIN_D1 // PIN RS
#define LCD_RW PIN_D2 // PIN RW
#define LCD_D4 PIN_D4 // PIN D4
#define LCD_D5 PIN_D5 // PIN D5
#define LCD_D6 PIN_D6 // PIN D6
#define LCD_D7 PIN_D7 // PIN D7
void blinking1(void);
void main()
{
double T,C;
setup_adc(ADC_CLOCK_INTERNAL); // SET INTERNAL CLOCK FOR ADC
setup_adc_ports(AN0_TO_AN1); // SET PORT RA0
set_tris_a(0xFF); // SET ALL PORT A AS INPUT PORT
lcd_init(); // INITIALIZE LCD
lcd_putc("\f....WELCOME.....");
delay_ms(500);
lcd_putc("\f");
lcd_putc("\n...loading...!");
delay_ms(500);
lcd_putc("\f");
lcd_putc("\f....Ready");
delay_ms(300);
while(TRUE)
{
delay_ms(200);
set_adc_channel(0); // POINTS ADC AT CHANNEL 0
delay_us(20); // DELAY TO GET ANALOG VALUE
T=read_adc(); //read analog input 0
C=T;
printf(lcd_putc,"\fVoltage=%f V ",(double)C);
}
} |
The PIC is a PIC18F4620 and I'm using the CCS PCW compiler. The reference voltage I want to set is Vrms=2.56V as that is the output of sensor I obtained without any load. The voltage becomes Vrms=2.58V when the load is applied (kettle with Irms 8.79A). I obtained these readings using an oscilloscope.
By using connect the sensor output direct to oscilloscope, I can get what I expected which is a sine graph with its Vrms is 2.56V. But after I connected the sensor to PIC, the output displayed at the LCD is not a group of sinusoidal readings as show at oscilloscope but more to a group of readings like rectifier waveform (the LCD display value in the range of 0 to 255 but not a group of sine wave readings from -ve value to +ve value as shown in oscilloscope).
Can I have some tips to the correct formula for conversion?
Last edited by ruth on Tue Apr 15, 2014 8:39 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9270 Location: Greensville,Ontario
|
|
Posted: Mon Apr 14, 2014 9:27 am |
|
|
WARNING WARNING WARNING
That PIC( in fact ALL PICs) do NOT read AC voltages !!!!!
PICs are NOT bipolar!!
YOU must convert to the AC source voltage to a DC voltage !!!!!
You need to add additional circuitry between the AC input and the ADC input. This can be a simple diode-R-C network or a specific true AC RMS to DC V chip.How you design is up to you as only you know factors such as specs, funds available,time to complete project,production qty, etc.
hth
jay |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Apr 14, 2014 9:28 am |
|
|
What version of proteus are you using ?
The curve for I-in -> Vout looks pretty simple \ and
remember you only have 10 bits resolution,
device=8 is wrong for using 10 bits !!
And your schematic is well short of being usefully connected to anything. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Apr 14, 2014 10:26 am |
|
|
Is it 4 or 20 mhz? _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
ruth
Joined: 14 Apr 2014 Posts: 11
|
|
Posted: Tue Apr 15, 2014 8:21 am |
|
|
temtronic, so is it possible to read AC voltage without convert to DC? It is because my project need to use instantaneous concept, so i need the instantaneous value to calculate the RMS value.
Asmboy, sorry i am not good in proteus, i just use it to draw so ppl can understand how my hardware look like >< ..Can I know how to find the LTS current transducer in proteus?
Gabriel, i use 20Mhz...sry for the wrong comment i write |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9270 Location: Greensville,Ontario
|
|
Posted: Tue Apr 15, 2014 9:39 am |
|
|
NO !!! Trying to do so will eventually destroy the PIC.
The ADC within the PIC ( all PICs that I know) is NOT designed for AC voltages.
Please read the ADC section of the datasheet, check the 'electrical specs and charts' near the back of the datasheet.
You must either design your own AC to DC interface or use a premade unit( Allegro is one mfr) to allow a PIC to read AC voltages.
hth
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Apr 15, 2014 9:52 am |
|
|
OR you can bias the PIC ADC input to mid-rail, and work with that, and I showed how to do the RMS calculations on this forum recently.
Mike |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 15, 2014 11:56 am |
|
|
actually the OP's question RE: LTS 15
provides a very reasonable way to digitize low frequency AC or
any DC current with a 5V Vref PIC. bipolar even!!
READING the DATASHEET , especially the I->V graph will show why this is so. a very nice part i did not know about till now
- |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9270 Location: Greensville,Ontario
|
|
Posted: Tue Apr 15, 2014 12:08 pm |
|
|
asmboy is right(again !)...
I downloaded the datasheet...seems it is similar to Allegro products that convert an AC current into a DC unipolar voltage so some very simple 'math' can do the job.
sigh
too many new chips....too little time....my head hurts...
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Apr 15, 2014 3:09 pm |
|
|
Sorry Ruth, I had not taken the precaution of checking the data sheet for the current sensor you are using.
So, you already have a biased output to feed into your PIC.
Exactly what measurements are you wanting to make?
From what I can tell you only want an RMS value for an input current at either 50 or 60 Hz.
You seem to be looking to measure up to ~10A RMS.
I then assume you are using the effective 5 turn primary.
Am I correct so far?
Mike |
|
|
ruth
Joined: 14 Apr 2014 Posts: 11
|
|
Posted: Tue Apr 22, 2014 9:29 am |
|
|
Actually my goal is want to display the current used by an electric appliances such as kettle on LCD by using PIC18F4620.
Now I am study about the ADC conversion of my sensor LTS 15NP.
My idea is get the period of 1 cycle and know how many sampling at 1 period of PIC to obtain sampling period and sampling frequency of the PIC so I can estimate the amount of samples that i need to convert the analog input to my PIC.
But i don't know how to find out the period of 1 cycle and know how many sampling at 1 period of PIC.
Can anyone give me some clues about that? thank a lot |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 22, 2014 10:20 am |
|
|
1- record the ADC count when NO AC is being sensed
now connect ac and draw current thru the sensor
2- when new count ( at what ever sample rate you can manage) goes ABOVE the saved -no current value -
and then goes below - you have detected a zero crossing
at that sample time
more samples == better resolution of this crossing. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Apr 22, 2014 10:50 am |
|
|
I outlined in this link how to calculate RMS values by simply averaging.
http://www.ccsinfo.com/forum/viewtopic.php?t=52105&start=45
The way many DMMs designers deal with your timing problem is to assume mains frequency is either 50 or 60Hz.
Their meters sample the input signal for a time which is an integer multiple of both mains periods.
5 whole periods of 50Hz mains is 100ms.
6 whole periods of 60Hz mains is also 100ms.
You could sample at regular intervals for an integer multiple of 100ms.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9270 Location: Greensville,Ontario
|
|
Posted: Tue Apr 22, 2014 11:42 am |
|
|
Expanding Mike's knowledge....
Take 10 readings.
Do an 'olympic' average (toss high and low readings, average the 8 remaining).
Display on LCD.
This gives a real nice 1HZ update on the LCD.
You really do not need to update any faster than that...
hth
jay |
|
|
ruth
Joined: 14 Apr 2014 Posts: 11
|
|
Posted: Sun May 04, 2014 10:21 am |
|
|
may i know it is any method that i can use both of my current sensor (10 bit analog input) and voltage sensor (10 bit analog input) into my PIC which is 10 bit? |
|
|
|