cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32f4 discovery timers

ivan88go
Associate II
Posted on November 03, 2013 at 19:57

Hi all!

this is my first post I apologize for the banality of the subject, but they are just starting out with programming the micro.

I wanted to ask if it is possible to utilize two timers, where the first increase of one unit the second just complete the period.

is possible to obtain an example in code?

thanks to all

#stm32 #timer #discovery
6 REPLIES 6
Posted on November 03, 2013 at 22:11

Master-Slave mode?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ivan88go
Associate II
Posted on November 04, 2013 at 07:05

may better explain the difference between the two modes?

Posted on November 04, 2013 at 15:13

I'd start with the Reference Manual, and then work through the timer examples. STM32F4xx_DSP_StdPeriph_Lib_V1.2.0\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_ExtTriggerSynchro

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ivan88go
Associate II
Posted on November 11, 2013 at 17:23

I found a possible solution. I created a timer that generates a PWM channel CH1 of tim2. Now I could use a timer that takes as input the PWM how could I do?

ivan88go
Associate II
Posted on November 11, 2013 at 17:24

I found a possible solution. I created a timer that generates a PWM channel CH1 of tim2. Now I could use a timer that takes as input the PWM how could I do?

samehta3
Associate
Posted on December 18, 2013 at 08:05

Hello, I m new in micro-controller programming  world, so i have a problem regarding timer, plz help..

 I wish to count no. of pulses in 1 sec, for that i have to create a loop of 1 sec , But I  am unable to prescale counter,some more commands might be needed, here is the code

 RCC_APB1ENR  |= TIM3EN;  

 TIM3_PSC = 10000;

 TIM3_ARR =4200;

 TIM3_CR1   |=0x01;      // CNTR ENABLE 

 while((TIM3_SR & 0x01) != 0x01)  // condn for  countr overflow flag set

 {

           count1++;

 }

TIM3_SR  &= ~(0x01);

 while((TIM3_SR & 0x01) != 0x01)  // condn for  countr overflow flag set and loop of 1sec

 {

  count3++;

 }  

this is for timer and prescaller only bt the overall code is

 #include ''defines.h'' 

int volatile  count1 , count2 , count3, count4 , count5 ,count6 ;

int main()

{

  

  

  count1 = 0;

  count2 = 0;

  count3 = 0;

  count4 = 0;

  count5 = 0;

  count6 = 0;

  

//-------------clock-----------------------------------

 

  RCC_APB1ENR  |= TIM3EN;                                  //  TIM  CLOCK, TIMR ENABLE

  RCC_AHB1ENR  |= (GPIOBEN | GPIOAEN  );                  // GPIO

//-------------GPIO CONFIG----------------------------------

 GPIOA_MODE   |= (MODER_AF_PIN6 );      // MODER  PIN A6= TIM3 CH1

 GPIOA_OSPEED |= (SPEEDR_100MHZ_6);    //SPEED 100MHZ

 GPIOA_PUPDR  |= (PUPDR_UP_PIN6);     // PUPD IS UP

 

 

  GPIOA_AFRL  |=  0x02000000 ;    // PA6 CONNECTED TO AF TIM3 CH1

  

TIM3_CCMR1 |= 0x01;        // CC1S= 01, channel is configured as input, IC1 is mapped on TI1.

TIM3_CCMR1 |= 0x30;       // IC1F= 0011 FILTER BY 8 CYCLES

TIM3_CCER  |=0x00 ;    // CC1P=CC1NP= 00 ACTIVE EDGE SELECTION

TIM3_PSC = 10000;

TIM3_CR1 |=0x00;       // CNTR IN UPCOUNTING MODE, DIR =UPCOUNTING

TIM3_CCER  |=0x01 ;     //    Enable capture from the counter into the capture register

TIM3_ARR   =4200;

 //----------------capture counter value----------------

TIM3_CR1   |=0x01;      // CNTR ENABLE  

while((TIM3_SR & 0x01) != 0x01)  // condn for  countr overflow flag set

 {

                  

count1++;

 }

TIM3_SR  &= ~(0x01);

 while((TIM3_SR & 0x01) != 0x01)  // condn for  countr overflow flag set

    {

      count2++;

          if( (TIM3_SR & 0x02) == 0x02)

           {

              count3++;

               count4 = TIM3_CCR1;

        

                if( (TIM3_SR & 0x0100) ==0x0100 )

                     {

                          count3++;    

                               count4 = TIM3_CCR1;

                         }

        

         }

     }

 

}

here the aim is, count3 will give the no. of pulses in 1 sec...

but i am also not sure that the main clock is 42 mhz...

if possible then plz suggest me how to configure main clock too...

and 1 more thing, its giving  exact no. of  pulses in 1 sec when ARR is set to 1600 in above program .So, it means the  clock should be 16 Mhz,..is it so? and how?

 suggestions plz...