2 Generate PWM Signals Using TCE
A TCE key characteristic, when compared to timers such as TCB or TCA, is the versatility and precision of the PWM generation. The user can choose from various configurations according to the complexity of the application. The TCE can be configured in both Single-Slope and Dual-Slope PWM Generation modes, which allows the trade-off between a constant phase, Correct Phase PWM, and a higher maximum operation frequency, Fast PWM. Also, the TCE has a buffering scheme that ensures a glitch-free PWM. Another feature of the TCE is the possibility of scaling the PWM signal’s duty cycle using amplitude and offset.
Both the TCE and TCB can be used to generate a PWM signal with a high maximum operating frequency. Only the TCE can be used in critical applications due to its dual-slope PWM capabilities given by its selectable direction. Dual-slope PWM does not modify the pulse center position when the duty cycle is changed. Thus, the phase is always constant. This feature is essential for motor control applications, because the switching noise caused by the simultaneous commutation of multiple PWM signals is avoided. The noise comes from transistors switching. Using Dual-Slope PWM signals with different duty cycles can avoid this noise type.
The buffering scheme contains a buffer for each Compare register and the Period register. In critical applications where an unexpected long pulse can lead to a short circuit, using these buffers it is essential. Moreover, the buffer presence can prevent the loss of synchronization between two peripherals that use the same timer but different compare channels. However, given the fact that the Period and Compare registers can be updated directly, the buffering scheme can be avoided by the user. The following waveforms illustrate the difference between the buffered and unbuffered operations.
If the user changes the Period register directly (unbuffered operation), it is possible that the timer has already passed the new threshold, so it will continue counting to the maximum value. That will cause an unusually long pulse that can cause further problems. Also, if using two or more compare channels and one is updated, the sync between the triggers may be lost. To prevent all these possible problems, using the buffering scheme is required. The buffers hold the new value and transfer it to the Compare or the Period register accordingly when the timer is updated. With all values changed at the same time, the problems mentioned disappear.
Below is an example of how to set a TCE instance to generate four PWM signals at 10 kHz with a 20%, 40%, 60%, and 80% duty cycles using the buffering scheme described above. In this example the scaling feature of the values set in compare registers is highlighted, as well as the high resolution feature. The user can increase the PWM signal resolution up to three bits.
In this example, the user can change the maximum range of the duty cycles from 0-100% to 0-75% , 0-50%, or 0-150%. The duty cycles are calculated based on the period value. The period will always be 100%, the maximum value of the duty cycle. All the duty cycles over 100% will be saturated to, 100%, the value of the period. When the user selects the range of duty cycles to 0-50% of the period, the duty cycles generated initially for the four PWM signals with duty cycle values of 20%, 40%, 60%, and 80% will now have the values scaled to 10%, 20%, 30%, and 40% duty cycles.
The proposed example modifies the scaling value of the compare registers of TCE at run time at every 10 ms. The range of duty cycles will be modify depending on the scaling value. The next two subsections present in detail how to configure the TCE peripheral to do the desired behavior. The first subsection explains how to configure the TCE using bare metal code. The following two subsections, in detail, present how to configure the TCE using MCC Melody. The last subsection contains the results.