cancel
Showing results for 
Search instead for 
Did you mean: 

Timer simply as a counter

h239955_stm1_stmicro
Associate II
Posted on November 03, 2004 at 06:07

Timer simply as a counter

4 REPLIES 4
h239955_stm1_stmicro
Associate II
Posted on October 18, 2004 at 12:52

Hi! Does anybody knows / has an exapmle for using one of the timer as a counter without using the GPIO. Just initialize the timer, set an external variable to a specific value wich will be counted down/up by the interruptroutine. In my program, i use the timer just as a counter but

my main problem is the prescalervalue. I can change it between 0xf and 0xf0 and the time between 2 interrupts will change from 31 microseconds to 148 microsecond. This seems to be very short. I would like to have times around 10-100 milliseconds between an interrupt. So, perhaps i have something forgotten to initialize and somebody has a suggestion?

hein_b

void start_time1(ushort x_in_sek)

{

u32 sekundenfaktor=1; // 10

timer1_cnt = 0x1*sekundenfaktor*x_in_sek; // 0x300 *...

Myprescaler1=0x50;

// just for time-measurements (not necessary for real program)

// Configure Port 2 pins

GPIO_Config (GPIO0, 0xFFFF, GPIO_OUT_PP);

GPIO0->PD = 0x0000;

// Initialize the Timer

TIM_Init ( TIM1 );

//---------------------------------------------------------------------------

// Configure the EIC Timer1 IRQ channel

//---------------------------------------------------------------------------

EIC_IRQChannelConfig( T1TIMI_IRQChannel, ENABLE );

EIC_IRQChannelPriorityConfig( T1TIMI_IRQChannel , 1);

EIC_IRQConfig( ENABLE );

// Configure the TIM Prescaler

TIM_PrescalerConfig ( TIM1, Myprescaler1 );

// Enable the OverFlow Interrupt

TIM_ITConfig ( TIM1 , TIM_TO_IT , ENABLE );

TIM_CounterConfig ( TIM1, TIM_START );

// own flags

timer1_fin = 0; // ;timer ist noch nicht abgelaufen

timer1_run = 1; // ;timer laeuft

time_out = 0;

return;

}

// routine, called by the interruptprogram

void cnt_dwn1()

{

if (timer1_run==1) // und der timer laeuft

{

if (timer1_cnt > 0) // und noch nicht abgelaufen ist

{

timer1_cnt -=1; // dann einen runterzaehlen

// GPIO0->PD = ~GPIO0->PD; //just for time measurement

}

else

{

time_out = 1; // sonst time_out flag setzen!

}

}

}

h239955_stm1_stmicro
Associate II
Posted on October 28, 2004 at 09:58

Thx for Help. Your suggestion was't the problem. Timerproblem is solved now, i had problems to understand the TIM_OCFA feature.

johnchang
Associate II
Posted on November 02, 2004 at 06:39

I have the same question.

Could you give me some advice?
johnchang
Associate II
Posted on November 02, 2004 at 07:03

The overflow interrupt works properly.

But I still want to know more information about OCFA.

For example:

How to make a interrupt when TIMn_CNTR matches TIMnOCAR.

Thanks for your help