Hi, Anders,
Firstly, you should determine the sampling frequency, for example 1KHz,2KHz whatever which should be in the range of kl02 ADC converter, then in the normalized frequency from 0~2PI, you can design your FIR/IIR filter based on the digital filter type(IIR/FIR), pass-type(low/high/band pass) , then get the coefficients for example, I assume you design a FIR filter, you will get the coefficients h0, h1,h2,...,hn. you can save the coefficients in a static array, they are constants.
For the kl02 mcu, as you know, it has TPM, LPTMR0 timer, ADC module, and the hardware triggering circuits. If you want to implement the digital filter, the ADC conversion rate should be constant, we suggest customer use timer to trigger ADC so that the conversion rate is constant for each sample value from ADC converter.
based on the desired ADC sampling rate, you can set the TPM1 mod register,. set the TPM1 c0sc register as "output compare mode" and "Toggle output mode".
set the SIM_SOPT7 register, clear the ADC0ALTTRGEN bit, the TPM1 channel0 will trigger ADC0 converter. all the description is based on KL02P20M48SF0RM doc.
configure the ADC0 module, set the ADCO bit in ADC0_SC3, set the ADTRG bit in ADC0_SC2, then set AIEN bit and the ADCH bits based on the exact channel you are using. I suppose you know how to set an interrupt for example enabling interrupt, setting the priority of interrupt source, changing interrupt vector.
write an ISR of ADC converter, in the ISR, read the sample from the ADC0_RA register, then calling FIR api function GDFLIB_FilterFIR(), it is okay.
we have developed the digital filter library for Cortex-M0 core, you can download it from the website:
http://tinyurl.com/lvt4pxu
I attach a doc which tell you how to call digital filter api function which is from the lib.