cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S103F2 TIMER EXAMPLE(needed please)

keskintaylan
Associate II
Posted on November 24, 2009 at 06:49

STM8S103F2 TIMER EXAMPLE(needed please)

11 REPLIES 11
keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

Dear Mozra, thanks for your reply.

I tried your code.But counters still don't work.

While debugging i can see TIM2's REGISTERS. And also TIM2_CNTRH & TIM2_CNTRL.

I check these step by step, and there isn't any count.They are always ''0'' Is it normal? Is it a bug? Also i put a breakpoint in

''void TIM2_UPD_OVF_BRK_IRQHandler(void) interrupt 13''

And program never stopped.

What's wrong? :-[

I really need it. It's very important for me!

[ This message was edited by: keskintaylan on 19-11-2009 15:39 ]

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Hi,

you can find below an example using Timer2:

/* TimerTick = 5 ms

Warning: fcpu must be equal to 16MHz

fck_cnt = fck_psc/presc = fcpu/512 = 31.25 kHz --> 1 tick every 32 µs

==> 5 ms / 32 µs = 156 ticks

*/

TIM2_TimeBaseInit( TIM2_PRESCALER_512, 156);

TIM2_UpdateRequestConfig(TIM2_UPDATESOURCE_GLOBAL);

TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);

/* Enable interrupts */

enableInterrupts();

TIM2_Cmd(ENABLE);

Regards

mozra

keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

Hi everybody.

I have a problem with timers on STM8S103F2.

I'm using RIDE. I need UPD/OV interrupt urgently. I tried all of timer examples but i have nothing.Counters didin't work.(on debug screen)They are always ''0''.Interrupt was never occured!

PLEASE! give me an example of TIM2 UPD interrupt or tell some tips. Some told that i must edit STM8S.h, but how,where,what?

I will be appreciate if answered quickly...

Thank you...

[ This message was edited by: keskintaylan on 19-11-2009 12:05 ]

keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

Please & Please:

Send me a full project about TIM2 UPD&OV writing with RIDE. GPIOA.3 must toggle in interrupt routine.

Please send with using ''h'' & ''c'' files.

And please try yourself, be sure it's working.

Very very appreciate who helps.

THANK YOU!

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Hi,

Can you please check the status for the PCKEN15 bit in CLK_PCKENR1 this bit should be kept set(reset value)?

you can set this bit using:

CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);

Regards

mozra

keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

Dear Mozra

While debugging

CLK_PCKENR1 = 0xFF;

[ This message was edited by: keskintaylan on 19-11-2009 16:39 ]

keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

Dear Mozra,

I used STVD as you suggest.Yes timer is working.Thank you for your suggest.I guess too that RIDE have issues.

But interrupt didn't work.

Here is my codes:

.

.

.

.

void Init_TIM2(void)

{

/* TimerTick = 5 ms

Warning: fcpu must be equal to 16MHz

fck_cnt = fck_psc/presc = fcpu/512 = 31.25 kHz --> 1 tick every 32 µs

==> 5 ms / 32 µs = 156 ticks

*/

TIM2_TimeBaseInit( TIM2_PRESCALER_512, 156);

TIM2_UpdateRequestConfig(TIM2_UPDATESOURCE_GLOBAL);

TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);

/* Enable interrupts */

enableInterrupts();

TIM2_Cmd(ENABLE);

}

void main(void)

{

Init_TIM2();

GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);

while(1);

}

.

.

.

.

keskintaylan
Associate II
Posted on May 17, 2011 at 15:05

in ''stm8s_it.c''

#include ''stm8s_it.h''

.

.

.

#ifdef _COSMIC_

@far @interrupt void TIM2_UPD_OVF_BRK_IRQHandler(void)

#else /* _RAISONANCE_ */

void TIM2_UPD_OVF_BRK_IRQHandler(void) interrupt 13

#endif /* _COSMIC_ */

{

//GPIO_WriteReverse(GPIOA, GPIO_PIN_3);

GPIO_WriteHigh(GPIOA, GPIO_PIN_3);

TIM2_ClearITPendingBit(TIM2_IT_UPDATE);

/* In order to detect unexpected events during development,

it is recommended to set a breakpoint on the following instruction.

*/

}

.

.

.

mozra27
Associate II
Posted on May 17, 2011 at 15:05

Hi,

It seems that is an issue with RIDE and is under investigation you can use STVD + Raisonance to avoid temporarily this issue

Regards

mozra