I already know that the problems with the Arduino uno's internal comparator come from the lack
of hysteresis. So I used an ATtiny1614, which has a comparator with hysteresis.
I started testing the comparator with the simplest possible case. I apply voltages to its
inputs (+) and (-) and look at the output result - whether the LED lights up or
not depending on the relationship of the voltages at (+) and (-). But I don't see
any response from the comparator. I have tried everything and nothing. What could I be doing wrong ?
There is no help in the datasheet. The language for describing the pin functions is strange,
I don't find it in C++ or in the datasheet. What else can be done ?
#include <avr/io.h>
#include <stdio.h>
#define F_CPU 16000000
// pin definition
#define POS_INPUT AC_MUXPOS_PIN0_gc // PA7
#define NEG_INPUT AC_MUXNEG_PIN0_gc // PA6
int main(void)
{
PORTA.DIRCLR = PIN6_bm; // input pin of AC0
PORTA.DIRCLR = PIN7_bm; // input pin of AC0
// AC0 input setings
AC0.MUXCTRLA = POS_INPUT | NEG_INPUT;
// AC0 output setting
AC0.CTRLA = AC_ENABLE_bm | AC_OUTEN_bm;
PORTA.DIR = PIN3_bm; // LED as AC0 output test
while (1)
{
if (AC0.STATUS & AC_STATE_bm)
{
PORTA_OUTSET = PIN3_bm; // LED ON
}
else
{
PORTA_OUTCLR = PIN3_bm; // LED OFF
}
}
}
Problem was solved due to 6v6gt.

