adc conversion

Status
Not open for further replies.

rafey maher

New Member
hi.. i have atmega16 and i have connected a potentiometer on the adc channel0 and want to see the converted or digital data on the computer
so i have made a program in which the adc output is transmitted serially to pc.. but i think there is a problem in the code... can any1 plz rectify it...??

note: asynchronous mode, baud rate 9600, parity bit none, 8 bit character size, division factor 8, stop bit 1.


Code:
clr r23
out $07,r23 //adcmux
ldi r16,$c3
out $06,r16 //adscra
ldi r25,$ff
out $11,r25 //port d as output or txd as output
out $20,r23 //ubrrh data
ldi r17,$16
out $09,r17 //ubrrl data (16)h or (22)d for baud rate 9600
clr r18
out $0b,r18 //ucsra data
ldi r19,$08
out $0a,r19 //ucsrb data
ldi r20,$86
out $20,r20 //ucsrc data
next: sbis $0b,5 //checking for udre
rjmp next
sbi $06,6 //set bit start conversion in adcsra
check: sbis $06,4 // checking for adif in adcsra
rjmp check
lds r27,$04 //read the data from adcl
out $0c,r27 // send the data to udr
sbi $06,4 // set bit adif (reseting the bit actually)
jmp next //repeating
 
Last edited by a moderator:
Every thing seems ok with the UART code. Try this: command the ADC to sample, and then keep checking whether it has finished sampling when finished send the data via UART to the PC. You can use the Hyper Terminal to check your results on the PC. When the UART is finished send sample again and send.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…