Skip to main content
Visitor II
November 24, 2009
Question

STM8S103F2 TIMER EXAMPLE(needed please)

  • November 24, 2009
  • 11 replies
  • 1831 views
Posted on November 24, 2009 at 06:49

STM8S103F2 TIMER EXAMPLE(needed please)

    This topic has been closed for replies.

    11 replies

    Visitor II
    May 17, 2011
    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 ]

    Visitor II
    May 17, 2011
    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

    Visitor II
    May 17, 2011
    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 ]

    Visitor II
    May 17, 2011
    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!

    Visitor II
    May 17, 2011
    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

    Visitor II
    May 17, 2011
    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 ]

    Visitor II
    May 17, 2011
    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);

    }

    .

    .

    .

    .

    Visitor II
    May 17, 2011
    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.

    */

    }

    .

    .

    .

    Visitor II
    May 17, 2011
    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

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:05

    I did it, yeah i did it! :-]

    The problem is weird...:

    I disassemble the code. I check this '' TIM2->IER = 1; '' and i see in disassembler '' MOV 0x5301,#0x01 '' but TIM2 interrupt register address is 0x5303. Then i check STM8S.h -> I found there :

    typedef struct TIM2_struct

    {

    vu8 CR1;

    #if defined STM8S103

    vu8 RESERVED1;

    vu8 RESERVED2;

    #endif

    vu8 IER;

    vu8 SR1;

    .

    .

    .

    .

    }

    Then i realize that the compiler don't see reserved bits.Thus IER's address was 5301. So i remove defines and tataaa... program worked.

    But still i don't understand why compiler passover reserved bits? Why ''#if defined STM8S103'' didn't work?

    Thank you anyway mozra...

    [ This message was edited by: keskintaylan on 21-11-2009 13:19 ]