2020-01-11 08:08 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))
Main.c:
#include "stm8s.h"
//Pulse width measurment
unsigned char data_value;
unsigned long duty_cycle = 0;
unsigned long duty_cycle_temp = 0;
unsigned long start_time = 0;
unsigned long end_time = 0;
bool duty_cycle_updated=FALSE;
bool state=FALSE;
void clock_setup(void);
void GPIO_setup(void);
void TIM1_setup(void);
void TIM2_setup(void);
void delay_cycles(uint16_t cy);
void main() {
//Set PinMode
GPIOA->DDR |= 0xFF; // PD.0 as Output
GPIOA->CR1 |= 0xFF; // PD.0 as Push Pull Type Output
GPIOA->ODR |=1ODR &= ~(1
stm8s_it.c:(Top part only)
#include "stm8s_it.h" #include "stm8s_eval.h" #include "stm8s.h" static bool state = FALSE; extern unsigned long duty_cycle; extern unsigned long start_time; extern unsigned long end_time; static bool duty_cycle_updated=FALSE; unsigned long my_test_****=0; void TIM1_CH1_OVF_IRQHandler(void){ my_test_****++; } 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); }
stm8s_interupt_vector:
#include "stm8s_it.h" typedef void @far (*interrupt_handler_t)(void); struct interrupt_vector { unsigned char interrupt_instruction; interrupt_handler_t interrupt_handler; }; @far @interrupt void NonHandledInterrupt (void) { /* in order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction */ return; } extern void _stext(); /* startup routine */ struct interrupt_vector const _vectab[] = { {0x82, (interrupt_handler_t)_stext}, /* reset */ {0x82, NonHandledInterrupt}, /* trap */ {0x82, NonHandledInterrupt}, /* irq0 */ {0x82, NonHandledInterrupt}, /* irq1 */ {0x82, NonHandledInterrupt}, /* irq2 */ {0x82, NonHandledInterrupt}, /* irq3 */ {0x82, NonHandledInterrupt}, /* irq4 */ {0x82, NonHandledInterrupt}, /* irq5 */ {0x82, NonHandledInterrupt}, /* irq6 */ {0x82, NonHandledInterrupt}, /* irq7 */ {0x82, NonHandledInterrupt}, /* irq8 */ {0x82, NonHandledInterrupt}, /* irq9 */ {0x82, NonHandledInterrupt}, /* irq10 */ {0x82, (interrupt_handler_t)TIM1_CH1_OVF_IRQHandler}, /* irq11 */ {0x82, (interrupt_handler_t)TIM1_CH1_CCP_IRQHandler}, /* irq12 */ {0x82, NonHandledInterrupt}, /* irq13 */ {0x82, NonHandledInterrupt}, /* irq14 */ {0x82, NonHandledInterrupt}, /* irq15 */ {0x82, NonHandledInterrupt}, /* irq16 */ {0x82, NonHandledInterrupt}, /* irq17 */ {0x82, NonHandledInterrupt}, /* irq18 */ {0x82, NonHandledInterrupt}, /* irq19 */ {0x82, NonHandledInterrupt}, /* irq20 */ {0x82, NonHandledInterrupt}, /* irq21 */ {0x82, NonHandledInterrupt}, /* irq22 */ {0x82, NonHandledInterrupt}, /* irq23 */ {0x82, NonHandledInterrupt}, /* irq24 */ {0x82, NonHandledInterrupt}, /* irq25 */ {0x82, NonHandledInterrupt}, /* irq26 */ {0x82, NonHandledInterrupt}, /* irq27 */ {0x82, NonHandledInterrupt}, /* irq28 */ {0x82, NonHandledInterrupt}, /* irq29 */ };
stm8s_it.h(top part only):
#ifndef __STM8S_IT_H #define __STM8S_IT_H @far @interrupt void TIM1_CH1_OVF_IRQHandler(void); @far @interrupt void TIM1_CH1_CCP_IRQHandler(void); /* Includes ------------------------------------------------------------------*/ #include "stm8s.h"