2013-02-14 5:30 AM
Hello.
As described on STM32F100 manual:The OCxREF signal for a given channel can be driven Low by applying a High level to the ETRF input (OCxCE enable bit of the corresponding TIMx_CCMRx register set to ‘1’). The OCxREF signal remains Low until the next update event, UEV, occurs.
For example, the OCxREF signal) can be connected to the output of a comparator to be used for current handling.
I am trying to do this, and I am using 3 PWM for BLDC motor control (wich works very well for now but lacks current control). I am using OC1, OC2 and OC3 for PWM generation.When ETR pin is active (output of a LM258 comparator when over current), ONLY the OC3Ref signal is clear and so I only get PWM channel 3 off on over current while channel 1 and 2 should also be off.Where is the code configuration for ETR:
GPIO_InitStructure
.
GPIO_Pin
=
GPIO_Pin_12
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_50MHz
;
GPIO_Init
(
GPIOA
,
&
GPIO_InitStructure
);
/* configure ETR for current control */
TIM_ETRConfig
(
TIM1
,
TIM_ExtTRGPSC_OFF
,
TIM_ExtTRGPolarity_NonInverted
,
0
);
TIM_ClearOC1Ref
(
TIM1
,
TIM_OCClear_Enable
);
TIM_ClearOC2Ref
(
TIM1
,
TIM_OCClear_Enable
);
TIM_ClearOC3Ref
(
TIM1
,
TIM_OCClear_Enable
);
My code is here:
This is an OpenSource motor BLDC controller, project page: Right now the motor works very well, including the Hall Sensor and Brake (using STM32 hardware for this). The only thing missing is over current control.Thank you in advance.2013-02-15 2:45 AM
Check (read out in real application) content of TIM1_CCMR1 and TIM1_CCMR2.
JW2013-02-16 5:00 AM
Thank you. Now the code works perfect.
I were doing this during the program to turn off the PWM:TIM_ForcedOC2Config(TIM1, TIM_ForcedAction_InActive); // disable PWMTurns out that it changed the initial configuration.2013-02-19 2:03 PM
I recorded a video showing current control working:
2013-02-19 2:20 PM
2013-02-20 2:27 AM
I don't get it - TIM_ForcedOC2Config() is not supposed to change the OC2CE bit, so it should not affect the PWM behaviour once it's restored.
Or have I overlooked something? JW2013-02-22 2:42 PM
Seems that TIM_ForcedOC2Config() disables PWM1 mode I am using and so when configuring again to PWM1 mode is needed to setup the correct bits again. Maybe leaving out PWM1 mode ''resets'' some bits on the register.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.