Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How can I use ADC8 and ADC9 on a atmega32u4?

Status
Not open for further replies.

Winch

Member
I am trying to use the analog inputs ADC8 and ADC9 on an atmega32u4.
Somehow I am unable to use this analog input as I am used to within oshonsoft?

Has anyone used these inputs before and how do you get them activated?
The inputs ADC0, ADC1 and ADC4 to ADC7 do not cause any problems. But the other inputs just won't respond.

Reading the datasheet it looks like you need to edit the admux registry. Any suggestions?
 
To test I use an Arduino leonardo.

But in the meantime I have found a solution. See my code below.
This is currently working properly.
If anyone has any other suggestions they are always welcome.

Code:
Define CLOCK_FREQUENCY = 16

Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 0
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 6
Define LCD_EREG = PORTC
Define LCD_EBIT = 7
Define LCD_RWREG = PORTD
Define LCD_RWBIT = 0

Define ADC_SAMPLEUS = 50
Define ADC_CLOCK = 7  'ADC input Prescaler Selections = 128
Define ADC_VREF = 1  'AVCC with external capacitor on AREF pin

DDRD.4 = 0  'input ADC8
DDRD.6 = 0  'input ADC9

Dim pot As Word

Lcdinit 0
WaitMs 500

pot = 0

main:

Gosub GetADC_9
    
        Lcdcmdout LcdLine1Home
        Lcdout "Potentiometer"
        Lcdcmdout LcdLine2Home
        Lcdout #pot
        WaitMs 200
        
Goto main
End                                               

GetADC_9:

ADMUX.MUX0 = 1
ADMUX.MUX1 = 0
ADMUX.MUX2 = 0
ADMUX.MUX3 = 0
ADMUX.MUX4 = 0
ADMUX.ADLAR = 1
ADCSRB.MUX5 = 1
ADCSRA.ADEN = 1
ADCSRA.ADSC = 1

    ADC_Read 8, pot

Return
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top