praveenofpersia
Newbie level 2
Is there any problem with the following program???
Iam trying to read IR sensor values using ATMega16's ADC
but the values displayed on the LCD doesn't seem to be the values from the sensors..
The values seems to be fluctuating in all channels(the values on each channel seems to start from 000 then increase from there to 255 Confused I don't think it's displaying the sensor values ), even when a white/black paper is placed in front of a IR TX RX pair ... Sad
also please help me in interpreting the values..
Iam trying to read IR sensor values using ATMega16's ADC
but the values displayed on the LCD doesn't seem to be the values from the sensors..
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #include<avr/io.h> #include<avr/delay.h> #include "lcd.h" void adc_init() { ADCSRA|=(1<<ADEN)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);//prescalar of 128 ADMUX|=(1<<REFS0)|(1<<ADLAR); } uint16_t adc_value(uint8_t ch) { ADMUX&=~0X0F; ch&=0x07; ADMUX|=ch; ADCSRA|=(1<<ADSC); while(ADCSRA&_BV(ADSC)); return (ADCH); } int main() { uint16_t pa0,pa1,pa2,pa3,pa4,pa5,pa6,pa7; InitLCD(0); LCDClear(); adc_init(); _delay_ms(50); while(1) { pa0=adc_value(0); pa1=adc_value(1); pa2=adc_value(2); pa3=adc_value(3); pa4=adc_value(4); pa5=adc_value(5); pa6=adc_value(6); pa7=adc_value(7); LCDGotoXY(0,0); LCDWriteInt(pa0,3); _delay_ms(2500); LCDGotoXY(4,0); LCDWriteInt(pa1,3); _delay_ms(2500); LCDGotoXY(8,0); LCDWriteInt(pa2,3); _delay_ms(2500); LCDGotoXY(12,0); LCDWriteInt(pa3,3); _delay_ms(2500); LCDGotoXY(0,1); LCDWriteInt(pa4,3); _delay_ms(2500); LCDGotoXY(4,1); LCDWriteInt(pa5,3); _delay_ms(2500); LCDGotoXY(8,1); LCDWriteInt(pa6,3); _delay_ms(2500); LCDGotoXY(12,1); LCDWriteInt(pa7,3); _delay_ms(2500); _delay_ms(50); } return 1; }
The values seems to be fluctuating in all channels(the values on each channel seems to start from 000 then increase from there to 255 Confused I don't think it's displaying the sensor values ), even when a white/black paper is placed in front of a IR TX RX pair ... Sad
also please help me in interpreting the values..