|
4 | 4 |
|
5 | 5 | ## Description: |
6 | 6 |
|
7 | | -In this example, ADC is configured to sample (AN5) at 250 KHz rate and the converted 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 used.<br /> |
8 | | -Timer 3 is setup to time-out every 4 microseconds (250 KHz rate). On every Timer3 time-out (every Ts = 4 microsecs), the ADC module will stop sampling and trigger a 10-bit A/D conversion. At that time, the conversion process starts and completes Tc = 12 * Tad = 1.2 microsecs later. <br /> |
9 | | -When the conversion is complete, the module starts sampling again. <br /> |
10 | | -However, since Timer3 is already on and counting, about (Ts-Tc) secs later Timer3 will expire again and trigger the next conversion. <br /> |
11 | | -The DMA is configured in continuous, ping pong mode, such that after the DMA channel has read 480 samples into a buffer (BufferA/BufferB) a DMA interrupt is generated.<br /> |
12 | | -These samples are filtered by a function call in the main function while 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.<br /> |
13 | | -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.<br /> |
14 | | -FIRStruct describes the data structure for FIR filter with the filter specifications given below. FIRStructInit() initializes the FIR filter structure parameters. <br /> |
15 | | -FIRDelayInit() initializes the delay values in the FIR filter structure to zeros. The FIR() function applies an FIR filter to a sequence of source samples and places the result in a sequence of destination samples.<br /> |
16 | | - |
17 | | -FIR filter specifications used:<br /> |
18 | | -Sampling freq = 250 KHz<br /> |
19 | | -FIR block size, N = 480<br /> |
20 | | -Number of FIR coefficients, M = 20<br /> |
21 | | -FCY = 40 MIPS<br /> |
22 | | -Passband Frequency = 1300 Hz<br /> |
23 | | -Stopband Frequency = 1350 Hz<br /> |
24 | | -Passband Ripple = 1 dB<br /> |
25 | | -Stopband Ripple = 3 dB<br /> |
| 7 | +In this example, ADC is configured to sample (AN5) at 250 KHz rate and the converted 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 used. |
| 8 | +Timer 3 is setup to time-out every 4 microseconds (250 KHz rate). On every Timer3 time-out (every Ts = 4 microsecs), the ADC module will stop sampling and trigger a 10-bit A/D conversion. At that time, the conversion process starts and completes Tc = 12 * Tad = 1.2 microsecs later. |
| 9 | +When the conversion is complete, the module starts sampling again. |
| 10 | +However, since Timer3 is already on and counting, about (Ts-Tc) secs later Timer3 will expire again and trigger the next conversion. |
| 11 | +The DMA is configured in continuous, ping pong mode, such that after the DMA channel has read 480 samples into a buffer (BufferA/BufferB) a DMA interrupt is generated. |
| 12 | +These samples are filtered by a function call in the main function while 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. |
| 13 | +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. |
| 14 | +FIRStruct describes the data structure for FIR filter with the filter specifications given below. FIRStructInit() initializes the FIR filter structure parameters. |
| 15 | +FIRDelayInit() initializes the delay values in the FIR filter structure to zeros. The FIR() function applies an FIR filter to a sequence of source samples and places the result in a sequence of destination samples. |
| 16 | + |
| 17 | +FIR filter specifications used: |
| 18 | +Sampling freq = 250 KHz |
| 19 | +FIR block size, N = 480 |
| 20 | +Number of FIR coefficients, M = 20 |
| 21 | +FCY = 40 MIPS |
| 22 | +Passband Frequency = 1300 Hz |
| 23 | +Stopband Frequency = 1350 Hz |
| 24 | +Passband Ripple = 1 dB |
| 25 | +Stopband Ripple = 3 dB |
26 | 26 | Kaiser Windowing |
27 | 27 |
|
28 | 28 | The FIR() function takes [53+N(4+M)] instruction cycles. In this example, since N = 480 and M = 20, the total number of instruction cycles taken by FIR() is C = 11,573. Since the instruction cycle frequency is FCY = 40 MIPS the total time taken by the FIR filter to filter 480 samples is TFIR = C/FCY = 0.3 millisecs. |
29 | 29 |
|
30 | 30 | 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 dsPIC33E device family. |
31 | 31 |
|
32 | 32 |
|
33 | | -void initTmr3();<br /> |
| 33 | +void initTmr3(); |
34 | 34 | Timer 3 is configured to time-out at 250 KHz rate. |
35 | 35 |
|
36 | | -void initAdc1(void);<br /> |
| 36 | +void initAdc1(void); |
37 | 37 | ADC module is set-up to convert AIN5 input using CH0 S/H on Timer 3 event in 10-bit mode. |
38 | 38 |
|
39 | | -void initDma0(void);<br /> |
| 39 | +void initDma0(void); |
40 | 40 | DMA channel 0 is confiured in ping-pong mode to move the converted data from ADC to DMA RAM on every sample/convert sequence. |
41 | 41 | It generates interrupt after every 480 sample transfer. |
42 | 42 |
|
43 | | -void \_\_attribute\_\_((\_\_interrupt\_\_)) _DMA0Interrupt(void);<br /> |
| 43 | +void \_\_attribute\_\_((\_\_interrupt\_\_)) _DMA0Interrupt(void); |
44 | 44 | DMA interrupt service routine sets flag for FIR filtering on the data buffer. |
45 | 45 |
|
46 | 46 |
|
|
0 commit comments