Analog Comparator: PE2 PE3
Analog Comparator: PE2 PE3
(1.26V)
PE2
PE3
Analog Comparator
Analog comparator controlled with two registers SFIOR and ACSR
(1.26V)
PE2
PE3
Analog Comparator
Analog Comparator Control and Status Register (ACSR)
Its used by the brownout detection circuitry and optionally by ADC or comparator.
PF7
PF6
PF5
PF4
PF3
PF2
PF1
PF0
ADC
ADC Power Connections
To keep the digital noise out of the ADC circuitry, it is given its own
power supply pin. This pin has extra decoupling circuitry.
Data registers
-ADCH and ADCL
-Accessed together as ADCW (16-bit access)
-Only need 8-bits?.....,
-left justify, read ADCH, and throw away 2 bits of precision
ADC
ADC clock input
Successive approximation conversion requires a input clock.
To stay under 200khz, must divide 16Mhz clock by 128, giving 125khz
ADC clock.
ADLAR=0
(right justified)
ADLAR=1
(left justified)
ADC
ADC Noise Canceler
-Power-down mode to reduce CPU core digital noise
-MCU Control Register (MCUCR) controls power management
-MCUCR sleep mode bits will cause CPU to enter noise reduction mode
-Stops CPU, I/O clocks, and memory clocks
To use:
-ADC enabled, single conversion mode, interrupts on
-Enter noise reduction mode via MCUCR register (SM2-0 = 001)
-When conversion is done, interrupt wakes up CPU and
ISR(ADC_vect) is executed
Note: Other interrupts can wake up CPU from noise reduction mode
before the ADC conversion is completed.
ADC
ADC as a Voltmeter div_t declares a structure with 2 members:
int main()
.quot and .rem
{
//initialize the SPI port and then the LCD
spi_init();
In this example, fp_adc_result and fp_low_result
lcd_init(); are declared as type div_t.
clear_display();
//Initialize ADC and its ports The operation div(a,b) computes the value a/b and
DDRF &= ~(0x80); //port F bit 7 is ADC input returns the quotient and remainder in .quot and .rem.
PORTF &= ~(0x80); //port F bit 7 pullups are off
while(1){
ADCSRA |= 0x40; //poke ADSC and start conversion
while(bit_is_clear(ADCSRA, ADIF)); //spin while interrupt flag not set
ADCSRA |= (1 << ADIF); //its done, clear flag by writing a one
adc_result = ADCW; //read the ADC output as 16 bits
for(i=0;i<=10;i++){_delay_ms(10);}
clear_display();
cursor_home();
} //while
}//main