I am using ATmega1608 and IAR for AVR IDE. I am trying to program Timer B in single-shot mode and this single-shot will give a pulse width of 1us-15us depending on the CCMP value I set . My Timer configuration works fine and I can see it working correctly i.e giving me a pulse width on output pin. I am facing a glitch when it comes to changing the compare value in the timer single shot function. what is this glitch? as soon as I change the CCMP register value, I can see a weird pulse of random duration mainly between 0.3us-2us and it can happen at the begging of normal pulse or at the end or it can combine with the normal pulse width. I tried few things here to get rid of this glitch pulse, I am polling STATUS bit in TCB, so that when counter is not running at that time only I will change the CCMP value, but it didn't work. I am attaching my timer initialization and the timer value change function, please let me know if anyone can help here.
TCB1.CTRLB= TCB_CCMPEN_bm | TCB_CNTMODE_SINGLE_gc | TCB_ASYNC_bm;
TCB1.EVCTRL= TCB_FILTER_bm | TCB_CAPTEI_bm | ~TCB_EDGE_bm;
void timer_singleshot(char pulse)
while((TCB1.STATUS & TCB_RUN_bm));
scope shot of what my glitch pulse, looks like. The second continuous pulse(fourth from the left) is glitch pulse here.