Hi all,
I am trying to apply a FIR filter on an ADC buffer and then turn around and loop it back out to DAC. Simple stuff.
But, for some reason, when I uncomment the FIR function itself, I then start to get a high pitched beeping sound coming out.
It isn't even touching the data going to the DAC. It simply is applying the FIR filter and storing it elsewhere.
I have the ADC->DAC loopback set up in ping-pong mode with two buffers so, by my implementation, I have two FIR function calls (one when BufferA is DAC converted and same for BufferB). If I comment out one of the two FIR function calls, the frequency of this undesired waveform lowers.
Any ideas here?
The full project is attached.
Here is my main (sorry about the goofy comments... I like to have fun when I code ):
I am trying to apply a FIR filter on an ADC buffer and then turn around and loop it back out to DAC. Simple stuff.
But, for some reason, when I uncomment the FIR function itself, I then start to get a high pitched beeping sound coming out.
It isn't even touching the data going to the DAC. It simply is applying the FIR filter and storing it elsewhere.
I have the ADC->DAC loopback set up in ping-pong mode with two buffers so, by my implementation, I have two FIR function calls (one when BufferA is DAC converted and same for BufferB). If I comment out one of the two FIR function calls, the frequency of this undesired waveform lowers.
Any ideas here?
The full project is attached.
Here is my main (sorry about the goofy comments... I like to have fun when I code ):
Code:
#include "p33fxxxx.h"
#include "dsp.h"
#include "..\h\adcdacDrv.h"
#include "..\h\table.h"
#include <delay.h>
//Macros for Configuration Fuse Registers:
//Invoke macros to set up device configuration fuse registers.
//The fuses will select the oscillator source, power-up timers, watch-dog
//timers etc. The macros are defined within the device
//header files. The configuration fuse registers reside in Flash memory.
// Internal FRC Oscillator
_FOSCSEL(FNOSC_FRC); // FRC Oscillator
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON & POSCMD_NONE);
// Clock Switching is enabled and Fail Safe Clock Monitor is disabled
// OSC2 Pin Function: OSC2 is Clock Output
// Primary Oscillator Mode: Disabled
_FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
// (LPRC can be disabled by clearing SWDTEN bit in RCON register
/* Constant Definitions */
#define BLOCK_LENGTH 256 /*We will filter a block of 256 samples in this example*/
/* extern definitions for the imported *.s files from dsPIC Filter Design */
extern FIRStruct filterFilter; /*Contains filter structures for FIR-BPF*/
/* Filter Operation Vectors */
fractional FilterOut[BLOCK_LENGTH] ; /*Output array where filtered output will*/
/*be stored */
int main (void)
{
// Configure Oscillator to operate the device at 40MIPS
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 7.37M*43/(2*2)=79.22Mhz for ~40MIPS input clock
PLLFBD=41; // M=43
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
OSCTUN=0; // Tune FRC oscillator, if FRC is used
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x01); // Initiate Clock Switch to
// FRC with PLL (NOSC=0b001)
__builtin_write_OSCCONL(0x01); // Start clock switching
while (OSCCONbits.COSC != 0b001); // Wait for Clock switch to occur
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};
initAdc(); // Initialize the A/D converter to convert Channel 4
initDac(); // Initialize the D/A converter
initDma0(); // Initialize the DMA controller to buffer ADC data in conversion order
initTmr3(); // Initialize the Timer to generate sampling event for ADC
extern fractional BufferA[NUMSAMP]; // Ping pong buffer A
extern fractional BufferB[NUMSAMP]; // Ping pong buffer B
extern unsigned int DmaBuffer; // DMA flag
extern int flag; // Flag
int i;
// Let's get this party started...
int bitArray[25];
initS2P();
clearDisplay();
testAllLights();
// fullDisplayFlash();
/*Initialize the filter state variables (delay line) prior to calling */
/*the FIR() routine the very first time */
FIRDelayInit(&filterFilter);
while (1) // Loop Endlessly - Execution is interrupt driven
{
if(flag)
{
for(i = 0; i < NUMSAMP; i++)
{
while(DAC1STATbits.REMPTY != 1);// Wait for D/A conversion
if(DmaBuffer == 0){
/* Perform FIR Band Pass filtering on ADC buffah */
FIR(BLOCK_LENGTH,&FilterOut[0],&BufferA[0],&filterFilter);
DAC1RDAT = BufferA[i]; // Load the DAC buffer with data
}else{
/* Perform FIR Band Pass filtering on ADC buffah */
FIR(BLOCK_LENGTH,&FilterOut[0],&BufferB[0],&filterFilter);
DAC1RDAT = BufferB[i]; // Load the DAC buffer with data
}
}
flag = 0;
}
}
return 0;
}
Attachments
Last edited: