i working with a TWR-K60F120M Evaluationboard.
I build a continuous single ended adc Measurement and all works fine. With the dma function i don't have to burden the µC with the measurement. My problem is that i can't find any components for digital filtering and i have problems to use the CMSIS Lib of ARM. I looking for a way to use a Moving average on my measured value without programm the code myself.
My ADC measurement saves 32768 values via dma in a array and all works fine and the change of my coeffs work also from float to int16_t.
Here my code for fir
#define TEST_LENGTH_SAMPLES 16384
#define BLOCK_SIZE 32
#define NUM_TAPS 29
//COEFFICIENTS fir1(28,1/5) mathlab
0.0011 , 0.0021 , 0.0032 , 0.0031 , -0.0000 , -0.0071 , -0.0165 , -0.0233 , -0.0200 , 0.0000 , 0.0386 , 0.0906 , 0.1441 ,
0.1845 , 0.1995 , 0.1845 , 0.1441 , 0.0906 , 0.0386 , 0.0000 , -0.0200 , -0.0233 , -0.0165 , -0.0071 , -0.0000 , 0.0031 ,
0.0032 , 0.0021 , 0.0011
//NUMBER OF SAMPLES
/*lint -restore Enable MISRA rule (6.3) checking. */
If i debug my system jumps in a hardfault. What am i doing wrong?
I suspect that the code is incorrect.
Pls check if the address of Messwertarray and output_fir is correct.
I suspect you should use this line.
Pls have a check.
I am glad to hear you have fixed the library issue.
Regarding the q15 FIR digital filter, I suppose you have to acquire the coefficents array with matlab or the other tools based on the application requirements, if the coefficents array is float type, and the absolute maximum element is greater than 1, you can divide each element of the coefficents with the absolute maximum element, in this way all the coeffiecnts in the array ranges from -1 to +1.
You can use the macro to transform the coeeicents to Q15.
#define FRAC16(x) 32768*x
#define TAPNUMBER 20
#define BLOCKSIZE 1
#define TOTAL_POINTS 100
#define Q15_OFFSET 0x4000
const arm_fir_instance_q15 sFirStru;
In the code, the temp is the latest sample(Note if the sample is in 16 bits, you should logic right shift one bit, because the MSB is regarded as sign. In other words, the MSB should be zero), temp1 is the filtered result. Generally, the arm_fir_fast_q15() should be put in the ADC ISR.
Hope it can help you
I suggest you can use FIR digital filter, if you want to perform Moving average, it is okay to use digital filter by setting the digital coefficents as the same value.
I think you have to do digital filtering, currently, what is your problem? You can post you code, I can help you to fix the issue.