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

CE154 - ADC to DAC Loopback

Microchip Technology

In this example, ADC is configured to sample (AN4) at 103.16 KHz rate and the converted data is assembled in a 256-sample buffer. The captured 256 samples are output using the on-chip DAC.

About this Code Example

In this example, ADC is configured to sample (AN4) at 103.16 KHz rate and the converted data is assembled
in a 256-sample buffer. Timer 3 is setup to time-out every 9.69 microseconds (103.16 KHz rate). On every
Timer3 time-out (every Ts = 9.69 microsecs), the ADC module will stop sampling and trigger a 12-bit A/D conversion.
At that time, the conversion process starts and completes Tc = 14*Tad = 1.4 microsecs later.
When the conversion is complete, the module starts sampling again. However, since Timer3 is already on and counting,
about (Ts-Tc) = 8.29 microsecs later, Timer3 will expire again and trigger the next conversion.
The DMA is configured in continuous, ping pong mode, such that after the DMA channel has read 256 samples
into a buffer (BufferA/BufferB) a DMA interrupt is generated. The captured 256 samples are output using the on-chip DAC.
Mean while the DMA controller starts filling new ADC samples into buffer (BufferB/BufferA). Thus the two buffers are
alternately filled and released in an infinite loop.
The ADC module clock time period is configured as Tad = Tcy*(ADCS+1) = (1/40M)*(3+1) = 100 nanosecs with ADCS = 3.
Hence the conversion time for 12-bit A/D is 14*Tad = 1.4 microsecs.

Categories

Release History

  • Jul 22, 2011

    Version: 1.0.0

    First upload to ECS

Download Contact the Developer

*Required Fields

  • Current Version:1.0.0
  • Created:Jul 22, 2011
  • Updated:Feb 26, 2015
  • Downloads:5425
  • MPLAB Version:latest
  • C Compiler:MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs
  • Development Tools:16-Bit 28-Pin Starter board with dsPIC33FJ128GP802 device
  • Supported Devices:dsPIC33

Corporate News

Resources

Stay Connected

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