I use TCB's single shot mode. The datasheet says that there is a 2 clock delay from the trigger event to the start of the count.(2 to 3 clocks are written elsewhere)
But in reality it is 4 clocks.
The devices I tested were mega3208, mega4809 and tiny1616, but the results were the same.
Is this my mistake?
Please give me your opinion.
This is the test code for mega0.
Generate a single shot of 4 clock width.
#include <avr/io.h> #include <avr/interrupt.h> //////////////////////////////////////////////////////////////// // Fuses //////////////////////////////////////////////////////////////// FUSES = { .WDTCFG = 0, .BODCFG = 0, .OSCCFG = FUSE_FREQSEL1_bm, // 20MHz .SYSCFG1 = 0b00000111, .APPEND = 0, .BOOTEND = 0, .SYSCFG0 = 0b11000000, }; //////////////////////////////////////////////////////////////// // main //////////////////////////////////////////////////////////////// int main(void){ // CLOCK set(20MHz) _PROTECTED_WRITE((CLKCTRL.MCLKCTRLB), CLKCTRL_PDIV_2X_gc | !CLKCTRL_PEN_bm); _PROTECTED_WRITE((CLKCTRL.MCLKCTRLA), CLKCTRL_CLKSEL_OSC20M_gc); EVSYS.CHANNEL0 = EVSYS_GENERATOR_TCB1_CMP0_gc; EVSYS.USERTCB0 = EVSYS_CHANNEL_CHANNEL0_gc; EVSYS.USEREVOUTB = EVSYS_CHANNEL_CHANNEL0_gc; // TCB1 1ms Periodic (TCB0 trigger) TCB1.CCMP = 20 * 1000 -1; TCB1.CTRLB = TCB_CNTMODE_INT_gc; TCB1.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm; // TCB0 4clk width 1shot TCB0.CCMP = TCB0.CNT = 3; TCB0.EVCTRL = TCB_CAPTEI_bm; // TEST parameter TCB0.CTRLB = TCB_CNTMODE_SINGLE_gc | TCB_CCMPEN_bm; // TCB0.CTRLB = TCB_CNTMODE_SINGLE_gc | TCB_CCMPEN_bm | TCB_ASYNC_bm; TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm; // TCB0.CTRLA = TCB_CLKSEL_CLKDIV_gc | TCB_ENABLE_bm; sei(); while (1) { } }
This is the output waveform.
You can see that it takes 4 clocks to start up single shot.
This is the output waveform in asynchronous mode.
The event is received without delay and the output is transitioning to H immediately.