comparator AC1 problem with ATtiny1616 #1184
Replies: 5 comments 1 reply
-
Hard to tell since you don't show complete code. I see you enabling an interrupt, but there is no ISR. |
Beta Was this translation helpful? Give feedback.
-
Well the entire project is a bit more involved: This is a loco-controller for some maerklin MM2-system. It includes PWM motor-control with BEMF measurement. In the long run I want to use the comparator to get an early indication for power drop in order to potentially save data to NVM before I brown-out. So I want to use the interrupt - not the output. That's why the interrupt is configured - the output is for debugging only. In the long run I also want to use the reference rather than AIN0. |
Beta Was this translation helpful? Give feedback.
-
Posting a minimal sketch that compiles and demonstrates your problem is always a smart idea. That way people can load that easily in their development environment and play/experiment with your findings. I quickly looked in your sketch and I don't see you clearing the interrupt flag in your ISR(18), so I would not be surprised that ISR keeps firing. You do clear the flag in the TCB0 ISR. |
Beta Was this translation helpful? Give feedback.
-
O.K. |
Beta Was this translation helpful? Give feedback.
-
Great, that does the trick! I did not really care for the difference between _bm, _bp and _gc, but it becomes obvious if you look at what the directive expands to. |
Beta Was this translation helpful? Give feedback.
-
I am having serious problems using comparator AC1 on attiny1616.
Basic-Idea:
use AC1.AINP2(PB0) as positive input and AC1.AINN0(PA5) as negative input and observe the comparator output on AC1.OUT(PB3).
Here is the extraction of my code:
void setup() {
VREF.CTRLA=VREF_ADC0REFSEL_4V34_gc | VREF_DAC0REFSEL_4V34_gc; //references doe ADC0 and DAC0
VREF.CTRLC=VREF_DAC1REFSEL_2V5_gc;
VREF.CTRLB|=VREF_DAC1REFEN_bm | VREF_ADC0REFEN_bm; //reference for AC1
AC1.MUXCTRLA=AC_MUXPOS_PIN2_gc | AC_MUXNEG_PIN0_gc;
AC1.CTRLA=AC_OUTEN_bp | AC_INTMODE_NEGEDGE_gc | AC_HYSMODE_50mV_gc |AC_ENABLE_bm;
AC1.INTCTRL=AC_ENABLE_bm; //enable interrupt for AC1
PORTB.DIR &= ~0x3; //disable digital output-driver on PB3
PORTB.DIRSET &= ~0x3;
PB3(RXD) is constantly low.
Any idea on what I am missing? Do I need to configure PB3 to see the output?
Beta Was this translation helpful? Give feedback.
All reactions