2017-03-07 07:05 AM
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
2017-03-07 03:55 PM
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
2017-03-08 03:28 AM
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
2017-03-08 04:19 AM
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?
2017-03-08 01:20 PM
Hi
The TIM2 CC2 is configured by HAL according to the Reference Manual. The TRGI (from where the commutation is generated) should be edge-sensitive. But it could be, that this configuration is not the right one. Maybe a OnePulse-Setting would fit better. The COMIF is cleared by the 'HAL_TIM_IRQHandler'.
2017-03-08 05:00 PM
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=false2017-03-09 06:50 AM
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