Skip to main content
Stefan Hubacher
Associate
March 7, 2017
Question

STM32F446 Timer1 Commutation via Timer2

  • March 7, 2017
  • 2 replies
  • 1747 views
Posted on March 07, 2017 at 16:05

Hi

I try to control a BLDC Motor with TIM1 as the PWM-Generator and TIM2 as the Hall-Interface-Timer.

The TIM2-Setup is done via HAL-API 'HAL_TIMEx_HallSensor_Init()'; TIM1 is setup as a 3 channel PWM also via HAL-APIs.

When I generate the Commutation-Event for TIM1 in Software (in CaptureCallback of TIM2), TIM1 is working fine. But when I change the Commutation-Event-Generation in TIM1 to the ITR1 (TRGO from TIM2), the Commutation is never triggered. If I set the Commutation Delay >0, I got many Commutation-Events before I call 'HAL_TIMEx_HallSensor_Start()' and also without Hall-Signals (-> System is blocked by IRQ-Calls).

Is there an Example with Commutation of TIM1 through another Timer (via ITR)?

Best Regards

Stefan

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    March 7, 2017
    Posted on March 08, 2017 at 00:55

    Have you set TIM2_CR2.MMS to the proper OCxRef to source TRGO?

    And TIM1_SMC.TS to properly select source of TRGI?

    And have you set TIM1_CR2.CCUS to enable COM from TRGI?

    JW

    Stefan Hubacher
    Associate
    March 8, 2017
    Posted on March 08, 2017 at 11:28

    Hi

    I use the HAL-Functions to do this:

    - 'HAL_TIMEx_HallSensor_Init(&hTim2, &sHallConfig)'

    - 'HAL_TIMEx_ConfigCommutationEvent(&hTim1, TIM_TS_ITS1, TIM_COMMUTATION_TRGI)

    The first API setups the CC2 in PWM2-Mode and sets TIM2_CR2.MMS to OC2REF. The second API sets the TIM1_SMC.TS to ITS1 (=TIM2) and enables the CCUS-Bit. The TIM2_CCR2 is used to set a delay. When I set it to '0' (inside sHallConfig-Struct) I never get a Commutation-Event. When I set it to '>0' I get Commutation-Events without triggering TIM2.

    Stefan

    waclawek.jan
    Super User
    March 8, 2017
    Posted on March 08, 2017 at 12:19

    Ah. Maybe commutation is level-sensitive rather than edge-sensitive. Try setting CCR2 so that it outputs only a 1-tick-wide pulse.

    JW

    [EDIT] Do you or the 'library' clear the COMIF flag in TIMx_SR upon invocation of theISR?

    waclawek.jan
    Super User
    March 9, 2017
    Posted on March 09, 2017 at 02:00

    I wrote a simple test program with the same TIM2_CH2->TRGO->TRGI->TIM1_COM; and for me only one COM interrupt is triggered per TIM2 period.

    JW

    ________________

    Attachments :

    commutation.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HypT&d=%2Fa%2F0X0000000bCx%2F3xRHKYyTpitu2WnGe4x8KIYLEkFptMlXkWNKo7Rjgpc&asPdf=false
    Stefan Hubacher
    Associate
    March 9, 2017
    Posted on March 09, 2017 at 14:50

    Hi

     - Did you use the HAL-Library to do the configuration?

     - If not, what's the Output-Channel configuration of TIM2? PWM-Mode? OnePulse-Mode?

    SH