cancel
Showing results for 
Search instead for 
Did you mean: 

Clearing the OCxREF signal on an external event

casainho
Associate II
Posted on February 14, 2013 at 14:30

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:

https://github.com/casainho/EBike-Smart-Controller/blob/8461b455ac4f96b2241e3a312c9c726ff0795221/firmware/pwm.c

This is an OpenSource motor BLDC controller, project page: 

http://smartebike.likesyou.org/

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.
6 REPLIES 6
Posted on February 15, 2013 at 11:45

Check (read out in real application) content of TIM1_CCMR1 and TIM1_CCMR2.

JW
casainho
Associate II
Posted on February 16, 2013 at 14:00

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 PWM

Turns out that it changed the initial configuration.

casainho
Associate II
Posted on February 19, 2013 at 23:03

I recorded a video showing current control working:

http://www.youtube.com/watch?v=i0VohXLZfCA

Nickname12657_O
Associate III
Posted on February 19, 2013 at 23:20

0690X0000060MlyQAE.gif

Posted on February 20, 2013 at 11:27

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?

JW

casainho
Associate II
Posted on February 22, 2013 at 23:42

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.