Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Saving last two samples of ADC readings....

Status
Not open for further replies.

armghan11

Member level 1
Member level 1
Joined
Oct 9, 2012
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,557
Saving latest two samples of ADC readings....

I am working on a non intrusive load monitoring system i want my micro controller to reads the analogue input of the ADC then this input is normalized to remove the values in points because the micro controller cannot store values which are after decimal point. So to save important information being discarded the values are multiplied by 100. after that i want micro controller keeps the latest two samples. After normalization of the sample, it is subtracted from the previous sample. If the difference is positive, it show it on LCD.

I am attaching a flow chart below it might help you... i want help in saving samples of adc... i work on ccs c compiler
 

Attachments

  • flowchart.jpg
    flowchart.jpg
    72 KB · Views: 113
Last edited:

I am not quite sure exactly what your problem is.

You need to have two variables - new_ADC and old_ADC for example. Before entering your loop you need to read the ADC and store it in old_ADC.

Once in the loop you need to read the ADC - this is new_ADC - and do your comparison. Then store new_ADC into old_ADC ready for the next time round the loop.

Keith.
 

I am not quite sure exactly what your problem is.

You need to have two variables - new_ADC and old_ADC for example. Before entering your loop you need to read the ADC and store it in old_ADC.

Once in the loop you need to read the ADC - this is new_ADC - and do your comparison. Then store new_ADC into old_ADC ready for the next time round the loop.

Keith.

i just want to store latest two adc samples and do a comparison and after that it again take latest two sample that how the loop continues
check out the flowchart it might help
 

here is the c code i made... but it isnt working properly :(
Code:
#include <16F877a.H> 
#device adc=10 
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#include <lcd2.c>

char look(int a)
{
switch(a)
{
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
default:
return '.';
}
}

void main()
{
unsigned int16 new_adc,old_adc;
lcd_init(); 
setup_adc_ports(ALL_Analog); 
setup_adc(ADC_CLOCK_DIV_8); 
set_adc_channel(3);
delay_us(20);
old_adc= read_ADC();
old_adc = (old_adc * 4.89)/0.47;
Char *current = "0.00";
Char *current1= "0.00";
do
{
delay_us(20);
new_adc = read_ADC();
new_adc = (new_adc * 4.89)/0.47;
if ( new_adc  > Old_adc) {
int16 k;
k = new_adc - old_adc;
current1[0] = look(k/1000);
current1[2] = look((k/100)%10);
current1[3] = look((k/10)%10);
lcd_gotoxy(1,2);
printf(LCD_PUTC,"L1=%s",current);
lcd_gotoxy(9,2);
printf(LCD_PUTC,"L2=%s",current1);
        }
else
        {
current[0] = look(new_adc/1000);
current[2] = look((new_adc/100)%10);
current[3] = look((new_adc/10)%10);
lcd_gotoxy(1,2);
printf(LCD_PUTC, "L1=%s",current);
        }
Delay_ms(250);
old_adc = new_adc;
} while(1);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top