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.

adc using atmega16 controller

Status
Not open for further replies.

santhoshb

Newbie level 1
Joined
Sep 4, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
can any one help me to use an adc in atmega16
and also tell me the basic steps to program .......

thanks in advance
 

Hi
It is really helpful for you to take a look at its datasheet,you'll get what you want
Simply to say,firstly you should initial some registers to set the voltage reference,divider,operating mode,etc.Then after you enable the ADC,you can read the data from ADCL and ADCH.

Good luck!
 

Hi,
Code to read from channel 0 and display on PORTB and PORTD.
Code:
program ADC_Test

main:
     DDRB = $FF
     DDRD = $FF
     DDRC = 0
     ADMUX = 0
     DIDR0 = $3F
     ADCSRA = $85 
     while true
           ADCSRA.ADCS = 1
           while (ADCSRA.ADCS)
           wend
           PORTB = ADCL
           PORTD = ADCH
           delay_ms(2)
     wend
end.

Code to read from channel 0 and show on LCD:
Code:
program ADC_LCD

symbol RW = PORTB.B1
symbol RW_Direction = DDRB.B1

dim LCD_RS as sbit at PORTB2_bit
dim LCD_EN as sbit at PORTB3_bit
dim LCD_D4 as sbit at PORTB4_bit
dim LCD_D5 as sbit at PORTB5_bit
dim LCD_D6 as sbit at PORTB6_bit
dim LCD_D7 as sbit at PORTB7_bit

dim LCD_RS_Direction as sbit at DDB2_bit
dim LCD_EN_Direction as sbit at DDB3_bit
dim LCD_D4_Direction as sbit at DDB4_bit
dim LCD_D5_Direction as sbit at DDB5_bit
dim LCD_D6_Direction as sbit at DDB6_bit
dim LCD_D7_Direction as sbit at DDB7_bit

dim Value as longword
dim Disp as word[3]
dim sValue as string[5]
dim sDisp as string[5]

main:
     RW_Direction = 1
     RW = 0
     LCD_Init()
     LCD_Cmd(_LCD_CLEAR)
     LCD_Cmd(_LCD_CURSOR_OFF)
     LCD_Out(1, 1, "Reading:")
     LCD_Out(2, 1, "Voltage:")
     sDisp = "4.99V"
     while true
           Value = ADC_Read(0)
           WordToStr(Value, sValue)
           LCD_Out(1, 10, sValue)
           Value = (Value * 500) >> 10
           Disp[0] = (Value div 100) + 48
           Disp[1] = ((Value div 10) mod 10) + 48
           Disp[2] = (Value mod 10) + 48
           sDisp[0] = Disp[0]
           sDisp[2] = Disp[1]
           sDisp[3] = Disp[2]
           LCD_Out(2, 10, sDisp)
     wend
end.

Code to read and show using ADC interrupt:
Code:
program ADC_int

dim done as byte

sub procedure ADC_Int() org $015
    PORTB = ADCH
end sub

sub procedure TMR0_Int() org $010
    ADCSRA.ADSC = 1 'ADCSRA.ADSC 'START CONVERSION
end sub

main:
     DDRB = $FF 'ALL OUTPUT
     DDRC = 0 'ALL INPUT
     TCCR0A = 0 'NORMAL OPERATION
     TCCR0B = 3 'PRESCALER 64
     SREG = $80 'GIE
     TIMSK0 = 1 'ENABLE TMR0 INTERRUPT
     ADMUX = $20 '8-bit, CH0
     DIDR0 = $3F 'ALL ANALOG
     ADCSRA = $8D 'ADC ON, INTERRUPT ENABLED, FOSC/64
     while true
     wend
end.

All codes are in mikroBASIC. You should download the datasheet, go to ADC and have the codes in front of you and then you will be quite clear on the topic.
Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top