Pulse Width Modulation
Technical Note 7009
Applicable Model(s)
HMC2000
HMC3000
HMC4000
HMC7000
MLC Series
Title
Pulse Width Modulation
Date
01/25/2023
Rev
04
P/N
0907-7009
Summary
Maple Systems HMC and MLC products are capable of producing four types of Pulse Width Modulation (PWM) signals when using specific output modules. This document describes each of the four types of PWM output, and then lists which registers to configure, how to configure those registers, and the minimum and maximum ranges of each register. Review the module specification sheets to ensure PWM is available.
Solution
There are four types of Pulse Width Modulation (PWM) signals available as outputs for the HMC3000, HMC7000, HMC2000, and HMC4000 Series, as well as the MLC Series: Normal, CW/CCW, Pulse/Direction, and Trapezoidal (Fixed Pulse). In Normal mode, both Channel 1 and Channel 2 can be enabled to output. They may have different Duty Cycles but have to have the same frequency. CW/CCW mode can only be configured for Channel 1, but a positive frequency turns on Channel 1 and a negative frequency turns on Channel 2. Pulse/Direction mode can only be configured for Channel 1, but a positive frequency sets Channel 2 low and a negative frequency sets Channel 2 high. Trapezoidal (Fixed Pulse) mode can only be set for Channel 1, Channel 2 is not useable in this mode.
When using PWM outputs, different product lines have different maximum frequencies ranging from 1 kHz to 200 kHz. To find more information about a specific product, please see the I/O Module Guide for that product series.
For further information and training on PWM, please reference these tutorials found on the Maple Systems website under support:
NOTE: In the following waveforms, Channel 1 is yellow, and Channel 2 is blue.
Normal: The frequency must be the same for channel 1 and channel 2, but the Duty Cycle is independently adjustable for each channel. Duty Cycle can be adjusted while the output is running. The valid range is 0 to 100%, but the effective range will vary depending on the device being controlled. The output must be shut off to adjust the frequency. The Channel 1 and Channel 2 outputs can be enabled and disabled independently.
CW/CCW: When the frequency is positive, the output signal is generated on Channel 1, and Channel 2 is not used. When the frequency value is negative, the output signal is generated on Channel 2, and Channel 1 is not used. The frequency can be adjusted while running, and the Duty Cycle is fixed at 50%.
Pulse/Direction: The output signal is generated on Channel 1. If the frequency value is positive, Channel 2 is held low. If the frequency value is negative, Channel 2 is held high. The frequency can be adjusted while running, and the Duty Cycle is fixed at 50%.
Trapezoidal (Fixed Pulse): The output signal is generated on Channel 1. The frequency ramps up from the minimum frequency to the maximum frequency in the interval specified by acceleration time. The output signal is generated until the specified number of pulses has been sent. As the number of pulses approaches the specified count, the frequency ramps down from the maximum frequency to the minimum frequency in the interval specified by deceleration time. When the specified number of pulses is reached, the output signal stops but remains enabled. The Duty Cycle is fixed at 50%.
Configuring the HMC3000, HMC2000, and HMC4000 Series PWMs
The HMC3000, HMC2000, and HMC4000 series I/O modules have PWM functionality built in, with specific registers and bits predefined for setup and control. For the register addresses listed below, nn stands for which slot the module was installed (slot 1 is 01, slot 2 02, etc.).
For each of the modes and registers listed below, first configure the PWM output using the configuration register for that channel and mode. Then, set the parameter values and define a way to monitor the error flags. Finally, enable the output by setting the Enable Output bit for that channel.
Normal:
Function | Register Address | Description | |
Output, PWM Pulse | Y0 (Channel 1) | Y1 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn30 | Set to 1 for Normal mode |
Frequency Setting | MWnn25 | MWnn31 | Range is 1 to 200,000 or 200kHz |
ON Duty Cycle Setting | MWnn27 | MWnn33 | Range is 0 to 100 |
Enable Output Flag | Mnn576 | Mnn577 | Output enabled when ON |
ON Duty Error Flag | Mnn466 | Mnn471 | ON with an error, resets automatically |
Frequency Setting Error Flag | Mnn467 | Mnn472 | ON with an error, resets automatically |
CW/CWW:
Function | Register Address | Description | |
Output, PWM Pulse | Y0 (Channel 1) | Y1 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn30 | Set to 3 for CW/CCW mode |
Frequency Setting | MWnn25 | MWnn31 | Range is -10,000 to -1 and 1 to 10,000 |
Enable Output Flag | Mnn576 | Mnn577 | Output enabled when ON |
Frequency Setting Error Flag | Mnn467 | Mnn472 | ON with an error, resets automatically |
Pulse/Direction:
Function | Register Address | Description | |
Output, PWM Pulse | Y0 (Channel 1) | Y1 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn30 | Set to 7 for Pulse/Direction mode |
Frequency Setting | MWnn25 | MWnn31 | Range is -100,000 to -1 and 1 to 100,000 |
Enable Output Flag | Mnn576 | Mnn577 | Output enabled when ON |
Frequency Setting Error Flag | Mnn467 | Mnn472 | ON with an error, resets automatically |
Fixed Pulse:
Function | Register Address | Description | |
Output, PWM Pulse | Y0 (Channel 1) | Y1 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn30 | Set to 9 for Fixed Pulse mode |
Minimum Frequency | MWnn25 | MWnn31 | Range is 1 to 100,000 |
Maximum Frequency | MWnn27 | MWnn33 | Range is 1 to 100,000 |
Acceleration Time | MWnn37 | MWnn38 | Range is 0 to 65535 |
Deceleration Time | MWnn39 | MWnn40 | Range is 0 to 35536 |
Total Pulses | MWnn41 | MWnn43 | 0 to 4,294,967,295 |
Elapsed Pulses | MWnn45 | MWnn47 | 0 to 4,294,967,295 |
Enable Output Flag | Mnn576 | Mnn577 | Output enabled when ON |
Frequency Setting Error Flag | Mnn467 | Mnn472 | ON with an error, resets automatically |
Acceleration Time Error Flag | Mnn468 | Mnn473 | ON with an error |
Deceleration Time Error Flag | Mnn469 | Mnn474 | ON with an error |
Total Pulses Setting Error Flag | Mnn470 | Mnn475 | ON with an error |
Total Pulses Reached | Mnn784 | Mnn785 | ON when Total Pulses are sent |
Configuring the HMC7000 Series PWMs
The HMC7000 series I/O modules that have PWM functionality have specific registers and bits predefined for setup and control. For the register addresses listed below, nn stands for which slot the module was installed (slot 1 is 01, slot 2 02, etc.). Any N/As are due to Channel 2 not supporting the Fixed Pulse, CW/CCW, or Pulse DIR modes.
For each of the modes and registers listed below, first configure the PWM output using the configuration register for that channel and mode. Then, set the parameter values and define a way to monitor the error flags. Finally, enable the output by setting the Enable Output bit for that channel.
Normal:
Function | Register Address | Description | |
Output, PWM Pulse | Y2 (Channel 1) | Y4 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn30 | Set to 1 for Normal mode |
Frequency Setting | MWnn25 MWnn26 | MWnn25 MWnn26 | Range is 1 to 10,000 or 10 kHz |
ON Duty Cycle Setting | MWnn27 MWnn28 | MWnn31 MWnn32 | Range is 0 to 100 |
Enable Output Flag | MWnn36_0 | MWnn36_1 | Output enabled when ON |
ON Duty Error Flag | MWnn29_2 | MWnn29_7 | ON with an error, resets automatically |
Frequency Setting Error Flag | MWnn29_3 | MWnn29_3 | ON with an error, resets automatically |
CW/CCW:
Function | Register Address | Description | |
Output, PWM Pulse | Y2 (Channel 1) | Y4 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn24 | Set to 3 for CW/CCW mode |
Frequency Setting | MWnn25 MWnn26 | MWnn25 MWnn26 | Range is -10,000 to -1 and 1 to 10,000 |
Enable Output Flag | MWnn36_0 | MWnn36_0 | Output enabled when ON |
Frequency Setting Error Flag | MWnn29_3 | MWnn29_3 | ON with an error, resets automatically |
Pulse/Direction:
Function | Register Address | Description | |
Output, PWM Pulse | Y2 (Channel 1) | Y4 (Channel 2) | Physical Output |
Configuration | MWnn24 | MWnn24 | Set to 7 for Pulse/Direction mode |
Frequency Setting | MWnn25 MWnn26 | MWnn25 MWnn26 | Range is -10,000 to -1 and 1 to 10,000 |
Enable Output Flag | MWnn36_0 | MWnn36_0 | Output enabled when ON |
Frequency Setting Error Flag | MWnn29_3 | MWnn29_3 | ON with an error, resets automatically |
Fixed Pulse:
Function | Register Address | Description | |
Output, PWM Pulse | Y2 (Channel 1) | N/A | Physical Output |
Configuration | MWnn24 | N/A | Set to 9 for Fixed Pulse mode |
Minimum Frequency | MWnn25 MWnn26 | N/A | Range is 1 to 10,000 |
Maximum Frequency | MWnn27 MWnn28 | N/A | Range is 1 to 10,000 |
Acceleration Time | MWnn37 | N/A | Range is 0 to 32767 |
Deceleration Time | MWnn39 | N/A | Range is 0 to 32767 |
Total Pulses | MWnn41 MWnn42 | N/A | 0 to 2,147,483,647 |
Elapsed Pulses | MWnn45 MWnn46 | N/A | 0 to 2,147,483,647 |
Enable Output Flag | MWnn36_0 | N/A | Output enabled when ON |
Frequency Setting Error Flag | MWnn29_3 | N/A | ON with an error, resets automatically |
Acceleration Time Error Flag | MWnn29_4 | N/A | ON with an error |
Deceleration Time Error Flag | MWnn29_5 | N/A | ON with an error |
Total Pulses Setting Error Flag | MWnn29_6 | N/A | ON with an error |
Total Pulses Reached | MWnn49_0 | N/A | ON when Total Pulses are sent |
Configuring the MLC Series PWMs
The MLC Base modules and I/O Expansion modules both work in a similar fashion, but use different registers, so first is listed the Base module registers, then the I/O Expansion module registers. For the I/O Expansion module register addresses listed below, nn stands for which slot the module was installed (slot 1 is 01, slot 2 02, etc.). Any N/As are due to Channel 2 not supporting the Fixed Pulse, CW/CCW, or Pulse DIR modes.
For each of the modes and registers listed below, first configure the PWM output using the configuration register for that channel and mode. Then, set the parameter values and define a way to monitor the error flags. Finally, enable the output by setting the Enable Output bit for that channel.
MLC Base Module Registers:
Function | Channel 1 | Channel 2 |
Output Pin | Y0 | Y1 |
Enable Bit | M816 | M832 |
ON Duty Setting Error | M818 | M834 |
Frequency Setting Error | M819 | M835 |
Acceleration Time Setting Error | M820 | M836 |
Deceleration Time Setting Error | M821 | M837 |
No. of Total Pulse Setting Error | M822 | M838 |
End of Total Pulses | M823 | M839 |
Configuration Register | MW59 | MW75 |
Frequency of Min Frequency Register (LSW, MSW) | MW60, MW61 | MW76, MW77 |
Duty Cycle or Max Frequency Register (LSW, MSW) | MW62, MW63 | MW78, MW79 |
Acceleration Time Setting Register | MW64 | MW80 |
Deceleration Time Setting Register | MW65 | MW81 |
Total Pulses Setting Register | MW66, MW67 | MW82, MW83 |
Elapsed Value Register | MW68, MW69 | MW84, MW85 |
MLC I/O Expansion Module Registers:
Function | Channel 1 | Channel 2 |
Output Pin | Ynn002 | Ynn004 |
Enable Bit | Mnn016 | Mnn018 |
Direction Flag | Mnn017 | N/A |
Configuration Register | MWnn00 | MWnn26 |
Frequency or Min Frequency Register (LSW, MSW) | MWnn02, MWnn03 | N/A |
Duty Cycle or Max Frequency Register (LSW, MSW) | MWnn04, MWnn05 | MWnn26, MWnn27 |
Acceleration Time Setting Register | MWnn06 | N/A |
Deceleration Time Setting Register | MWnn07 | N/A |
Total Pulses Setting Register | MWnn08, MWnn09 | N/A |
Register and Bit Definitions, Settings, and Ranges:
Register/Bit | Description | CPU Base Unit Setting | I/O Expansion Setting |
Configuration Register | 16-bit register that sets the mode being used by the PWM. | 0: Not defined 1: Normal (Fixed Frequency) 2: Norman (Variable Frequency) 3: CW/CCW (Fixed Frequency) 4: CW/CCW (Variable Frequency) 7: Pulse/Dir (Fixed Frequency) 8: Pulse/Dir (Variable Frequency) 9: Fixed Pulse | 0: Not defined 1: Normal (Fixed Frequency) 3: CW/CCW (Variable Frequency) 7: Pulse/Dir (Variable Frequency) 9: Fixed Pulse |
Frequency Setting or Min Frequency Register | 32-bit register that sets the Frequency (in Normal, CW/CCW, and Pulse/Dir) or the Min Frequency (Fixed Pulse). | Range: MLC1-F Models: 1 to 100,000 for Normal or Fixed Pulse modes. -100,000 to -1 or 1 to 100,000 for CW/CCW or Pulse/Dir modes. MLC1-E & MLC2-E Models: 1 to 200,000 for Normal or Fixed Pulse modes. -200,000 to -1 or 1 to 200,000 for CW/CCW or Pulse/Dir modes. | Range: 1 to 10,000 for Normal or Fixed Pulse modes. -10,000 to -1 or 1 to 10,000 for CW/CCW or Pulse/Dir modes. |
Duty Cycle or Max Frequency Register | 32-bit register that defines the Duty Cycle (Normal), or Max Frequency (Fixed Pulse). | Range: 1 to 100 for Normal mode. 1 to 100,000 for Fixed Pulse mode. | Range: 1 to 100 for Normal mode. 1 to 100,000 for Fixed Pulse mode. |
Acceleration Time | 16-bit register that determines acceleration time in Fixed Pulse mode. | Range: 0 to 65535 (in 10ms) | Range: 0 to 32767 (in ms) |
Deceleration Time | 16-bit register that determines the deceleration time in Fixed Pulse mode. | Range: 0 to 65535 (in 10ms) | Range: 0 to 32767 (in ms) |
Total Pulses Register | 32-bit register that defines the Total Number of Pulses in Fixed Pulse mode. | Range: 128 to 4,294,967,296 | Range: 0 to 2,147,483,647 |
Elapsed Value Register | 32-bit register that records the Elapsed Value in Fixed Pulse mode. | Range: 0 to 4,294,967,296 | Range: 0 to 2,147,483,647 |
Pulse Enable | Enable bit for PWM signal output. | ||
End of Total Pulses | Indicates when the Total Number of pulses has been reached in Fixed Pulse mode. | ||
Duty Cycle Setting error | Indicates if the value for Duty Cycle is out of range. | ||
Frequency Setting Error | Indicates if the value for Frequency is out of range. | ||
Acceleration Time Setting Error | Indicates if the value for Acceleration Time is out of range. | ||
Deceleration Time Setting Error | Indicates if the value for Deceleration Time is out of range. | ||
No. of Total Pulses Error | Indicates if the value for Total No. of Pulses is out of range. |