Hello,
As TonyP has already pointed out, is important to set the CLKSB:CLKSA bits of the TPM1SC register after the TPM1MOD and the TPM channel registers have been set up, in order to avoid a delay of a full TPM overflow cycle in free running mode. Here is an extract from the datasheet.
Writing to either byte (TPMxMODH or TPMxMODL) latches the value into a buffer and the registers are updated with the value of their write buffer according to the value of CLKSB:CLKSA bits, so:
• If (CLKSB:CLKSA = 0:0), then the registers are updated when the second byte is written
• If (CLKSB:CLKSA not = 0:0), then the registers are updated after both bytes were written, and the TPM counter changes from (TPMxMODH:TPMxMODL - 1) to (TPMxMODH:TPMxMODL). If the TPM counter is a free-running counter, the update is made when the TPM counter changes from 0xFFFE to 0xFFFF.
Similar considerations also apply to the update of the channel registers -
In output compare or PWM modes, writing to either byte (TPMxCnVH or TPMxCnVL) latches the value into a buffer. After both bytes are written, they are transferred as a coherent 16-bit value into the timer-channel registers according to the value of CLKSB:CLKSA bits and the selected mode, so:
• If (CLKSB:CLKSA = 0:0), then the registers are updated when the second byte is written.
• If (CLKSB:CLKSA not = 0:0 and in output compare mode) then the registers are updated after the second byte is written and on the next change of the TPM counter (end of the prescaler counting).
• If (CLKSB:CLKSA not = 0:0 and in EPWM or CPWM modes), then the registers are updated after the both bytes were written, and the TPM counter changes from (TPMxMODH:TPMxMODL - 1) to (TPMxMODH:TPMxMODL). If the TPM counter is a free-running counter then the update is made when the TPM counter changes from 0xFFFE to 0xFFFF.
Even if the update of the TPM1MOD and channel registers occurs while CLKSB:CLKSA = 0:0, the PWM output signal will not commence until the first modulo overflow occurs. Perhaps you are not waiting a sufficient time for the changes to take effect.
As to the initial 2.5 second delay, this is probably due to the start-up delay of the low frequency crystal. The oscillation amplitude will slowly build up to the normal operating level, and then there will be a further delay until the FLL locks. Higher frequency crystals will have considerably shorter start-up delay.
Regards,
Mac