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 February 01, 2018 at 18:27

If the timer's run (given by ARR and PSC) is to be longer than the bouncing, then it's not needed - triggering an already running timer does nothing.

JW

Posted on February 01, 2018 at 18:34

And if he wanted the one-shot on button release he would need to filter/debounce for the press noise, no matter the period of the timer, unless the bounce is less than one sample, in which case ... he didn't need the filter.

Posted on February 01, 2018 at 18:44

Indeed - the same applies for release noise in case of shooting the one on button press.

One more remark - the value selected in that box is apparently not the number of samples taken, see TIMx_CCMR1.IC1F description in TIM chapter of RM.

JW

Darrin Weiss
Associate II
Posted on February 06, 2018 at 00:22

Thanks everyone.  Most things are easy, once you know the answer

Below is the STM32CubeMX config (for 2 timers, I got bold), and the info for Timer 2.  The timers should be started with this code:

HAL_TIM_OnePulse_Start(&htim1, TIM_CHANNEL_1);

HAL_TIM_OnePulse_Start(&htim2, TIM_CHANNEL_2);

I would now like to start Timer 2 from Timer 1 being started instead of the button (I have wired the button to Timer 1 as well).  Working to try to figure out that next.

0690X00000609cXQAQ.png0690X00000609chQAA.png
Posted on February 06, 2018 at 09:31

In TIM1 once set to trigger from the input (button), set TIM1_CR2.MMS to 0b001, so that enable signal is used as TRGO.

In TIM2, set TIM2_SMCR.TS to that Internal Trigger which is coming from TIM1, see TIM2 row of table at TIMx_SMCR description in RM. Then set TIM2_SMCR.SMS to 0b110 for Trigger mode.

That's all.

JW