AnsweredAssumed Answered

TIM1 counter

Question asked by Klszcz on Mar 8, 2012
Latest reply on Mar 13, 2012 by Klszcz
Hello,
I try measure frequency 50-500Hz. I use STM8S-DISCOVERY KIT with STM8S105C6T6 and FWLib. How initiate the appropriate timer and which port to use?

#include "stm8s_conf.h"
#include "stm8s.h"
#include "stm8s_it.h"
#include "stm8s_tim1.h"
#include "stm8s_gpio.h"
 
void init(void);
void GPIO_app_init(void);
void TIM1_app_init(void);
 
main()
{
    init();
    enableInterrupts();
while (1)
    {
        TIM1_SetCounter(5);
        tim1freq = TIM1_GetCounter();
    }
}
 
void init(void)
{
    GPIO_app_init();
    TIM1_app_init();
    return;
}
 
void GPIO_app_init(void)
{
}
void TIM1_app_init()
{
    TIM1_DeInit();
 
    TIM1_TimeBaseInit(31, TIM1_COUNTERMODE_UP, 65535, 0)
    TIM1_CounterModeConfig (TIM1_COUNTERMODE_UP);
    //TIM1_ICInit(TIM1_CHANNEL_1,TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1,0 );
    TIM1_Cmd(ENABLE);
}

Outcomes