Problems with ADC on Atmega32

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
Hammer_marco
Posts: 1
Joined: 11 May 2008 18:52

Problems with ADC on Atmega32

#1 Post by Hammer_marco » 11 May 2008 19:05

I have modified the following code:

program adtest
'
'* Project name:
' adc on lcd
'* Author:
' MikroElektronika, September 2006.
'* Description:
' This program demonstrates how to use ADC library.
'* Test configuration:
' MCU: ATmega128
' Dev.Board: Big AVR
' Oscillator: External, 10 MHz
' Ext. Modules:
' SW: mikroBasic for AVR 4.02
' * NOTES:
' connect potentiometer to MCU
'

Code: Select all

dim dataA,dataB as word
    textA,textB as string[7]
main:
  Lcd_Init(PORTC, 3, 2, PORTC, LCD_HI_NIBBLE)
  Lcd_Cmd(LCD_CURSOR_OFF)
  Lcd_Out(1,1,"Analog Voltage:")
  while true
    ' adc input PORTF.1
    dataA=Adc_Read(1)
    dataB=Adc_Read(0)
    WordToStr(dataA, textA)
    WordToStr(dataB, textB)

    Lcd_Out(2,5, textA)
    Lcd_Out(2,15, textB)
    Delay_ms(10)
  wend
end.
it should give me the AD Value of PortA.0 and PortA.1 on Display it works,
but the both Values have the same content, it makes no different if i choose ADCchannel 0 or ADCCannel1 and so on. The result is always the same Value. If i change the code dataA=Adc_Read(1) with dataB=Adc_Read(0) like this:

Code: Select all

dim dataA,dataB as word
    textA,textB as string[7]
main:
  Lcd_Init(PORTC, 3, 2, PORTC, LCD_HI_NIBBLE)
  Lcd_Cmd(LCD_CURSOR_OFF)
  Lcd_Out(1,1,"Analog Voltage:")
  while true
    ' adc input PORTF.1
    dataB=Adc_Read(0) <---------
    dataA=Adc_Read(1) <---------
    WordToStr(dataA, textA)
    WordToStr(dataB, textB)

    Lcd_Out(2,5, textA)
    Lcd_Out(2,15, textB)
    Delay_ms(10)
  wend
end.
both values have the content of ADC 0.

What did i wrong, please help me i am a beginner in Mikrobasic
thanks for your support !

Post Reply

Return to “mikroBasic for AVR General”