I try to use Analog Comparator on ATTiny461A. The voltage of the AIN1 changes according to below table.
I/P Normal Left Right
AIN0 (Pin 12) NEG 2.5v 2.5V 2.5V
AIN1 (Pin 11) POS 2.5V 2.1V 2.6V
AC0 0 1
I wish to compare AIN1 to AIN0. If AIN1 voltage more than AIN0, AC0 to be set.
I try to get below code work, but there isnt any response on the output pin. i attached the datasheet table.
#include <avr/io.h> void port_init() { DDRA |= (1<<PINA6) | (1<<PINA7); //AIN0 AND AIN1 AS INPUT DDRB |= (1<<PINB4)| (1<<PINB6);//OUTPUT PINS } void AC_Init(){ ACSRA = 0b00000000; ACSRB = 0b00000010; //ain0 as negative input, ain1 as positive } int main(void) { port_init(); AC_Init(); while (1) { if ((ACSRA & 0X20) == 1) { PORTB |= (1 << PINB6); //PINB6 HIGH PORTB &= ~(1 << PINB4); //PINB4 LOW } else { PORTB &= ~(1 << PINB6); //PINB6 LOW PORTB |= (1 << PINB4); //PINB4 HIGH } } }
Is there anything else I need to set on the ACSRA, ACSRB register or ADCSRA register ?
I have try set ADEN to zero, it doesnt work too. Any help is much appreciated.