avr - Display ADC result on LCD or Terminal using CodevisionAVR -
my project audio spectrum analyzer, stuck in displaying adc results, either on lcd or on terminal of codevisionavr.
the project uses atmega16a, 7.37 mhz external oscillator. ide using codevisionavr.
the audio spectrum analyzer takes input through 3.5 mm jack audio cable, signal amplified , filtered in order select frequencies between 0 , 4 khz, , output of circuit connected pa0, channel 0 of adc of microcontroller.
for testing, have set adc work on 8 bits (read significant 8 bits), taking internal 2.56v voltage reference. have decoupled aref pin using 10nf capacitor (i change 100nf better noise reduction). adc in free running mode.
i stuck in displaying adc results, either on lcd or on terminal of codevisionavr (through uart --- configured using wizard).
this function used adc:
// voltage reference: int., cap. on aref #define adc_vref_type ((1<<refs1) | (1<<refs0) | (1<<adlar)) // read 8 significant bits // of ad conversion result unsigned char read_adc(unsigned char adc_input) { admux=adc_input | adc_vref_type; // delay needed stabilization of adc input voltage delay_us(10); // start ad conversion adcsra|=(1<<adsc); // wait ad conversion complete while ((adcsra & (1<<adif))==0); adcsra|=(1<<adif); return adch; }
main function of code:
void main (void) { init_controller(); // must first "init" action/call! #asm("sei") // enable interrupts lcd_init(16); lcd_gotoxy(0,1); lcd_putsf("audio spectrum"); delay_ms(3000); lcd_clear(); while(true) { wdogtrig(); tcnt1 = 0; //usage of timer1 ocr1a tifr |= 1<<ocf1a; for(i=0;i<n;i++) { while((tifr & (1<<ocf1a)) == 0) putchar(read_adc()); //adc_set[i] = adc_read(); //this second option tifr |= 1<<ocf1a; } //for(i=0; i<n; i++) //printf("adc values: %d \n",adc_set[i]); } //end while loop }
n defined 32 = number of samples in 1 ad conversion.
the first error see using putchar() write number lcd.
the result of read_adc() number, not string of ascii characters. need use sprintf write adc result string buffer, use lcd_putsf() send buffer lcd.
Comments
Post a Comment