IMPLEMENTACIÓN DEL FILTRO FIR USANDO ARM CORTEX M4
Dr. Carlos Hernandez-Gutierrez
En este ejemplo, quiero mostrar cómo implementar un filtro digital FIR en un ARM CORTEX M4.
Esto es una parte de mi curso de ARM cortex M4. Si está interesado en el código o en aprender a hacerlo, aqui comparto el link del curso:
https://www.balamsemiconductor.com/store/p1/Sistemas_embebidos_Pr%C3%A1cticos_usando_ARM_cortex_M4_%2829_de_Junio_2019%29..html#/
Tambien puede escribirnos a:
[email protected]
Usamos el ADC de la TIVA C y el DAC MCP4921 de 12 bits para la entrada analógica y la salida analógica, respectivamente, empleando las bibliotecas ADC.h y SPI_DAC.h. Donde ambas bibliotecas fueron desarrolladas por un servidor.
Para gener un muestreo periodico, implementamos una interrupción por timer e implementamos el algoritmo de convolución en cada evento de interrupción.
La fórmula de convolución se expresa en la siguiente ecuación:
Esto es una parte de mi curso de ARM cortex M4. Si está interesado en el código o en aprender a hacerlo, aqui comparto el link del curso:
https://www.balamsemiconductor.com/store/p1/Sistemas_embebidos_Pr%C3%A1cticos_usando_ARM_cortex_M4_%2829_de_Junio_2019%29..html#/
Tambien puede escribirnos a:
[email protected]
Usamos el ADC de la TIVA C y el DAC MCP4921 de 12 bits para la entrada analógica y la salida analógica, respectivamente, empleando las bibliotecas ADC.h y SPI_DAC.h. Donde ambas bibliotecas fueron desarrolladas por un servidor.
Para gener un muestreo periodico, implementamos una interrupción por timer e implementamos el algoritmo de convolución en cada evento de interrupción.
La fórmula de convolución se expresa en la siguiente ecuación:
Aquí se presenta el simple pero didactico código que implementa la convolución de la última ecuación [1]. Este filtro es un filtro promedio donde los coeficientes h[n] tienen el valor de 1/N (N=5), por lo tanto, el vector h[n] contiene el valor 0.2 para cada elemento del vector.
#include "TM4C123.h" // Device header
#include "pll.h"
#include "ADC.h"
#include "SysTick.h"
#include "SPI_DAC.h"
#define N 5
unsigned short tick = 0;
unsigned long voltage, y;
float h[N] = {
0.2,0.2,0.2,0.2,0.2};
float x[N];
void SysTick_Handler(void){
short i;
float yn = 0.0;
GPIOF->DATA ^= 0x04;
x[0]= ADC0_capture();//get new input sample form ADC
for (i=0 ; i<N ; i++) //calculate filter output
yn += h[i]*x[i];
for (i=(N-1) ; i>0 ; i--) //shift delay line contents
x[i] = x[i-1];
dac_output(yn); // output voltage form MCP4921
}
void PortF_config(void);
int main()
{
ADC_config();
PLL_Init();
SysTick_Interrupt_Init();
spi_init();
PortF_config();
while(1){
}
} // end of main
void PortF_config(){
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
}
[1] Digital Signal Processing and Applications with the TMS320C6713 and TMS320C6416 DSK, 2nd Edition, Rulph Chassaing, Donald S. Reay ISBN: 978-0-470-13866-3.
#include "TM4C123.h" // Device header
#include "pll.h"
#include "ADC.h"
#include "SysTick.h"
#include "SPI_DAC.h"
#define N 5
unsigned short tick = 0;
unsigned long voltage, y;
float h[N] = {
0.2,0.2,0.2,0.2,0.2};
float x[N];
void SysTick_Handler(void){
short i;
float yn = 0.0;
GPIOF->DATA ^= 0x04;
x[0]= ADC0_capture();//get new input sample form ADC
for (i=0 ; i<N ; i++) //calculate filter output
yn += h[i]*x[i];
for (i=(N-1) ; i>0 ; i--) //shift delay line contents
x[i] = x[i-1];
dac_output(yn); // output voltage form MCP4921
}
void PortF_config(void);
int main()
{
ADC_config();
PLL_Init();
SysTick_Interrupt_Init();
spi_init();
PortF_config();
while(1){
}
} // end of main
void PortF_config(){
SYSCTL->RCGC2|=(0x1<<5);// The clock of PORTF
GPIOF->DEN |= 0xFF; //PORTF is Digital enable now
GPIOF->DIR|=(0x1<<2)|(0x1<<3)|(0x1<<1);//LEDs are outputs
}
[1] Digital Signal Processing and Applications with the TMS320C6713 and TMS320C6416 DSK, 2nd Edition, Rulph Chassaing, Donald S. Reay ISBN: 978-0-470-13866-3.