cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100VLDISCOVERY & One Pulse Mode (TIM2) Triggered by Button

Darrin Weiss
Associate II
Posted on January 30, 2018 at 15:52

 I am trying to understand how to configure a timer in one pulse mode, using the STM32F100VLDISCOVERY board.  I have used STM32CUBEMX to configure the blue button (PA0) as TIM2_CH1 ('Channel 1 input capture direct mode'), and PA1 as TIM2_CH2 '(Channel2 PWM Generation').   (STM32CUBEMX project attached).

I added a single line to the project, just after the line that says: 'MX_TIM2_Init();'  :

HAL_TIM_OnePulse_Start(&htim2, TIM_CHANNEL_2);

When I press the Blue Button, I see the 'CC1IF' bit (SR register) momentarily toggle.  But I don't see a pulse on PA1.

I imagine I'm still missing a line of code or two, advice/assistance is greatly appreciated.

#one-pulse-mode #stm32f100vldiscovery
14 REPLIES 14
Posted on January 30, 2018 at 16:18

Read out and check/post the content of relevant GPIO and TIM registers.

JW

Posted on January 30, 2018 at 16:34

0690X00000609YGQAY.png 0690X00000609YBQAY.png
Posted on January 30, 2018 at 17:17

In timer, you want to have SMCR.TS set to TI1FP1 and SMCR.SMS set to Trigger Mode - thus pressing the blue button starts the timer. You also want to have a nonzero CCR2 otherwise your output pulse length is zero.

You can try to set all this in the debugger, you don't need to write any code to try.

I don't Cube so I don't know how to click this in CubeMX nor write in Cube's terms.

I did not check GPIO - sorry, I don't use 'F1xx and their GPIO is different from the others.

JW

Posted on January 30, 2018 at 17:57

Thanks for the help so far!  So in STM32CUBEMX I can set Slave Mode to ''Trigger Mode''.  But TI1FP1 is not an available choice in Trigger Source (it is grayed out, see screenshot).

0690X00000609YQQAY.png
Darrin Weiss
Associate II
Posted on February 01, 2018 at 16:24

Bump

Posted on February 01, 2018 at 16:41

As I've said, I don't and won't Cube/CubeMX so can't help with the clicking, sorry.

JW

John Craven
Senior
Posted on February 01, 2018 at 18:07

You have channel1 set as input. This locks using TI1FP1 as a trigger.

Set channel1 to disabled.

Then you will be able to choose TI1FP1 as the trigger.

0690X00000609WuQAI.png
henry.dick
Senior II
Posted on February 01, 2018 at 18:10

What you are trying to do is quite easy if you simply follow the datasheet. Set up the time base, set up the output compare module, but put it in freeze:OCiM = 0b000.

Once a button press is detected, put the OCiM in one pulse mode. And optionally reset the counter.

One thing through, a button press is a dirty source so some form of debouncing would be desirable.

John Craven
Senior
Posted on February 01, 2018 at 18:17

If you are using a mechanical switch,

apply the Trigger Filter = 15 (most filtering or debounce)

filter is the number of trigger samples the trigger signal has be stable before the input signal to the timer changes.

0690X00000609ZsQAI.png

see RM;

0690X00000609PpQAI.png0690X00000608yQQAQ.png