2019-12-12 08:57 AM
Hello!
I work on 10KHz dual PWM (CH, CHN) generation with dead time implemented.
In error handle I want to stop the timer, and now I do it like this:
if(HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_2) != HAL_OK)
{
//Error_Handler();
}
//Stop channel xN
if(HAL_TIMEx_PWMN_Stop(&htim8, TIM_CHANNEL_2) != HAL_OK)
{
//Error_Handler();
}
----------------------------------------------------------
----------------------------------------------------------
(duty cycle 50%)
The first osci picture looks like its a good stop, but the second osci picture is totally bad.
The thing, if I use the firt cube picture config, and change the time when I execute the STOP function, it create a peak on Negative channel.
The main problem is when the N channel output is high, when it doesn't need to be.
I does'nt really understand, why it switch pin to HIGH at the moment of STOP.
So my question is, how to stop properly the timer?
Do I miss some other configuration in CubeMX?
I have tried to change PWM mode 1, 2 and changing the idle state but it doesn't help.
Thank you,
Szilveszter
2019-12-12 01:51 PM
The easiest way to achieve an active level of your choice is to change the respective pins to GPIO output, with previously set proper level in ODR.
I don't Cube.
JW
2019-12-13 03:56 AM
Thanks for the answer!
I would to use cube, its now better for me instead of defining everything with code, I don't feel so safe with raw code.
There is BRK interrupt for PWM, which not total clear how it works, but it set the PWM output on high or low, as you define.
In TIM8 case the BRK input pin is PG2, BRK2 pin PG3.
(STM32 H743ZI)
Is there any function to call the Break function, instead of GPIO read?
I mean, stopping the timer, or set the PWM output to 0, or disable the pin it's doesn't matter.
Duty cycle set to 0 help nothing, cuz then 1 channel will be always high and its pair low.
Problem occure only when Positive channel is high, and Negative channel is low. If I in this moment do STOP, the negative channel make a peak.
Software pull down, help only that the time shorter from 3.3 to 0, and not like on "picture 2 osci" shows.
I have tried:
counter = htim8.Instance->CNT;
to get the counter value. It works fine, with this I can stop the timer in specific counter value.
With this the problem is that when the Positive channel in the whole duty cycle is high, I also become a peak from Negative channel.
Everything would be fine without N channel peak... Why it works like this?
Some other info: PWM create with FET 0V to 400V output, which is connected to the grid. So the fast shutdown can only be if both PWM output is LOW.
Thanks.
2019-12-13 06:35 AM
> Is there any function to call the Break function, instead of GPIO read?
I don't understand, why would there be GPIO read.
Break clears TIMx_BDTR.MOE, you can do the same in software, if this suits you.
> Everything would be fine without N channel peak... Why it works like this?
Probably because in HAL_TIM_PWM_Stop() the first thing is that the CHx channel is disabled in TIMx_CCER, which has the side effect, that CHxN channel changes polarity. See the Output control bits for complementary OCx and OCxN channels with break feature table in RM.
Maybe reversing the two calls will produce the output you want. Note, that there are three states - driven high, driven low, and Hi_Z.
JW
2019-12-13 06:47 AM
Okey, it works now.
I just tested out an hour ago the same what you said right now :D
You have right. The calling sequence do this. If the first stop is on the Positive channel, then the Negative changing the polarity.
Here are two pictures, which clearly shows, what is the differences:
HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_2) ;
HAL_TIMEx_PWMN_Stop(&htim8, TIM_CHANNEL_2);
-------------------------------------------------------
HAL_TIMEx_PWMN_Stop(&htim8, TIM_CHANNEL_2);
HAL_TIM_PWM_Stop(&htim8, TIM_CHANNEL_2) ;
Solution:
If you want to stop the timer which uses Positive and Negative channel, first stop the Negative channel, and after the Positive.
Thank you ✌�?