View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
ADC_Value vs o\p display on 16*2 LCD |
Posted: Sun Jan 01, 2012 12:19 pm |
|
|
Now I'm using like this:
Code: |
/* 16F676 Configuration
O = Output, I = Input
2.2K
_________ |-----------------^^^--
Vdd | 1 14 | Vss | 4.7K
(O) L1 <-- RA5 | 2 13 | AN0 <-- I\P V_Sense (I)--^^^--<|-- up to 15 V AC
(O) L2 <-- RA4 | 3 12 | AN1 <-- O\P Volt_Sense (I) 1N4007
(I) SW1 --> MCLR | 4 11 | RA2 --> NC (O)
(O) RS <-- RC5 | 5 10 | RC0 --> DB4 (O)
(O) E <-- RC4 | 6 9 | RC1 --> DB5 (O)
(O) DB7 <-- RC3 | 7 8 | RC2 --> DB6 (O)
---------
*/
/*****************************************************************************
Function ProcessMains
Reads ADC_Value and etc
****************************************************************************/
int ProcessMains(void)
{
set_adc_channel(0); // Select AN0
delay_ms(ADC_DELAY); //Charge capacitor
read_adc(ADC_START_ONLY); //Do A/D conversion
done == adc_done();
while(!done) {
done = adc_done();
}
temp_result += read_adc(); // Read A/D register . Pin A0 in an input
delay_ms(ADC_2TAD); // Wait 2 TADs before doing another A/D conversion
ADC_Value = temp_result / ADC_AVERAGE_COUNT;
tlong = (int32)ADC_Value*500; //Convert the result in millivolts
tlong = tlong/1023; // 0..1023 -> 0-5000mV
volt = tlong; // Extract volts (thousands of millivolts 250mv = 250volt
}
lcd_init();
lcd_putc("\fVOLT =volt \n");
lcd_putc("I\P Volt"); |
Now anybody clear me, Value volt which display on 16*2 LCD are RMS VALUE or peak to peak VALUE?
Quote: | volt = tlong; // Extract volts (thousands of millivolts 250mv = 250volt |
_________________ sahu |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jan 01, 2012 12:33 pm |
|
|
is that for real??? up to 15v AC thru a 4.7 k resistor ??
how are you expecting the PIC to deal with that signal? |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sun Jan 01, 2012 12:53 pm |
|
|
asmboy wrote: |
is that for real??? up to 15v AC thru a 4.7 k resistor ??
how are you expecting the PIC to deal with that signal? |
yes its real via step down tx.
pls right now ignore any hardware mistake.
clear me only ---
Value volt which display on 16*2 LCD are RMS VALUE or peak to peak VALUE? _________________ sahu |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Jan 01, 2012 3:46 pm |
|
|
You will get the instantaneous voltage at the time the A/D samples. If you synchronize your A/D readings with the AC cycle you can get Peak readings. If you get the + peak and the - peak you can calculate the peak to peak value. To synchronize the PIC you usually use a "Zero Crossing Detector" circuit.
To get RMS you need to take many samples each cycle, then Square them, calculate the Mean over some time period, then take the square Root.
Note that the PIC A/D can not read negative instantaneous voltages. Your 4.7K & 2.2K divider will scale the positive voltages, but the negative ones will read as zero. As shown the negative 15 AC cycle would put 3mA into the PIC protection diode which is not a good idea. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Mon Jan 02, 2012 10:54 am |
|
|
Please anybody sages me- how I can find true RMS value ? _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jan 02, 2012 11:18 am |
|
|
SherpaDoug has very nicely explained the procedure for you.
Since only you control the design/build of the hardware, it's up to you to create the code you need. We can only offer limited help, not actual code as what we create will only work on our equipment. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Mon Jan 02, 2012 12:46 pm |
|
|
temtronic wrote: | SherpaDoug has very nicely explained the procedure for you.
Since only you control the design/build of the hardware, it's up to you to create the code you need. We can only offer limited help, not actual code as what we create will only work on our equipment. |
oho oho no sir not need me complete code . need only
correction for this code
Code: | set_adc_channel(0); // Select AN0
delay_ms(ADC_DELAY); //Charge capacitor
read_adc(ADC_START_ONLY); //Do A/D conversion
done == adc_done();
while(!done) {
done = adc_done();
}
temp_result += read_adc(); // Read A/D register . Pin A0 in an input
delay_ms(ADC_2TAD); // Wait 2 TADs before doing another A/D conversion
ADC_Value = temp_result / ADC_AVERAGE_COUNT;
tlong = (int32)ADC_Value*500; //Convert the result in millivolts
tlong = tlong/1023; // 0..1023 -> 0-5000mV
volt = tlong; // Extract volts (thousands of millivolts 250mv = 250volt |
which give Mean OR RMS VALUE .
sorry my bad English _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jan 02, 2012 12:50 pm |
|
|
ADC_value is already an average or mean value.
from your code...
ADC_Value = temp_result / ADC_AVERAGE_COUNT;
You cannot get RMS value as you are not sampling the input AC voltage correctly. You MUST do all of what SherpaDoug has said before if you want RMS value.
Five easy steps to sucess. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jan 02, 2012 5:23 pm |
|
|
To get RMS (Root of the Mean Square) you must square the values BEFORE you average them. How long you average for depends on how fast a response you need versus noise immunity. You also want to average over complete cycles. Many meters that measure 50 or 60Hz use 100ms. That is 5 complete cycles at 50Hz or 6 at 60Hz. Then you take the square root.
Of course you will also have to alter your hardware to accurately read the negative half of the AC cycle. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Jan 07, 2012 9:41 am |
|
|
now today i found 1 new problem ....
problem as Code: | ADC_Value = temp_result / ADC_AVERAGE_COUNT;
tlong = (int32)ADC_Value*500; //Convert the result in millivolts
tlong = tlong/1023; // 0..1023 -> 0-5000mV
volt = tlong; // Extract volts (thousands of millivolts 250mv = 250volt
}
lcd_init();
lcd_putc("\fVOLT = volt \n");
lcd_putc("I\P Volt"); |
volt is a numeric ,but lcd display volt word .
I'm use flex_lcd.c as lcd driver .
now clear me where i wrong ? _________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Jan 07, 2012 10:08 am |
|
|
Read a book on C?.....
You are sending the string 'VOLT = volt', which is what will be displayed.....
Look in the printf manual, in particular at the '%' operator, and it's formats.
Best Wishes |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Jan 07, 2012 10:17 am |
|
|
Ttelmah wrote: | Read a book on C?.....
You are sending the string 'VOLT = volt', which is what will be displayed.....
Look in the printf manual, in particular at the '%' operator, and it's formats.
Best Wishes |
it is right Code: | LCD_PutChar("INPUT= "%ld ",volt"); | ?
? _________________ sahu |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Jan 07, 2012 10:56 am |
|
|
While your project is open, press F11 to access the CCS C Onscreen HELP files !!
OR
LOOK at any of the examples that CCS kindly supplies to SHOW you HOW to use this compiler.
What you need to know is given there. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Jan 07, 2012 11:01 am |
|
|
temtronic wrote: | LOOK at any of the examples that CCS kindly supplies to SHOW you HOW to use this compiler.
What you need to know is given there. |
i was also try it but not found my ans . _________________ sahu |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Jan 07, 2012 12:22 pm |
|
|
You should be using lcd_putc in a printf statement.
The CCS Example file EX_LCDTH.C shows how it should be done..
There is another example in the current manual on page 216 under printf _________________ Google and Forum Search are some of your best tools!!!! |
|
|
|