CCS News

Programmable Switch Mode Controller (PSMC)

Monday 17 May, 2021

Pulse Width Modulation (PWM) capability was first added to the PIC® microcontroller line using the Capture/Compare/PWM (CCP) unit. Since then we have seen the enhanced CCP (ECCP) and a variety of power and motor control PWM modules each with its own features. The PWM module is called the Programmable Switch Mode Controller (PSMC). This is the most sophisticated PWM yet and is on chips like the PIC16F1789.

The PSMC allows for standard PWM, complementary PWM, shutdown control and deadband control like some of the older modules. It also allows for high resolution on the duty and frequency, as well variable frequency. It can for example do 3 phase 6 step PWM.

Input pins, comparator outputs and CCP triggers can be used not only to control shutdown, but to control if the PWM is running, or to start or stop a cycle.

Some PIC® MCU devices have as many as 4 independent units and the units can optionally be synchronized with each other.

The compiler functions are:
setup_psmc(unit, mode, period, period_time,
rising_edge, rise_time,
falling_edge, fall_time);

psmc_pins(unit, pins_used, pins_active_low);

psmc_duty(unit, fall_time);

psmc_deadband(unit, rising_edge, falling_edge);

psmc_blanking(unit, rising_edge, rise_time, falling_edge, fall_time);

psmc_shutdown(unit, option, source, pins_high);

psmc_freq_adjust(unit, freq_adjust);

psmc_modulation(unit, options);

psmc_sync(slave_unit, master_unit, options);

The following is a short example program that shows off some of the features:
#include <16f1789.h>
#use delay(osc=20mhz)

#define us(time) (int16)(time*(getenv("CLOCK")/1000000))

void main(void) {


psmc_deadband(1, us(2), us(4));
psmc_modulation(1, PSMC_MOD_IN_PIN);
psmc_pins(1, PSMC_A | PSMC_B | PSMC_C | PSMC_D);


while(TRUE) {
psmc_duty(1, us(((read_adc()*(int16)10)/25)) );

Other examples are included with the compiler download and begin with EX_PSMC_

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.