In this continuous guide of PWM with DMA on STM32G0, we shall add the complementary signal with the generated PWM.
In this guide, we shall cover the following:
- What is complementary signal of PWM.
- STM32CubeMX Configuration.
- Driver development.
- Results.
1. What is Complementary Signal of PWM:
A Complementary Signal of PWM refers to two pulse-width modulation (PWM) signals that are inverses of each other. These signals are often used in power electronics, such as in the control of H-bridges, full-bridge converters, or other switching circuits where pairs of transistors are used.
Key Characteristics:
- Duty Cycle Inversion: When one signal is high, the complementary signal is low, and vice versa. For example, if the primary PWM signal has a duty cycle of 40%, the complementary signal will have a duty cycle of 60%.
- Dead Time: A small, controlled delay (dead time) is typically introduced between the transitions of the two signals to prevent both switches (e.g., transistors or MOSFETs) from being on simultaneously, which could cause a short circuit.
Applications:
- Motor Control: In H-bridge configurations for driving motors, complementary PWM signals are used to control the direction and speed of the motor.
- DC-DC Converters: Complementary PWM signals are used in synchronous buck converters and other types of converters to control the switching of transistors.
- Inverters: In inverters, complementary PWM signals are used to create AC waveforms from DC sources.
Complementary PWM signals are crucial for efficient and safe operation in many power electronic circuits.
2. STM32CubeMX Configuration:
Continue from the previous guide here.
Open PWM_DMA.ioc file as following:
From timers, select TIM1 and configure it as following:
Channel 1 as PWM Generation CH1 CH1N. In similar manner, for channel 2.
You can noticed that PA7 has been selected as TIM1_CH1N and PB0 as TIM1_CH2N.
Save the project and this will generate the new code.
3. Driver Development:
In main.c.
In user code begin 2 section:
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, lookUp1, 200); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
First function is explained in the previous guide.
The function HAL_TIMEx_PWM_Start, it will start the PWM generate on the complementary pin of the PWM.
The function takes two arguments:
- Pointer to the timer which is timer1 as htim1.
- Timer channel which is timer channel 1.
For the second channel:
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, lookUp2, 200); HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
Thats it for the code.
Save the project, build it and run it on your STM32G070.
4. Results:
By using logic analyzer, probe PA7 and PA8 which they are TIM1_CH1N and TIM1_CH1 respectively.
You should get the following for both channel:
Note that when one channel is high, the other is low and vice versa.
Happy coding 😉
Add Comment