2020-01-11 08:03 PM
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))
2020-01-16 10:10 PM
with little informatin can't getting idea
2020-01-21 12:42 AM
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.