Skip to main content
Darrin Weiss
Associate
January 30, 2018
Question

STM32F100VLDISCOVERY & One Pulse Mode (TIM2) Triggered by Button

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
    This topic has been closed for replies.

    14 replies

    waclawek.jan
    Super User
    January 30, 2018
    Posted on January 30, 2018 at 16:18

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

    JW

    Darrin Weiss
    Associate
    January 30, 2018
    Posted on January 30, 2018 at 16:34

    0690X00000609YGQAY.png 0690X00000609YBQAY.png
    waclawek.jan
    Super User
    January 30, 2018
    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

    Darrin Weiss
    Associate
    February 1, 2018
    Posted on February 01, 2018 at 16:24

    Bump

    waclawek.jan
    Super User
    February 1, 2018
    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
    February 1, 2018
    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
    Associate II
    February 1, 2018
    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
    February 1, 2018
    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
    waclawek.jan
    Super User
    February 1, 2018
    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

    John Craven
    Senior
    February 1, 2018
    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.

    Darrin Weiss
    Associate
    February 5, 2018
    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
    waclawek.jan
    Super User
    February 6, 2018
    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