DSPRelated.com
Forums

question about FIR filters

Started by Unknown October 25, 2006


Hi, Im writing because Im trying to work with a MC56f8323. Im trying to
make a fir filter and I cant understand an example code that I have. My
idea Is to acquire continuously, pass signal trough a filter and then
transmit it via RS232. Im going to copy code that I have. Please, need
comments. Thanks.



Rodolfo



PD: I dont understand why increment pfirRead in 4







while (adquiere)

{

pTempWrtPtr = pAdcRxBuffWrt; // voy almacenando los datos adq.



/****** HERE IS THE FIR CODE *******************/



#ifdef FIR_ENABLED

#if (SAMPLE_RATE != 1000)

#error (SAMPLE RATE INCORRECT)

#endif



if(pTempWrtPtr >= pFirRead)

{

Size = pTempWrtPtr - pFirRead;

}

else

{

Size = ADC_RX_BUFF_SIZE - (pFirRead - pTempWrtPtr);

}



if (Size >= 4)

{

dfr16FIR (pFir, (Frac16 *) pFirRead, (Frac16 *)
pFirRead, NUM_SAMPLES);



// increment pointer

pFirRead += 4;



// check to see if at end of fifo

if(pFirRead > &AdcRxBuff[ADC_RX_BUFF_SIZE-1])

{

pFirRead = &AdcRxBuff[0];

}

}

#endif







2006/10/25, C. Rodolfo Ramez :
>
> Hi, I'm writing because I'm trying to work with a MC56f8323.
I'm trying to do a FIR filter with a MC56F8323 too.

I'm trying to
> make a fir filter and I can't understand an example code that I have.
You shouldn't look this example anymore (it drove me crazy).

My
> idea Is to acquire continuously, pass signal trough a filter and then
> transmit it via RS232. I'm going to copy code that I have. Please, need
> comments. Thanks.
>
> Rodolfo
>
> PD: I don't understand why increment pfirRead in 4
>
> while (adquiere)
>
> {
>
> pTempWrtPtr = pAdcRxBuffWrt; // voy almacenando los datos adq.
>
> /****** HERE IS THE FIR CODE *******************/
>
> #ifdef FIR_ENABLED
>
> #if (SAMPLE_RATE != 1000)
>
> #error (SAMPLE RATE INCORRECT)
>
> #endif
>
> if(pTempWrtPtr >= pFirRead)
>
> {
>
> Size = pTempWrtPtr - pFirRead;
>
> }
>
> else
>
> {
>
> Size = ADC_RX_BUFF_SIZE - (pFirRead - pTempWrtPtr);
>
> }
>
> if (Size >= 4)
>
> {
>
> dfr16FIR (pFir, (Frac16 *) pFirRead, (Frac16
> *)
> pFirRead, NUM_SAMPLES);
>
> // increment pointer
>
> pFirRead += 4;
>
> // check to see if at end of fifo
>
> if(pFirRead > &AdcRxBuff[ADC_RX_BUFF_SIZE-1])
>
> {
>
> pFirRead = &AdcRxBuff[0];
>
> }
>
> }
>
> #endif
what I'm doing is to use the DSP_Func_DFR bean library. But I can't
initialize the FIR filter with a DFR1_dfr16FIRIntCreate() because it uses
malloc which always returns NULL. In order to work-around this I create the
fir structure as static memory
This is my main code:

#include "Coef_prueba1.h" /* Including QEDesign Coef*/

/* VAR */ //This are global vars
word primer_tros,segon_tros,la_dada;
Frac16 resultat;

dfr16_tFirStruct Fir;
//Frac16 HistoryBuffer[sizeof(Coef_prueba1)];
Frac16 Buff[sizeof(Coef_prueba1)];
dfr16_tFirStruct *pFir= &Fir;

/*fVAR */
void main(void)
{
/* VAR */
Frac16 HistoryBuffer[sizeof(Coef_prueba1)*2],*pHistory;
/*fVAR */

.........MY INIT CODE HERE........

pHistory=&HistoryBuffer[0];

while (!memIsAligned(pHistory,sizeof(Coef_prueba1)))
{
pHistory++;
}

pFir->pC = (Frac16 *) &Buff[0];
pFir->pHistory = pHistory;

dfr16FIRInit (pFir, (Frac16 *)(&Coef_prueba1[0]),
sizeof(Coef_prueba1)/sizeof(Frac16));
T_mostreig_EnableEvent(); //Init interrupts

for(;;)
{

}

}
As you can see I create a HistoryBuffer two times longer than its own size.
Also I create a pointer which at end will point to the first memory position
aligned. After that I fill pFir and call dfr16FIRInit.

Then you can call dfr16FIRs with no problem as I do in my ADC_RSI:

void ADC1_OnEnd(void)
{

/* VAR */

/*fVAR */
la_dada = getReg(ADCA_ADRSLT0);

resultat = DFR1_dfr16FIRs (pFir,(Frac16) la_dada); /* colocamos la
dada filtrada en una variable global */
}

At the moment I'm looking to align the memory with .cmd linker file (Anyone
know how it works??).
On the other hand, I'm trying to make this code work :

#define SIK_SIZE 4

void main(void)
{
/* VAR */
word *p;
/*fVAR */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!!
***/
PE_low_level_init();

/*** End of Processor Expert internal initialization.
***/

/* Write your code here */
p = MEM1_memMallocAlignedIM(SIK_SIZE);

if( p == NULL)
printf_console("Can't create the buffer\n");
else
{
printf_console("Buffer crated\n");
if(MEM1_memIsAligned(p,SIK_SIZE))
printf_console("Memory is aligned\n");
else
printf_console("Memory is NOT aligned\n");

}

// for(;;) {}
}
Any help would be appreciated.
Thx (and sorry for my english).