Hi, Roman,
As you know the SDK provide CMSIS library, before you develop the FIR code based on K22, I suggest you install the Kinetis tools for example KDS tools and KSDK tools from the wbsite:
K40_100 |Kinetis K40 100 MHz MCUs|Freescale
after you install the the KDS and KSDK tools, you can find out the directory:
D:\Freescale\KSDK_1.2.0\platform\CMSIS\DSP_Lib\Source\FilteringFunctions
we provide the FIR source code.
This is the architacture of FIR filtering in real world, the Kinetis has on-chip SAR ADC, you can use PDB to trigger ADC so that you can sample an analog signal with a fixed cycle time, I suggest you use interrupt mode for the ADC conversion, after the ADC conversion is over, an ADC interrupt is triggered by ADC, in the ISR of ADC conversion, you can read the ADC sample and filter it.
You have to use the other tools to design a digital filter so that you can get the FIR coefficients based on filter type and pass-band.
Before you use the CMSIS library, you have to compile the platform library. we provide Q16/Q32/float data type digital filtering the CMSIS lib.
This is the snippet of FIR code:
#define FRAC16(x) 32768*x
#define TAPNUMBER 20
#define BLOCKSIZE 1
int16_t lpFilterCoefficent[TAPNUMBER]=
{
FRAC16(4.45556640625000e-003),
FRAC16(1.44042968750000e-002),
FRAC16(2.54516601562500e-002),
FRAC16(3.69873046875000e-002),
FRAC16(4.84619140625000e-002),
FRAC16(5.92041015625000e-002),
FRAC16(6.86950683593750e-002),
FRAC16(7.63244628906250e-002),
FRAC16(8.16650390625000e-002),
FRAC16(8.44116210937500e-002),
FRAC16(8.44116210937500e-002),
FRAC16(8.16650390625000e-002),
FRAC16(7.63244628906250e-002),
FRAC16(6.86950683593750e-002),
FRAC16(5.92041015625000e-002),
FRAC16(4.84619140625000e-002),
FRAC16(3.69873046875000e-002),
FRAC16(2.54516601562500e-002),
FRAC16(1.44042968750000e-002),
FRAC16(4.45556640625000e-003)
};
const arm_fir_instance_q15 sFirStru;
int16_t FirState[TAPNUMBER+BLOCKSIZE];
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
int16_t temp0,offset,scale;
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
//OSA_Init();
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
__asm("nop");
arm_fir_init_q15(&sFirStru,TAPNUMBER,&lpFilterCoefficent[0],&FirState[0],BLOCKSIZE);
...........................
}
void ADC_ISR(void)
{
__asm("nop");
| /* Write your code here ... */ |
temp=(int16_t)var0[index]; //ADC sample here
#ifdef DIGITALFILTER
arm_fir_fast_q15(&sFirStru,&temp,&temp1,1);
#endif
}
Hope it acn help you.
BR
XiangJun Rong