Microchip | The Embedded Control Solutions Company Register Login
Browse All
Microchip Technology
 369 Code Snippets

CE100 - ADC Sampling and IIR Filtering

Microchip Technology

In this example, ADC is configured to sample (AIN5) at 8Khz rate and coverted data is assembled as 256 sample buffer before triggering filtering operation.

About this Code Example

In this example, ADC is configured to sample (AIN5) at 8Khz rate and coverted data is assembled as 256 sample buffer before triggering filtering operation.

Timer 3 is setup to time-out every 125 microseconds (8Khz Rate).
As a result, the module will stop sampling and trigger a 12-bit A/D conversion on every Timer3 time-out, i.e., Ts=125us.
At that time, the conversion process starts and completes Tc=14*Tad periods later.
When the conversion completes, the module starts sampling again. However, since Timer3
is already on and counting, about (Ts-Tc)us later, Timer3 will expire again and trigger
next conversion.

ADC module clock time period is configured as Tad=Tcy*(ADCS+1)= (1/40M)*64 = 1.6us (625Khz).
Hence the conversion time for 12-bit A/D Conversion Time Tc=14*Tad = 22.4us

void initTmr3();
Timer 3 is configured to time-out at 8Khz rate.

void initAdc1(void);
ADC module is set-up to convert AIN5 input using CH0 S/H on Timer 3 event in 12-bit 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 256 sample transfer.

void __attribute__((__interrupt__)) _DMA0Interrupt(void);
DMA interrupt service routine performs IIR filtering on the data buffer.

Categories

Release History

  • Jun 15, 2012

    Version: 1.0.0

    First Release to ECS

Download Contact the Developer

*Required Fields


  • Current Version:1.0.0
  • Created:Jun 16, 2012
  • Updated:Feb 26, 2015
  • Downloads:3745
  • MPLAB Version:V8.xx or above
  • C Compiler:MCC18 v3.30 or above
  • Development Tools:Explorer16 board
  • Supported Devices:dsPIC33FJ256GP710

Corporate News

Resources

Stay Connected

Stay up to date with the latest news from Microchip Technology.