0
我正在对32位浮点MCU的嵌入式微控制器(TMS320F28069)进行编程。我正在回顾一些示例项目,其中一个实现了ADC采样数据上的简单FIR滤波器。针对FIR滤波器的循环缓冲区实现C
假设ADC缓冲区有10个元素。假设过滤器的长度为3(FILTER_LEN=3
)。过滤器的实现非常简单,它从延迟链的末尾开始并移动到开头。
float32 ssfir(float32 *x, float32 *a, Uint16 n)
{
Uint16 i; // general purpose
float32 y; // result
float32 *xold; // delay line pointer
/*** Setup the pointers ***/
a = a + (n-1); // a points to last coefficient
x = x + (n-1); // x points to last buffer element
xold = x; // xold points to last buffer element
/*** Last tap has no delay line update ***/
y = (*a--)*(*x--);
/*** Do the other taps from end to beginning ***/
for(i=0; i<n-1; i++)
{
y = y + (*a--)*(*x); // filter tap
*xold-- = *x--; // delay line update
}
/*** Finish up ***/
return(y);
}
现在,这里是如何实现ADC循环缓冲区。
//---------------------------------------------------------------------
interrupt void ADCINT1_ISR(void) // PIE1.1 @ 0x000D40 ADCINT1
{
static float32 *AdcBufPtr = AdcBuf; // Pointer to ADC data buffer
static float32 *AdcBufFilteredPtr = AdcBufFiltered; // Pointer to ADC filtered data buffer
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Must acknowledge the PIE group
//--- Manage the ADC registers
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADCINT1 flag
//--- Read the ADC result:
*AdcBufPtr = ADC_FS_VOLTAGE*(float32)AdcResult.ADCRESULT0;
//--- Call the filter function
xDelay[0] = *AdcBufPtr++; // Add the new entry to the delay chain
*AdcBufFilteredPtr++ = ssfir(xDelay, coeffs, FILTER_LEN);
//--- Brute-force the circular buffer
if(AdcBufPtr == (AdcBuf + ADC_BUF_LEN))
{
AdcBufPtr = AdcBuf; // Rewind the pointer to the beginning
AdcBufFilteredPtr = AdcBufFiltered; // Rewind the pointer to the beginning
}
}
xDelay
是长度FILTER_LEN
的FLOAT32阵列以0初始化,并且coeffs
是长度FILTER_LEN
的FLOAT32阵列与所述滤波器系数初始化。
我的问题是,这到底是怎么回事:
//--- Call the filter function
xDelay[0] = *AdcBufPtr++; // Add the new entry to the delay chain
*AdcBufFilteredPtr++ = ssfir(xDelay, coeffs, FILTER_LEN);
如何有史以来值获取存储在xDelay[1]
或xDelay[2]
? 他们的实现似乎工作正常,但我没有按照旧的数据被推回到xDelay数组。
很难说明没有看到代码的其余部分,比如xDelay初始化和所有被引用的地方。它只是在ISR中设置一次,它应该如何运作。 – cwhelms
xDelay全局声明为'float32 xDelay [FILTER_LEN] = {0.0,0.0,0.0};' – SPieiga