cancel
Showing results for 
Search instead for 
Did you mean: 

Resetting a Timer

infoinfo966
Associate II
Posted on July 22, 2011 at 09:04

Hi,

I have the following problem.

I have a RFID-Reader Chips from Melexis (90109) connected to two GPIO Pins (Clock and Data).

I process the incoming data with an EXTI handler that is triggert on the falling edge of the clock pin.

This works fine.

To detect if a transponder has left the field I must detect if the clock line is no longer atcive for a certain amount of time.

My current approach is that I set up TIM2 as normal Timebase counter with an TIM_UPDATE IRQ-Handler as sort of watch dog for the clock line.

In the EXTI handler I tried to reset TIM2 with

  TIM_SetCounter(TIM2, 0);

so that as long as I receive clock pulses shorter than the timer period, the TIM2 Handler should not be called at all.

If the clock stops, TIM2 handler should set a flag to signals the main loop that the transponder was removed.

So far the idea, but reality shows that although I reset the TIM2 counter regulary I always get the TIM2 IRQ in it's normal period.

Do I have to reset/restart a timer in a different way?

Best

Tom
2 REPLIES 2
greg_t
Associate II
Posted on July 23, 2011 at 20:29

Hello,

Please post your TIM2 configuration

infoinfo966
Associate II
Posted on July 25, 2011 at 11:03

Hi,

here is my TIM2 config

// Timer to detect if transponder was removed

#define

TIMER_TAKT

10000

/* Timer wird mit 10kHz getaktet */

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

uint16_t PrescalerValue;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

// TIMER 2 Takt freigeben

PrescalerValue = (uint16_t) (SystemCoreClock / TIMER_TAKT) -

1

;

// Vorteiler berechnen

// Timer Grundkonfiguration

TIM_TimeBaseStructure.TIM_Period =

100

;

// Timer zählt von 0 ... 100: also alle 10ms

TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

TIM_TimeBaseStructure.TIM_ClockDivision =

0

;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

// Timer einstellen

//Timer Vorteiler-Taktkonfiguration

TIM_PrescalerConfig(TIM2, PrescalerValue, TIM_PSCReloadMode_Immediate);

// Auto-Reload

// Timer aktivieren

TIM_Cmd(TIM2, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

/* Enable the Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =

0

;

NVIC_InitStructure.NVIC_IRQChannelSubPriority =

1

;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

I attach an Screenshot of my LA, where you can see the clock in wich EXTI do

TIM_SetCounter(TIM2,

0

);

// reset watchdog counter as we still receive clock ticks

In the timer IRQ handler I toggle an IO port, which you can see in the bottom line:

Best

Tom

________________

Attachments :

Timer-Reset.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0rh&d=%2Fa%2F0X0000000bh5%2FPh6rP86fHT35bOaqG049yYz0VZ45GVztBJnFD5uCOfc&asPdf=false