STM8S Timer1 input capture issue

Discussion in 'Embedded Systems and Microcontrollers' started by Radio Ratiometrics, May 17, 2016.

  1. Radio Ratiometrics

    Thread Starter New Member

    Mar 7, 2016
    2
    0
    Hello am working with the timer1 input capture of an STM8S103F3. No input is registered by the input capture module though I fed it with square waves from 10Hz all the way up to 1MHz. The same square wave registers properly in the input capture module of a pic micro. I have seen that the PC6 (TIM1 Channnel1) pin is set to TIM1 channel1 as an alternate function but I have not found anything helpful in the STM8S standard development library. I have pasted my code below in case anyone can help thanks:


    #include "stm8s.h"



    void main()
    {
    CLK_DeInit();
    CLK_HSICmd(ENABLE);
    CLK_LSICmd(DISABLE);
    CLK_HSECmd(DISABLE);
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
    CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);






    GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_IN_PU_NO_IT);

    TIM1_DeInit();
    CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1 , ENABLE);

    TIM1_ICInit( TIM1_CHANNEL_1, TIM1_ICPOLARITY_RISING,TIM1_ICSELECTION_DIRECTTI,TIM1_ICPSC_DIV1, 0x00);
    TIM1_SelectInputTrigger(TIM1_TS_TI1FP1);
    TIM1_SelectSlaveMode(TIM1_SLAVEMODE_RESET);

    TIM1_ITConfig(TIM1_IT_CC1,ENABLE);
    TIM1_GenerateEvent(TIM1_EVENTSOURCE_CC1);
    TIM1_ClearFlag(TIM1_FLAG_CC1);
    TIM1_UpdateRequestConfig(TIM1_UPDATESOURCE_REGULAR);
    TIM1_Cmd(ENABLE);


    enableInterrupts();


    while (1);


    }


    /***********Contents of stm8s_it.c*********************/

    uint16_t Capture;
    uint8_t Buf[10];

    INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
    {
    if(TIM1_GetITStatus(TIM1_IT_CC1)==SET)
    {
    Capture=TIM1_GetCapture1();
    TIM1_ClearFlag(TIM1_IT_CC1);
    }
    }
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    Clearly there is a disconnect between the hardware and the library. Do you have the source code for the library? You might have to go spelunking to find the answer. That is you might have to dive into the library.

    https://en.wikipedia.org/wiki/Caving

    I see that the program has no scaffolding for looking at results. What is your evidence that things are not working?
     
  3. Radio Ratiometrics

    Thread Starter New Member

    Mar 7, 2016
    2
    0
    Hi papabravo thanks a lot for the reply. I will share a last test I did recently I used the generate event function in my code to check if the interrupt was working and it did so properly. to me the issue seems to come from the input pin(PC6) that could not be properly setup to the input capture module. I browsed the net and even in the STM8S code library they don't set the input pin at all like I did above GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_IN_PU_NO_IT); but even without that I still don't register any input capture. I have tried to check the STM8S standard peripheral library help to find an alternate input mapping function but no result. In case you have any suggestions its welcome thanks
     
Loading...