Specifications
dsPIC33F Family Reference Manual
DS70183A-page 16-58 © 2006 Microchip Technology Inc.
Example 16-5: Code for Alternate Sampling Using DMA
/********************************************************************************************
* © 2005 Microchip Technology Inc.
*
* FileName: adcDrv1.c
* Dependencies: Header (.h) files if applicable, see below
* Processor: dsPIC33Fxxxx
* Compiler: MPLAB® C30 v2.01.00 or higher
*
* SOFTWARE LICENSE AGREEMENT:
* Microchip Technology Inc. (“Microchip”) licenses this software to you solely for use with
* Microchip dsPIC® digital signal controller products. The software is owned by Microchip
* and is protected under applicable copyright laws. All rights reserved.
* *
* SOFTWARE IS PROVIDED “AS IS.” MICROCHIP EXPRESSLY DISCLAIMS ANY WARRANTY OF ANY KIND,
* WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT
* SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES,
* LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS,
* TECHNOLOGY OR SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO
* ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
*
*********************************************************************************************/
#if defined(__dsPIC33F__)
#include "p33fxxxx.h"
#elif defined(__PIC24H__)
#include "p24hxxxx.h"
#endif
#include "adcDrv1.h"
#include "tglPin.h"
// Define Message Buffer Length for ECAN1/ECAN2
#define MAX_CHNUM 5
// Highest Analog input number enabled for alternate sampling
#define SAMP_BUFF_SIZE 16 // Size of the input buffer per analog input
// Number of locations for ADC buffer = 2 (AN4 and AN5) x 16 = 32 words
// Align the buffer to 32words or 64 bytes. This is needed for peripheral indirect mode
int BufferA[MAX_CHNUM+1][SAMP_BUFF_SIZE] __attribute__((space(dma),aligned(64)));
int BufferB[MAX_CHNUM+1][SAMP_BUFF_SIZE] __attribute__((space(dma),aligned(64)));
void ProcessADCSamples(int * AdcBuffer);
/*=============================================================================
ADC Initialisation for Channel Scan
=============================================================================*/
void initAdc1(void)
{
AD1CON1bits.FORM = 3; // Data Output Format: Signed Fraction (Q15 format)
AD1CON1bits.SSRC = 2; // Sample Clock Source: GP Timer starts conversion
AD1CON1bits.ASAM = 1; //
ADC Sample Control: Sampling begins immediately after conversion
AD1CON1bits.AD12B = 0; // 10-bit ADC operation
AD1CON2bits.ALTS=1; // Alternate Input Sample Mode Select Bit
AD1CON2bits.CHPS = 0; // Converts CH0