cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER EXTERNAL CLOCK

jonfs2000
Associate II
Posted on August 13, 2013 at 16:05

Hi,

Could someone explain me how external clock for timer is done. Specially I don't understand how TI1, TI2 etc., are mapped to the physical pin.

Alternate function on GPIO is mapped to different timers but is it the TIx pins?

Thanks

John

#external-clock-timer-ti2-ti1
4 REPLIES 4
Posted on August 13, 2013 at 17:59

0690X00000605VSQAY.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jonfs2000
Associate II
Posted on August 14, 2013 at 15:09

Thanks for your answer.

I have problem getting the TIMER2 working. 

I am polling for the UIF flag on my while loop. But it is never set. (BTW I did not use the library but by writing to registers)

Here is my code.

/

**--------- MAIN -----------*/

while(1)

 

{

 

    if

((TIM2->

SR

& 0x0001) == 0x001)          

// Check for UIF flag

    {

        GPIOD->

ODR

|= 0x2000;                       

// turn on led

        TIM2->

SR

&= 0xfffe;                            

// Clear the flag

    }

}

/***------- TIMER 2 INITIALISE ------------*/

void

InitTimer2()

{

// Enable the clock for TIMER 2

RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM2,

ENABLE

);

 

 

 //NOT holding in reset

RCC->

APB1RSTR

&= ~RCC_APB1RSTR_TIM2RST;

//TIMxCR1 -- Control Register 1

TIM2->

CR1

= 0x0000;

TIM2->

CR1

|= TIM_CR1_ARPE;         

//Auto

Preload

Enable is buffered 

 

/*------ TIM2_CR2 CONTROL REGISTER 2 ----*/

TIM2->

CR2

= 0x00;

// Don't care for now 

 

/*------ TIM2_SMXR Slave Mode

Ctrl

REGISTER ----*/

                                        // Selects the internal clock

TIM2->

SMCR

= 0x00;

// 

 

/*------ TIM2_DIER Interrupt/DMA Enable Register ----*/

TIM2->

DIER

= 0x0000;

TIM2->

DIER

|= TIM_DIER_UIE;        

// Update interrupt Enable

 

TIM2->

PSC

= 0x0f;                          

// Prescalar 

TIM2->

ARR

= 0xffff;     

             

// Auto Reload register

 

TIM2->

SR

&= 0xfffe;              

// Clear the UIF flag 

TIM2->

CR1

|= TIM_CR1_CEN;     

// Counter Enable

 }  Thanks

John

Posted on August 14, 2013 at 16:38

I don't care for register level programming, you'll need to own that choice.

RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);  << NOT AHB1

TIM2->SR &= 0xfffe;  << NOT RMW, just WRITE 0xFFFE (ie ~1)

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

Thank you clive for spotting the mistake.

Everything works now

.

Writing to registers gives me more understanding (for getting started). Will switch to libraries once I understood how things work.(right practice??). Thanks Again

John