-
Primarily, I am an assembly language programmer for ATmega32.
-
Now, I am trying to switch over to ArduinoUNO C platform.
-
My issue: Single Conversion Mode for Ch-0 of the internal ADC of ATmega328.
-
To operate Ch-0 in Single Conversion Mode, we write ASM codes for the following steps:
a. LL --> PRADC bit of PRR-register : ADC is connected with power supply
b. LH --> ADEN bit of ADCSRA : ADC is enabled
LL --> ADCSC bit of ADCSRA : ADC is not started
LL --> ADATE bit of ADCSRA : Auto Triggering OFF
LL --> ADIF bit of ADCSRA : ADC Interrupt Flag cleared
LL --> ADIE bit of ADCSRA : ADC Interrupt is disabled
c. [0, 1] --> [REFS1, REFS0] of ADMUX : VREF of ADC is AVcc (+5V)
0 --> ADLAR bit of ADMUX : ADC result is right adjusted
[0, 0, 0, 0] --> [MUX3:MUX0] : ADC Channel-0 is selected
d. LH --> ADCSC bit of ADCSRA : Start the ADC
e. Wait here until conversion is complete by polling ADSC-bit for LL or ADIF-bit for LH
f. LL --> ADIF bit of ADCSRA if ADIF-bit was being polled in Step-e
g. Read ADCL : Read Lower 8-bit first
Read ADCH : Read upper 2-bit (six 0s are automatically inserted at upper bits) -
In Arduino C, we write only the following two function:
analogReference(DEFAULT);
x = analogRead(0); -
My questions:
a. Do the two functions of Step-5 substitute all the instructions of Step-4?
b. Is there any header file (like #include <avr/adc.h> that contains the function prototypes and the
definitions of the symbols? -
Thanks in advance.
You have the source for both analogReference and analogRead.
a) NO.
b) Yes there are files you have to look inside and compare with yours. The wiring.c - some settings in the init(), wiring_analog.c - the rest.
Irrespective to Arduino's setup you can modify the registers etc. for your needs and use "advanced techniques" alongside with Arduino functions but do not forget that e.g. the changes in ADC could have an influence to functions like analogRead, analogWrite.