Skip to main content
keskintaylan
Associate
November 24, 2009
Question

STM8S103F2 TIMER EXAMPLE(needed please)

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

STM8S103F2 TIMER EXAMPLE(needed please)

    This topic has been closed for replies.

    11 replies

    keskintaylan
    Associate
    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 ]

    mozra27
    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

    keskintaylan
    Associate
    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 ]

    keskintaylan
    Associate
    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 ]

    mozra27
    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

    keskintaylan
    Associate
    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!

    mozra27
    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

    keskintaylan
    Associate
    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.

    */

    }

    .

    .

    .

    keskintaylan
    Associate
    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);

    }

    .

    .

    .

    .

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

    Hi,

    Sorry for the late answer,

    The FWLib is common for all STM8S family and by default the STM8S208 product is selected.

    The user can configure the target STM8S device used in his application in the stm8s, in your case you should make this configuration without updating any peripheral struct.

    #if !defined (STM8S208) && !defined (STM8S207) && !defined (STM8S105) && !defined (STM8S103) && !defined (STM8S903)

    /* #define STM8S208 */

    /* #define STM8S207 */

    /* #define STM8S105 */

    #define STM8S103

    /* #define STM8S903 */

    #endif

    Regards

    mozra