I am now trying to get a 1 second timer working. The code attempt I made is baelow, trying to use Timer B. But I'm kind of stuck. II think where I am going wrong is how to figure out the calculation to get the proper 1 second delay (i.e., what TOP value is going to give me the 1 second?). One reason I'm a confused is by the CLKSEL that Timer B comes with. I'm not going to be synchronizing with TCA so that's out.
So any suggestions of how to get the proper clock and calculation to get a 1 sec delay out of timer B now so then we can do a periodic interrupt every 1 second to check for something within the associated ISR?
void timer(void) /* By default, TCB is in Periodic interrupt mode In the periodic interrupt mode the counter counts to the capture value and restarts from zero. Interrupt is generated when counter is equal to TOP. */ // Write a TOP value to the Compare/Capture register (TCB.CC) // What should TCBO.CCMP be set to? TCB0.CCMP = ??? ; /* Enable the counter by writing a '1' to the ENABLE bit in the Control A register (TCB.CTRLA). The counter will start counting clock ticks according to the prescaler setting in the Clock Select bit field (CLKSEL in TCB.CTRLA). WHAT CLKSEL should I choose? */ TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCA_SINGLE_ENABLE_bm; // Compare/Capture Output has a valid value // Periodic interrupt mode; TCB0.CTRLB = TCB_CCMPEN_bm | TCB_CNTMODE_INT_gc /* The counter value can be read from the Count register (TCB.CNT). The peripheral will generate an interrupt when the CNT value reaches TOP */ }