• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C30 Madness Again...

Not open for further replies.


New Member
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 :D):
#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
												// 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

	// 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];
//	fullDisplayFlash();

	/*Initialize the filter state variables (delay line) prior to calling */
    /*the FIR() routine the very first time */

    while (1)               					// Loop Endlessly - Execution is interrupt driven

			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   */

					DAC1RDAT = BufferA[i];		// Load the DAC buffer with data

					/* Perform FIR Band Pass filtering on ADC buffah   */

					DAC1RDAT = BufferB[i];		// Load the DAC buffer with data
			flag = 0;
	return 0;



Last edited:
Not open for further replies.

Latest threads

EE World Online Articles