ADC on AtMega48PA

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
MadAl
Posts: 2
Joined: 25 Jul 2010 20:13

ADC on AtMega48PA

#1 Post by MadAl » 25 Jul 2010 20:17

Hi,

I tried the following code:

Code: Select all

program ADC_on_LEDs

dim adc_rd as word

main:

  UART1_Init(9600)             '9600 baud UART speed

  while TRUE                        ' endless loop
    adc_rd = ADC_Read(2)    ' get ADC value from 2nd channel
    delay_ms(500)                 'delay to make really sure AD conversion is finished
    UART1_Write(adc_rd)       'output value to terminal
  wend
end.
I measured the voltage on channel 2, and it varies when I rotate the potmeter. The result in the terminal emulator reads 255 and won't change.
MCu and clock speed have been correctly assigned.

Any ideas?

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: ADC on AtMega48PA

#2 Post by tihomir.losic » 27 Jul 2010 15:42

MadAl wrote:I measured the voltage on channel 2, and it varies when I rotate the potmeter. The result in the terminal emulator reads 255 and won't change.
MCu and clock speed have been correctly assigned.

Any ideas?
Hello,

please, look at ATmega48PA datasheet:
http://www.atmel.com/dyn/resources/prod ... pdf#page=2
you can see that this microcontroller has 6-channel 10-bit ADC on PORT C.

So, you need additional potentiometer board to connect on PORT C in order to try your code.
I'll attach you photo of mine EasyAVR6 and Potentiometer board which I used for running this project.
Potentiometer board.png
Potentiometer board.png (301.6 KiB) Viewed 2159 times
Best regards,

Losic Tihomir
mikroElektronika [Support team]

MadAl
Posts: 2
Joined: 25 Jul 2010 20:13

Re: ADC on AtMega48PA

#3 Post by MadAl » 27 Jul 2010 15:55

Hi,

I have a potmeter connected to port C2 (channel 2) so the code should be correct.

I used the very same code in Bascom AVR on this hardware and it works flawlessly.

Also in MikroBasic I tried a simple code to read serial data on the Rx port. Tx works, Rx not.
The same code in Bascom Rx works perfectly.

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: ADC on AtMega48PA

#4 Post by tihomir.losic » 28 Jul 2010 09:27

Hello,

New AVR compilers have arrived. And they are by far the most powerful yet! We have done so much in the previous months,
which resulted in a major compiler revision in both Look-n-Feel (IDE), as well as Under The Hood (compiler itself). Powerful new
SSA optimization now reduces code up to 46%! Some programs that were impossible to run on smaller chips, are now able to fit into
smaller Flash, therefore reducing costs and improving efficiency. We have finally introduced Edit Project option, suitable for in-project
settings of Fuse bits, wish is also supported in new AVRFlash.

Please, download new mikroBasic PRO for AVR, and try your project.
http://www.mikroe.com/download/eng/soft ... 0_beta.zip

Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroBasic PRO for AVR General”