cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, I had developed one application using STVD

Siddharth Kachhia
Associate II
Posted on March 25, 2017 at 10:03

#include 'Filter.h'

#define Samples 3

#include <math.h>

#include <stdlib.h>

extern unsigned long int data;

long int Result_Previous,Average,;

unsigned char Stable;

void FIR_Filter(unsigned long int Clean)

{

    static unsigned char Index=0;

//    static bit_16 Index1=4000;

    static unsigned long int ADC_Mean[Samples];

    

    unsigned long int Absolute;

    unsigned char Count;

//    Average = Clean>>5;

    Clean >>= 5;

    ADC_Mean[Index] = Clean;

    Average = 0;

    {    

        for(Count=0;Count<Samples;Count++)

        {

            Average+=ADC_Mean[Count];

             }

        Average /= Samples;

    }

    if(Index >= (Samples-1))

        Index=0;

    else

        Index++;

    Absolute = abs(Average - Result_Previous);

    

   if(Absolute <5)

    {

        Average = Result_Previous +((Average - Result_Previous)>>2);

    }

    if(Absolute<3)

        Stable++;

    else

        Stable=0; 

    

    Result_Previous = Average;

//    return (Average);

        data = Average;

}

this is my code in interrupt function.. i think problem with this statement addition in variable not working in interrupt function  ' Average+=ADC_Mean[Count];'

how can addition in that variable??

Help me for this.. Thank you..

6 REPLIES 6
S.Ma
Principal
Posted on March 25, 2017 at 15:07

Unclear. Interrupt routine should be as short as possible = as little computation as possible.

What is the signal triggering the interrupt? Which frequency?

Try to do the minimum in the interrupt, pass the result in a dedicated global register and set a RAM flag (to prevent future interrupts to corrupt the data). The main loop will wait for the flag, grab the data, divide, and clear the flag.

Arlet Ottens
Associate II
Posted on March 25, 2017 at 15:25

If you're modifying global variables inside an interrupt handler, and you want to access them outside, you need to declare them as 'volatile'.

Posted on March 27, 2017 at 07:01

Signal triggering is a falling edge and frequency is 2MHz.

Posted on March 27, 2017 at 07:52

 ,

 ,

I am getting the following errors.. ' ♯ error clnk Debug\stm8s003.lkf:1 @svlreg missing for function f_EXTI_PORTC_IRQHandler , ,The command: 'clnk -m Debug\stm8s003.map -l'C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\Lib' , -o Debug\stm8s003.sm8 Debug\stm8s003.lkf ' has failed, the returned value is: 1 ,exit code=1.'

Posted on March 27, 2017 at 09:23

Hello,

add the @svlreg before the interrupt function name as you are asked.

More in detail, you are doing complex calculations under interrupt (using long and/or floats), so you need to add the @svlreg keyword in order to save the internal registers that are used for this calculation and thus make sure that they are not corrupted (that would cause all kind of trouble later in the execution and is difficult and time-consuming to debug).

Regards,

Luca

Posted on March 27, 2017 at 12:34

Thnak you for help..