cancel
Showing results for 
Search instead for 
Did you mean: 

STM 32F4 Timers Step By Step

pic_micro
Associate II
Posted on October 17, 2014 at 18:40

Dear All

I would like to start a discuss about STM32F4 series timers operation while learning and understanding. Please share your idea and experience to explain each red circles from number 1 in the attached picture

Any one can have an idea of operation red circles 1 in the attached picture

0690X0000060MmkQAE.gif

4 REPLIES 4
Posted on October 17, 2014 at 20:02

Not clocked at 42 MHz

0690X00000605BNQAY.png

Lot of

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/47046/Edge_Aligned_PWM_TIM3.png

there, nothing personal, but I'm not going to read and interpret the timer chapter(s) for you. You'll need to read the docs to yourself and decimate that significantly.

0690X0000060MmlQAE.gif

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on October 18, 2014 at 08:43

Dear All 

Following program get one error which is Timer.c(23): error:  #268: declaration may not appear after executable statement in block

The error point this line

  TIM_TimeBaseInitTypeDef timerInitStructure;

-----------------------------------------------------------------------------------

#include ''stm32f4xx.h''

#include ''stm32f4xx_tim.h''

void InitializeLEDs();

void InitializeTimer2();

void InitializeLEDs(){

GPIO_InitTypeDef GPIO_Structure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    GPIO_Structure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13; 

    GPIO_Structure.GPIO_Mode = GPIO_Mode_OUT;

    GPIO_Structure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOD, &GPIO_Structure);

    GPIO_WriteBit(GPIOD, GPIO_Pin_12 | GPIO_Pin_13, Bit_RESET);

}

void InitializeTimer2(){

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);

   

    TIM_TimeBaseInitTypeDef timerInitStructure;

    timerInitStructure.TIM_Prescaler = (uint16_t) (((SystemCoreClock / 1000000) / 2) - 1);

    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

    timerInitStructure.TIM_Period = 65535;

timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

timerInitStructure.TIM_RepetitionCounter = 0;

    TIM_TimeBaseInit(TIM2, &timerInitStructure);

    TIM_Cmd(TIM2, ENABLE);

}

int main (){

InitializeLEDs();

InitializeTimer2();

for (;;)

    {

        int timerValue = TIM_GetCounter(TIM2);

        if (timerValue == 400)

            GPIO_WriteBit(GPIOD, GPIO_Pin_12, Bit_SET);

        else if (timerValue == 500)

            GPIO_WriteBit(GPIOD, GPIO_Pin_12, Bit_RESET);

    }

 

  

}

Posted on October 18, 2014 at 14:13

0690X00000605BSQAY.png

Images up to 100KB can be place in-line via the Word-in-a-box(tm) interface.

The Reference Manual is the best place to start, it's admittedly rather heavy going, but timers on most device are complicated things, trying to be all things to all people. The design has several frustrating weaknesses.

One of the first to get your head around is that there is a SINGLE counting element (ignoring the prescaler and repetition which have specific utility), the channels provide four latching/comparing elements, but do not count anything.

Another is that everything is integer, to hit specific frequencies they must neatly divide into the source clock, so you might need to run the processor at lower speeds or use magic crystals, or baby sit the timers.

Do you have experience with other timer devices, or silicon design implementation/understanding?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on October 19, 2014 at 06:23

Dear clivel 

Grate thanks for the reply

The Reference Manual is the best place to start, it's admittedly rather heavy going, but timers on most device are complicated things, trying to be all things to all people. The design has several frustrating weaknesses.

Yes, as you pointed out the said Manual not well documented, that is the reason I decided to start this discussion

One of the first to get your head around is that there is a SINGLE counting element (ignoring the prescaler and repetition which have specific utility), the channels provide four latching/comparing elements, but do not count anything.

Do you have experience with other timer devices, or silicon design implementation/understanding?

Yes, I have enough  experience of theory and practicals for 8 bit micro controller other than ARM.

I am expecting more advice from you

Thanks in advance