2018-05-09 07:39 AM
Hello forum,
I am new to STM32 but familiar with programming DSPs/MCUs.
I just bought a NUCLEO-F303ZE board and I am struggling with the PWM-Timer block. I have set up a CubeMX project and I achieved a project with a PWM on TIM1 from scratch. First it was very surprised that I have to write two HAL-commands to start the PWM and PWMN (HAL_TIM_PWM_Start and HAL_TIM_PWMN_Start).
No I am playing with the MOE. I noticed that this command is executed immediately and not at CNT=0.
So my question is if there is a way to start all TIM-PWMs synchronised at CNT=0 (very important for our motor control). The TIM update event also starts my ISR for controlling the motor so an On/Off of the TIM is not a good idea.
My next question will be if there is a way to switch of the PWM output at a given CNT value. For example on an up counting configuration I want to set the PWM-pin at CNT=2 and reset the PWM pin at CNT=5. I found one way to use a separate TIM module for each phase. But that is not my favourite solution.
Thank you for your support,
Martin
#tim #moe2018-05-24 04:19 AM
Hi Martin,
You should enable the normal and the complimentary channel outputs before enabling the timer.
* TIM1->CCER |= TIM_CCER_CC1E; /* Enable the PWM output */
* TIM1->CCER |= TIM_CCER_CC1NE; /* Enable the complementary PWM output */
* __HAL_TIM_MOE_ENABLE(TIM1); /* Enable the Main Output */
* __HAL_TIM_ENABLE(TIM1); /* Enable the Peripheral */
�?�?�?�?
Now for switching the PWM output at a given CTN value, you should use the combined PWM mode.
Please refer to 'Combined PWM mode' section of .Khouloud.
2018-05-24 07:58 AM
Hi Khouloud,
thank you for your answer.
Switching ON/OFF the PWM with Enable/Disable the TIM-Peripheral will also start/stop my ISR-Task? So I have to use another timer for my ISR? I found some hint in the manual regarding 'shadow registers'. The registers CCxE and CCxNE are shadowed ones. So I will try to start/stop the PWM by writing to these registers. First I have to check how to enable the shadow register.
I also found the combined PWM mode but this will generate only two PWM signals, not three for a drive application. So I have to think about the concept. Maybe I have to change our PWM aproach.
My first program was written with the HAL-functions. I also have to switch to the LL-functions - So I will start with a new project (there are not so many examples for LL)...
Thank you for your support
Martin
2018-05-24 09:15 AM
Hi Martin,
Switching ON/OFF the PWM with Enable/Disable the TIM-Peripheral will also start/stop my ISR-Task?
-> Correct. But for what reason you will enable/disable the whole timer?
If you only need to enable/disable the PWM signals simultaneously (without enabling/disabling the timer), you can't do it by enabling/disabling the channels using the CCER register (CCER doesn't have a preload register). However, you may use:
Khouloud.
2018-05-24 02:33 PM
Hi Khouloud,
Switching ON/OFF the PWM with Enable/Disable the TIM-Peripheral will also start/stop my ISR-Task?
-> Correct. But for what reason you will enable/disable the whole timer?
This was a misunderstanding from me.
Thank you for the hint with the break function. I will check this if this works for me.
Thank you
Martin