cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32L053] TIM21 reload value

stanzanim
Associate III
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 discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
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 Venmo
Up vote any posts that you find helpful, it shows what's working..
stanzanim
Associate III
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)