Skip to main content
stanzanim
Associate III
November 25, 2015
Question

[STM32L053] TIM21 reload value

  • November 25, 2015
  • 2 replies
  • 621 views
Posted on November 25, 2015 at 17:48

I cannot find any function which allow me to change the reload value (supposedly stored in ....Init.Period member of the timer struct). Should I rerun Cube MX and change the counter period in the the TIM21 settings panel? is there any drawback on changing this on the fly?

thanks
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    November 25, 2015
    Posted on November 25, 2015 at 18:51

    Couldn't you use something like TIM21->ARR = NewPeriod; ?

    The preload settings would determine if this is taken immediately, or at the next update.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    stanzanim
    stanzanimAuthor
    Associate III
    November 26, 2015
    Posted on November 26, 2015 at 11:04

    h

    ello clive

    I found this macro which does the job

      __HAL_TIM_SET_COMPARE(&htim21, 1, 6400/2);

    Then I cannot make the OC feature for TIM21 working: I am having Nucleo64 (STM32L053) as target I want to use the TIM21 OC for generating a periodic square wave at PB13 (OC channel 1). I set up the project with CubeMX enabling TIM21 output compare etc.

    To check the PB13 is alive I tried first to set the OCMODE to 'forced output'

      sConfigOC.OCMode = TIM_OCMODE_FORCED_ACTIVE;

    I then was expecting PB13 goes high but this does not happen :(

    I then went back to the option as generate by CubeMx

      sConfigOC.OCMode = TIM_OCMODE_TOGGLE;

    I set AAR = 6400(htim21.Init.Period = 6400;)

    and the comapre register at 3200 for channel 1

      __HAL_TIM_SET_COMPARE(&htim21, 1, 6400/2);

    Before the while(1) loop I execute

     //HAL_TIM_Base_Start(&htim21);

     HAL_TIM_OC_Start(&htim21, 1);

    expecting a waveform with 50%% duty cycle with 6400 clock cycle of period.

    APB13=0 forever ...

    please advice (I feel I am doing something completely wrong)