ATtiny1616 precision UVLO with timeout using AC, LUT, PIT, TCB

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sanity check required! - is it correct or is there a better way?

An external voltage is monitored by comparator, 30ms after it goes low an interrupt is triggered. If at any point it goes high the delay is reset.

---

AC (config not shown here) is fed into CCL LUT0, also Event0 and logic is set for an AND gate.
 

CCL.TRUTH0 = 0b1000;
CCL.LUT0CTRLB = CCL_INSEL0_EVENT0_gc | CCL_INSEL1_AC2_gc;
CCL.LUT0CTRLA = CCL_ENABLE_bm;
CCL.CTRLA = CCL_RUNSTDBY_bm | CCL_ENABLE_bm;

The RTC PIT feature is enabled. Note the period is not defined (zero) so it should fire on every tick.
 

RTC.PITCTRLA = 1U << RTC_PITEN_bm;

The EVSYS is configured to push the PIT to the LUT and the LUT output into TCB.
 

//EVSYS
//EVSYS.ASYNCCH0 = EVSYS_ASYNCCH0_AC1_OUT_gc;
//EVSYS.ASYNCCH1 = EVSYS_ASYNCCH1_RTC_CMP_gc;
EVSYS.ASYNCCH2 = EVSYS_ASYNCCH2_CCL_LUT0_gc;
EVSYS.ASYNCCH3 = EVSYS_ASYNCCH3_PIT_DIV64_gc;
//EVSYS.ASYNCUSER0 = EVSYS_ASYNCUSER0_ASYNCCH0_gc;     //TCB0 to AC1
//EVSYS.ASYNCUSER1 = EVSYS_ASYNCUSER1_ASYNCCH1_gc;   // ADC0 to RTC
EVSYS.ASYNCUSER2 = EVSYS_ASYNCUSER2_ASYNCCH3_gc;   // LUT0 EV0 to PIT
EVSYS.ASYNCUSER11 = EVSYS_ASYNCUSER11_ASYNCCH2_gc; // TCB1 to LUT0
//EVSYS.ASYNCUSER12 = EVSYS_ASYNCUSER12_ASYNCCH1_gc; // ADC1 to RTC

The TCB is configured as a timeout to interrupt after the 30ms. The PIT is 32768/64 so roughly 2ms resolution.
 

TCB1.CTRLB = TCB_ASYNC_bm | TCB_CNTMODE_TIMEOUT_gc;
TCB1.DBGCTRL = TCB_DBGRUN_bm;
TCB1.EVCTRL = TCB_CAPTEI_bm | TCB_EDGE_bm | TCB_FILTER_bm;
TCB1.CCMP = UVLO_TICKS_TIMEOUT;
TCB1.CTRLA = TCB_CLKSEL_CLKDIV2_gc | TCB_RUNSTDBY_bm;

(Interrupt is enabled later)