Skip to main content
Jhabi
Associate
January 12, 2020
Question

TIM1 doesn't work on STM8S003F3PU

  • January 12, 2020
  • 2 replies
  • 1404 views

Hello

I'm Using STM8S003F3PU mini-eval Board. My software is STVD and Cosmic.

Why My TIM1 don't work truly? It should measure the input signal HIGH_Duration on TIM1_CH1 (= PC6) and my led on PA3 turned off. But that's not so. Furthermore, I use debug mode but it doesn't enter my condition( if(duty_cycle_updated))

    This topic has been closed for replies.

    2 replies

    dbgarasiya
    Senior
    January 17, 2020

    with little informatin can't getting idea

    Jhabi
    JhabiAuthor
    Associate
    January 21, 2020

    Excuse me for Incomplete Post.

     void TIM1_setup(void){
     TIM1_DeInit();
     TIM1_TimeBaseInit(2000, TIM1_COUNTERMODE_UP, 55535, 1);
     TIM1_CCxCmd(TIM1_CHANNEL_1, ENABLE);
     TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, 1, 1);
     TIM1_ITConfig(TIM1_IT_CC1, ENABLE); 
     TIM1_Cmd(ENABLE);
     enableInterrupts();
    }

    stm8s_it.c:

    void TIM1_CH1_CCP_IRQHandler(void){
     if(TIM1_GetFlagStatus(TIM1_FLAG_CC1)) {
     if(state == FALSE) {
     start_time = TIM1_GetCapture1();
     TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_FALLING, TIM1_ICSELECTION_DIRECTTI, 1, 1);
     }
     else {
     end_time = TIM1_GetCapture1();
     TIM1_ICInit(TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING, TIM1_ICSELECTION_DIRECTTI, 1, 1);
     duty_cycle = (end_time - start_time);
    							duty_cycle_updated=TRUE;
     }
     state = ~state;
     }
     TIM1_ClearITPendingBit(TIM1_IT_CC1);
     TIM1_ClearFlag(TIM1_FLAG_CC1);
    }

    Full project attached.