SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
The C code below should provide an approximate 10 KHz interrupt from the T16:
TimerRegs.T16PWM0CMP0DAT.bit.CMP_DAT = 1587; //value to reset counter
TimerRegs.T16PWM0CMPCTRL.bit.CMP0_INT_ENA = 1; //interrupt when counter reset
TimerRegs.T16PWM0CNTCTRL.bit.CMP_RESET_ENA = 1; //enable reset by comp 0
TimerRegs.T16PWM0CNTCTRL.bit.SW_RESET = 1; //allow counter to run
In UCD3138 the interrupt flags are not cleared automatically by hardware when the interrupt is serviced. Therefore the interrupt flag needs to be manually cleared by adding the following statement at the end of the relevant interrupt service routine.
TimerRegs.T16PWM1CMPCTRL.all | = 3;
When T16 is used for timer interrupt generation, its PWM output can be used as an independent GPIO simultaneously. This can be done by using the PWM_OUT_ENA, PWM_OUT_DRV, and PWM_OUT bits described above, or it can be done using the Global I/O registers described elsewhere in this document.