Home Instrumentation High precision PWM modules offering advanced functions

High precision PWM modules offering advanced functions

Willem J Smit of Microchip Technology explains how to use the PWM modules of high precision that incorporate some microcontrollers.
The PWM modules Some microcontrollers host innovative features for power supply, LED lighting, color mixing, and motor control applications, where they allow the user to easily vary the phase, duty cycle, and number of offsets with much higher precision. Furthermore, thanks to the offset modes, each PWM output can introduce an offset in its waveform in relation to any other PWM module of the same device. When the PWM outputs are not used on these PWM modules High-precision 16-bit timers, such as those found in some Microchip PIC16 microcontrollers, can be leveraged to add up to four more general-purpose 16-bit timers. Each PWM module can have its timer synchronized independently by selecting from three sources. In addition, the PWM clock signal source can be divided with seven selectable prescalers for better adaptation to user needs. The timer value can then be compared to the event counter registers to generate numerous PWM waveforms. Four 16-bit count registers are available to manipulate phase, duty cycle, period, and offset (see Fig. 1).
 
PWM modes
Each PWM module has four selectable modes of operation: standard, set-on-match, toggle-on-match, and center-aligned. Standard mode generates a waveform single phase PWM which is constructed by comparing and matching the PWM counter value to the 16-bit phase, period, and duty cycle registers. In case of a match of the phase count record, the work cycle is started. The end of the work cycle occurs when it coincides with the work cycle count register. The matching mode generates an output when the phase count register matches the PWM timer. This output will remain active until the output bit is cleared or the PWM module is disabled. Coincidence switching mode produces a PWM waveform with a 50% duty cycle and a period twice that of standard PWM mode. The phase count registers determine the number of PWM timer periods after a period before the PWM waveform varies. Center-aligned mode generates a PWM waveform centered on the PWM period. The period equals twice the PWMx-PR count registers. In this mode, the PWM timer will count until there is a match with the PWMxPR registers, and then count in reverse until the value matches 0. The active rising and falling edge of the PWM waveform is determined by duty cycle count registers.
 
offset mode
In addition to these PWM modes, each PWM module it also has four offset modes that can offset your waveform relative to any other PWM module in the same device. The modes are: independent operation; slave operation with synchronous start; one-shot slave with synchronous start; and continuous operation with synchronous start and timer reset. In standalone mode, PWM offset, phase, duty cycle, and period are not affected by any of the other PWM modules. In this mode, the PWM will continue to run continuously as long as it is enabled (see Fig. 2). In slave operation mode with synchronous start mode, it is necessary to have at least two or more active PWM modules, thus allowing the existence of a master-slave pair. In this mode, the slave will wait until the master's offset equalizes to start counting and will continue counting as long as it is enabled. Much like the synchronous slave mode of operation, the synchronous start single shot slave mode also requires more than one active PWM: one master and one slave. In this mode, the timer starts counting, starting at a preset value in the timer, and counting until it hits a match. The PWM timer then waits for a match with the master offset value before repeating the cycle. In continuous slave operation mode with synchronous start and timer reset, the slave PWM timer does not start counting until the first master offset match. Subsequent master offset matches will reset the PWM timer value back to 1, after which it will continue to count (see Fig. 3).
 
Conclusion
As we have seen, the high-precision 16-bit PWM available in several Microchip PIC16 devices, such as the PIC16F1574, offers advanced features in addition to those found in the PWM modules standard.