How to use microcontroller PWM output to drive loads more efficiently

Publisher:玉树琼花Latest update time:2022-08-24 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Most microcontrollers have at least one pulse width modulation (PWM) peripheral that generates multiple waveforms in the form of square waves. These PWM outputs can be used to drive synchronous loads such as stepper motors in mechanical systems and power MOSFETs in power converters. For these loads, it is very important that the PWM waveforms are precisely synchronized for the target load to work properly.


If the PWM peripheral is not carefully programmed, it may occasionally produce phase delays between waveforms, resulting in loss of synchronization when the waveform edges are not properly aligned. These phase delays will reduce the efficiency of driving the load, thereby wasting power and potentially generating excessive heat. With common PWM peripherals, a PWM can be enabled or disabled, but this will cause phase delays in other PWM outputs.


This is particularly a problem for small form factor, battery powered Internet of Things (IoT) applications where a single PWM peripheral with 16 or 32 outputs is used to control multiple external loads. Phase delays in these IoT applications can waste battery power. Furthermore, because phase delays are not detected, network diagnostics at IoT endpoints can miss these delays.


This article will discuss some applications of microcontroller PWM peripherals and when it is important to keep the PWM waveforms synchronized in such applications. It will then introduce a microcontroller from Maxim Integrated that has a pulse train peripheral designed to prevent loss of waveform synchronization in such applications, and finally discuss how to configure this peripheral to ensure that the target load is driven efficiently.


Microcontroller PWM peripherals and their target loads

Most general-purpose microcontrollers have at least one PWM peripheral for generating a regular, repeating square wave. PWM drives can be used for many loads—from simple loads to more complex mechanical drive systems.


Light Emitting Diodes (LEDs) are one example of a simple load that can be driven efficiently with a PWM signal, especially in applications where dimming of colored LEDs is required. Compared to dimming an LED by varying the forward DC current, PWM dimming can more accurately maintain light quality without noticeably changing the color. A single PWM peripheral can easily drive one or more LEDs. If these LEDs are used as visual indicators for operators, the phase difference between two or more LEDs is not very noticeable. However, if these LEDs are used in more complex applications, such as multiple LEDs transmitting data to a photoreceiver in the form of light modulation, then LED synchronization can be a very important design consideration.


Another simple load for microcontroller PWM is a DC motor driven through a motor driver IC. Although the speed of a DC motor can be easily changed by varying the voltage across it, PWM control allows for more precise control of the motor rotation. If a speed sensor is used in a closed-loop control system, the motor speed can be maintained more accurately. If two or more DC motors are used and they must run together, it may be necessary to synchronize the PWM waveforms in order to maintain precise speed control between the motors.


Driving bipolar stepper motors

The design situation becomes more complicated when driving a bipolar stepper motor. A bipolar stepper motor is driven by two reversible current windings (Figure 1). Two PWMs are required for each winding, so four PWMs are required.

pYYBAGMC_LuACxS9AABK1BqRJi0119.png

Figure 1: A bipolar stepper motor is rotated by two current windings (represented as red and green coils) that carry current in each direction. By controlling the phase and duration of the current in the windings, the speed and position of the motor can be easily controlled. (Image source: Digi-Key)


As shown in Figure 1, the two current windings represented by the red and green coils must be driven in the correct sequence for the motor to operate properly. The sequence shown in Figure 2 drives the bipolar stepper motor one full step at each waveform change.

poYBAGMC_M2AZ6BOAABmb3oA-BA789.png

Figure 2: The two coils on a bipolar stepper motor must be driven separately as shown above in order for the motor to move a full step with each waveform change. First the current in each coil is driven in one direction; next the coil is idle; then the current is driven in the opposite direction. (Image source: Digi-Key)


Each step of the motor begins with each waveform transition. The polarity of the voltage across the windings, and therefore the current flowing through each winding, changes at each step, as shown in Figure 2. Any phase delay in the PWM signal can cause the motor to slip, resulting in a loss of torque, especially at low speeds.


When a microcontroller has a PWM peripheral that uses only four outputs, it is easy to control a stepper motor with only moderate care to maintain synchronization. However, the situation becomes more complicated when the same PWM peripheral is used to control multiple loads. For example, a 16-output PWM might have four PWM outputs assigned to stepper motors and other PWM outputs assigned to other loads, such as DC motors or LEDs. After the frequency and duty cycle of the PWM outputs are configured using the appropriate registers, a bit is set in the enable/disable register for each PWM. In Arm® microcontrollers, the firmware can set the corresponding bits by using bit-banding. However, bit-banding performs a read/modify/write (RMW) operation on the target register. If there are other PWM outputs programmed to start or end during the RMW operation, this can lead to unpredictable results and, in some cases, can even enable or disable the PWM in a manner contrary to firmware control.


Maxim Integrated has addressed this problem with the MAX32650 Arm Cortex®-M4F microcontroller, which runs at 120 megahertz (MHz). It has a wide range of peripherals, including three standard SPI interfaces, one quad-SPI, three UARTs, two I2C ports, a USB 2.0 high-speed interface with physical layer (PHY), six 32-bit timers, and an AES-256 encryption unit (Figure 3).

poYBAGMC_NiADfpnAAPz8fKNpmo811.png

Figure 3: The Maxim Integrated MAX32650 is based on a 120 MHz Arm Cortex-M4F and features a full range of peripherals and memory options for high-performance IoT edge computing applications. (Image source: Maxim Integrated)

The MAX32650 has 3 MB of flash and 1 MB of SRAM and is targeted at complex Internet of Things (IoT) endpoints that require edge computing. The MAX32650 also has a 16-output pulse train peripheral that can generate complex PWM signals. It can generate square waves with configurable frequency and 50% duty cycle, as well as pulse trains based on programmable bit patterns up to 32 bits in length.


Preventing phase delay

The pulse train generator can individually enable or disable any of the 16 PWM outputs using the 32-bit PTG_ENABLE register. Writing a 1 to any bit position enables that pulse train, causing it to operate as configured. Writing a 0 stops the pulse train clock and logic, freezing the outputs at their current logic states. This register has the same RMW limitations as the enable/disable registers in most microcontrollers, so bit-banding is not recommended.


To maintain phase synchronization between waveforms, the pulse train peripheral of the MAX32650 supports a unique feature called “safe enable” when using the 32-bit register PTG_SAFE_EN and “safe disable” when using the 32-bit register PTG_SAFE_DIS. The upper 16 bits of each of these registers are unused and it is recommended that these unused locations always be written with zeros.


To safely enable any output, the firmware writes a 1 to the corresponding bit position in PTG_SAFE_EN. This also immediately sets the bit positions in PTG_ENABLE for those outputs, thus starting the PWM outputs. Writing a 0 to any bit position in PTG_SAFE_EN has no effect on any pulse train outputs.


To safely disable any output, the firmware writes a 1 to the corresponding bit position in PTG_SAFE_DIS. This also immediately clears the bit positions in PTG_ENABLE for those outputs, thereby stopping the PWM outputs. Writing a 0 to any bit position in PTG_SAFE_DIS has no effect on any pulse train outputs.


Writing to these registers does not perform a RMW. The safe enable/disable feature allows one or more pulse trains to be started or stopped immediately while guaranteeing that any other pulse trains will not be affected. The PTG_SAFE_EN and PTG_SAFE_DIS registers do not support bit strapping.


Referring again to the bipolar stepper motor in Figure 1, pulse train outputs 0 and 1 can be used for the green current windings corresponding to A and B, and pulse train outputs 2 and 3 can be used for the red current windings corresponding to C and D. Since the waveform in Figure 2 contains dead spots, it is appropriate to use the pulse train feature to program a pattern that can be configured to repeat any number of times without firmware intervention.


Once set, the motor can be started by writing 0000000Fh to PTG_SAFE_EN. This simultaneously starts pulse train outputs 0 to 3, starting the motor without affecting any other running pulse train outputs. The motor can be stopped by writing 0000000Fh to PTG_SAFE_DIS. Both actions will not affect any other running pulse trains.


If any of the other 12 pulse train outputs need to be enabled or disabled, they can also be safely controlled using these two registers. As long as 1 is not written to the lower four bit positions of these registers, the operation of the stepper motor will not be affected. This is completely different from using the standard enable registers with RMW, when the outputs may stutter, causing phase shifts, which may have an adverse effect on torque. The safe enable/disable function is like an atomic operation, so it ensures that the stepper motor runs efficiently, does not waste power, and always maintains maximum torque.

[1] [2]
Reference address:How to use microcontroller PWM output to drive loads more efficiently

Previous article:Position Sensor Selection for BLDC Motor Control
Next article:Explanation of PLC basic signal concepts

Recommended ReadingLatest update time:2024-11-16 15:31

STM8 microcontroller triggers ADC synchronous sampling via PWM
  The PWM function and ADC sampling function are the most commonly used functions in the development of digital switching power supplies. The sampling time point is very important when sampling ADC. The sample must be taken when the PWM output is high, so that the sampled data is the most accurate. In the STM8 microco
[Microcontroller]
STM8 microcontroller triggers ADC synchronous sampling via PWM
STM32 uses PWM to control the LED breathing light effect
STM32 model used in the experiment: STM32F103C8T6 48-pin Knowledge involved: RCC, GPIO, TIMER, PWM settings *RCC needs to turn on the external clock * GPIO table check shows that PA3 defaults to multiplexing pin TIM2_CH4 *TIMER uses the default TIM2_CH4 *PWM control uses a dynamic duty cycle to achieve a breathing
[Microcontroller]
PIC microcontroller uses CCP1 module to generate 10-bit PWM waveform program
//This program is used to make the CCP1 module generate a PWM waveform with a resolution of 10 bits and a duty cycle of 50% #include p18f452.h void CCP1NIT(void) {  CCPR1L=0x7f;  CCP1CON=0x3c; //Set the CCP1 module to PWM mode, and      the lower 2 bits of its working //cycle are 11, and the upper 8 bits are 011
[Microcontroller]
Using DSP to control high power factor PWM rectifier
1 Introduction PWM rectifier is a new type of power converter developed by applying pulse width modulation technology. Its basic principle is to control the on and off state of the power switch tube so that the rectifier input current is close to a sine wave, and the current and voltage are in phase, thereb
[Embedded]
Exploring the Principle and Control Program of PWM in Single Chip Microcomputer
PWM is widely used in microcontrollers. Its basic principle is very simple, but its meaning is often not exactly the same when applied in different occasions. Here I will first introduce the basic concepts and principles to you, so that when you encounter them later, at least you know what they are. PWM is the abbre
[Microcontroller]
Exploring the Principle and Control Program of PWM in Single Chip Microcomputer
Realization of long-distance transmission of power drive PWM signal in high-voltage inverter
With the development of market economy and the improvement of automation and intelligence, the use of high-voltage inverters to control the speed of pump loads is not only beneficial to improving processes and improving product quality, but also a requirement for energy saving and economical operation of equipment
[Power Management]
Realization of long-distance transmission of power drive PWM signal in high-voltage inverter
Practical MSP430: TB captures the pulse width of PWM wave
Capturing pulse width with TB If you want to use TBCCRO to capture the low-level width of the pulse, the idea is: if tbccr0 captures a falling edge interrupt, then write down the value of tbccro and change it to a rising edge trigger; if it captures a rising edge interrupt, then write down the value of tbccro and
[Microcontroller]
Actual ZCT-PWM inverter circuit
Actual ZCT-PWM inverter circuit Figure 1. Actual ZCT-PWM inverter circuit
[Power Management]
Actual ZCT-PWM inverter circuit
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号