2017-03-25 02:03 AM
#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..
2017-03-25 07:07 AM
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.
2017-03-25 07:25 AM
If you're modifying global variables inside an interrupt handler, and you want to access them outside, you need to declare them as 'volatile'.
2017-03-27 12:01 AM
Signal triggering is a falling edge and frequency is 2MHz.
2017-03-27 12:52 AM
,
,
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.'
2017-03-27 02:23 AM
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
2017-03-27 05:34 AM
Thnak you for help..