Blockset described on this wiki is deprecated since 2012.

For Model Based Design (MBD), use the free MPLAB Device Blocks for Simulink, tool from Microchip.
Updated Rapid Control Prototyping (RCP) custom projects are published at:

DsPIC Block/PWM Motor Output

From - Simulink device driver Blockset for dsPIC / PIC24 / PIC32 Microcontrollers --[[User:LubinKerhuel|LubinKerhuel]] 12:40, 3 September 2009 (UTC)
Jump to navigation Jump to search
Block PWM Motor Output

The PWM Motor block allows to generate either simple PWM pulse like OC block or PWM pulse with two channel in opposit phase for motor control. This block do not use a timer like the OC or IC blocks.

Main Dialog Box Parameters

PWM Motor Output main Dialog

General Input Enable

Add the enable input to the block. Allow to Start and Stop the PWM pulses.

Input Periode

Add the Periode Input. When the PWM periode is not constant, this input allow to control the PWM periode dynamically. Only one Input Periode appears as this periode is common for PWM channels of the PWM peripheral. If your application require different input period, you may either

Output Channel

Choose the PWM motor Channels to be used.


  • When Input Periode is disable, Fixed the Periode value.
  • When Input Periode is enable, This define the max Periode that will be used.

All temporal value provided to the bock input must be uint16 variable. The integer variable PWMmax created automatically in the workspace code for the time defined in Periode. Thus, any temporal value at block input must be multiplied by [math]\frac{PWMmax}{Periode}[/math]. integer value at block input = [math]T_{set} * \frac{PWMmax}{Periode}[/math]


  • Tset = the requested time in second (should be inferior to Periode)
  • Periode = The literal value (in second) you defined in the Periode dialog box
  • PWMmax = a constant automatically evaluated in the matlab workspace

for example, a 1ms is coded with (Periode is set to 20ms : [math]20*10^{-3}[/math]):


ValMax Periode Calcule

This Variable will be evaluated in the workspace and allow you to scale the data.The ValMax is the max value that correspond to the duration defined in Periode.


Edge-Aligned PWM vs Center-Aligned PWM. Center-Aligned PWM multiply by two the max Period and Duty Cycle achievable

This parameter center-aligned PWM duty cycle (see figure on the right). A side effect is to add a factor 2 to the internal PWM prescaler. Thus, This option multiply by 2 the MAX Period and the MAX duty Cycle time that can be achieved. However, for fast PWM (with prescalar set to 1), this option divide by two the resolution.

Activate H Complementary Output

Activate the Complementary output (PWM low) of each channel.


Gives information :

  • NbrBits is the resolution for the full scale defined by Periode.
  • PWM max value corresponing to the time defined in Periode. PWM is evaluated in the workspace to allow you to scale the data.
  • Prescaler is the Prescaler internally used in the microcontroller..


Information if error encountred.

Dead Time TAB

PWM Motor Output Dead Time Dialog. some dsPIC has only one Dead Time Prescaler. This Dialog may be different, depending on the dsPIC being used
PWM motor Dead Time

This tab may change. Some PIC / dsPIC has only one Dead Time, others have two.

Dead Time A - B

Value in second for Dead Time A or B. When only one Dead time is available on the chip, only one value is requested and this value affect all PWM channels.

Dead Time Info

Get the real Dead Time value achievable

Dead Time PWMx Active

PWM high : delay the positive edge of the selected Dead Time (see figure)

Dead Time PWMx Inactive

PWM low : delay the positive edge of the selected Dead Time (see figure)

Know Bugs

PWM 2 peripheral : error at compilation time

Microchip pwm12.h definition has an error that cause a error at compilation time when using PWM2 peripheral. Read the workaround.