Sie sind auf Seite 1von 3

Readme File for Code Example: CE148 - ADC Sampling and FIR Filtering ---------------------------------------This file contains the

following sections: 1. Code Example Description 2. Folder Contents 3. Suggested Development Resources 4. Reconfiguring the project for a different dsPIC33F device 5. Revision History 1. Code Example Description: ---------------------------In this example, ADC is configured to sample (AN5) at 250 KHz rate and the conve rted data is assembled in a 480-sample buffer. This input data is then filtered using the block FIR filter function from the DSP library. A 20-tap filter is use d. Timer 3 is setup to time-out every 4 microseconds (250 KHz rate). On every Timer 3 time-out (every Ts = 4 microsecs), the ADC module will stop sampling and trigg er a 10-bit A/D conversion. At that time, the conversion process starts and comp letes Tc = 12*Tad = 1.2 microsecs later. When the conversion is complete, the mo dule starts sampling again. However, since Timer3 is already on and counting, ab out (Ts-Tc) secs later Timer3 will expire again and trigger the next conversion. The DMA is configured in continuous, ping pong mode, such that after the DMA ch annel has read 480 samples into a buffer (BufferA/BufferB) a DMA interrupt is ge nerated. These samples are filtered by a function call in the main function whil e the DMA controller starts filling new ADC samples into buffer (BufferB/BufferA ). Thus the two buffers are alternately filled and processed in an infinite loop . The ADC module clock time period is configured as Tad = Tcy*(ADCS+1) = (1/40M)*1 = 100ns nanosecs with ADCS = 3. Hence the conversion time for 10-bit A/D is 12* Tad = 1.2 microsecs. FIRStruct describes the data structure for FIR filter with the filter specificat ions given below. FIRStructInit() initializes the FIR filter structure parameter s. FIRDelayInit() initializes the delay values in the FIR filter structure to ze ros. The FIR() function applies an FIR filter to a sequence of source samples an d places the result in a sequence of destination samples. FIR filter specifications used: Sampling freq = 250 KHz FIR block size, N = 480 Number of FIR coefficients, M = 20 FCY = 40 MIPS Passband Frequency = 1300 Hz Stopband Frequency = 1350 Hz Passband Ripple = 1 dB Stopband Ripple = 3 dB Kaiser Windowing The FIR() function takes [53+N(4+M)] N = 480 and M = 20, the total number 11,573. Since the instruction cycle aken by the FIR filter to filter 480 instruction cycles. In this example, since of instruction cycles taken by FIR() is C = frequency is FCY = 40 MIPS the total time t samples is TFIR = C/FCY = 0.3 millisecs.

NOTE: A NOP associated with Y memory errata was removed from the fir.s source in the DSP library before using it in this code example, as this errata item only applies to certain dsPIC30F devices and does not affect the dsPIC33F device fami

ly. void initTmr3(); Timer 3 is configured to time-out at 250 KHz rate. void initAdc1(void); ADC module is set-up to convert AIN5 input using CH0 S/H on Timer 3 event in 10bit mode. void initDma0(void); DMA channel 0 is confiured in ping-pong mode to move the converted data from ADC to DMA RAM on every sample/convert sequence. It generates interrupt after every 480 sample transfer. void __attribute__((__interrupt__)) _DMA0Interrupt(void); DMA interrupt service routine sets flag for FIR filtering on the data buffer. 2. Folder Contents: ------------------This folder contains the following sub-folders: a. C:\Program Files\Microchip\MPLAB C30\support\gld This folder will have the device GLD file, it is used for building the p roject. This file was provided with the MPLAB C30 toolsuite. b. C:\Program Files\Microchip\MPLAB C30\support\h This folder contains C header files useful in building this project. Device register and bit definitions are provided in the *.h file that follows the device name. These files were provided with the MPLAB C30 toolsuite. c. C:\Program Files\Microchip\MPLAB C30\lib This folder contains library archive files, which are a collection of precompiled object files. The file named "libpic30-coff.a" contains the C run-time start-up library. These file were provided with the MPLAB C30 toolsuite. d. hex This folder contains three file types - coff, hex and map. These are files generated by the MPLAB C30 toolsuite on build operation performed within MPLAB IDE. The *.map file contains details on memory allocation for various variables, constants and dsPIC instructions specified in the source and library code. The *.hex file contains a binary file that may be programmed into the dsPIC device. The *.coff file contains a binary file that is used by MPLAB IDE for simulation. e. h This folder contains include files for the code example. f. src This folder contains all the C and Assembler source files (*.c, *.s) used in demonstrating the described example. This folder also contains a sub-folder named "obj" that stores compiled object files generated when the project is built.

3. Suggested Development Resources: ----------------------------------a. Explorer16 board with dsPIC33FJ256GP710 controller 4. Reconfiguring the project for a different dsPIC33F device: ------------------------------------------------------------The Project/Workspace can be easily reconfigured for any dsPIC33F device. Please use the following general guidelines: a. Change device selection within MPLAB IDE to a dsPIC33F device of your choice by using the following menu option: MPLAB IDE>>Configure>>Select Device b. Provide the correct device linker script and header file for your device. Device linker scripts and header files are available in your MPLAB C30 installation folder under: Device Linker ScriptYourDrive:>Program Files\Microchip\MPLAB C30\support\gld Device C Header fileYourDrive:>Program Files\Microchip\MPLAB C30\support\h Device ASM Include fileYourDrive:>Program Files\Microchip\MPLAB C30\support\inc c. Provide the appropriate path to your MPLAB C30 support file locations using the menu option: MPLAB IDE>>Project>>Build Options>>Project d. Chose the development board applicable to your device. Some options are provided below: e. Re-build the MPLAB project using the menu option: MPLAB IDE>>Project>>Build All f. Download the hex file into the device and run. 5. Revision History : --------------------12/05/2007 - Initial Release of the Code Example

Das könnte Ihnen auch gefallen