cancel
Showing results for 
Search instead for 
Did you mean: 

MOE behaviour on TIM1/8/20

Martin Izaak
Associate II
Posted on May 09, 2018 at 16:39

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 #moe
4 REPLIES 4
Khouloud GARSI
Lead II
Posted on May 24, 2018 at 13:19

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

http://www.st.com/content/ccc/resource/technical/document/reference_manual/4a/19/6e/18/9d/92/43/32/DM000435pdf/files/DM000435pdf/jcr:content/translations/en.DM000435pdf

.

Khouloud.

Posted on May 24, 2018 at 14:58

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

Posted on May 24, 2018 at 16:15

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:

  • a SW solution: clear the MOE bit in the TIMx_BDTR register.
  • HW solutions: break function or clearing the OCxREF signal on an external event (detailed in the RM).

Khouloud.

Posted on May 24, 2018 at 21:33

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