common/pic24_adc.c File Reference

#include "pic24_all.h"
#include <stdio.h>

Go to the source code of this file.

Functions

uint16 convertADC1 (void)
void configADC1_ManualCH0 (uint16 u16_ch0PositiveMask, uint8 u8_autoSampleTime, uint8 u8_use12bit)
void configADC1_AutoScanIrqCH0 (uint16 u16_ch0ScanMask, uint8 u8_autoSampleTime, uint8 u8_use12bit)
void configADC1_AutoHalfScanIrqCH0 (uint16 u16_ch0ScanMask, uint8 u8_autoSampleTime, uint8 u8_use12bit)
void configADC1_Simul4ChanIrq (uint8 u8_ch0Select, uint16 u16_ch123SelectMask, uint16 u16_numTcyMask)


Detailed Description

Implementation of analog-to-digital converter functions prototyped in pic24_adc.h

Definition in file pic24_adc.c.


Function Documentation

void configADC1_AutoHalfScanIrqCH0 ( uint16  u16_ch0ScanMask,
uint8  u8_autoSampleTime,
uint8  u8_use12bit 
)

Configures ADC1 to perform conversions over a number of scanned channels to CH0. The sampling is done against the AVDD and AVSS references and using the internal ADC clock to conserve timer resourses. Samples are obtained continuously once sampling begins. Triggers ADC completion interrupts every N conversion cycles, where N is the number of bits set in the scan channel mask argument u16_ch0ScanMask. Results are written to the first u8_NumChannels locations in the 8 word alternating halves of the 16 word ADCxBUFn registers.

User ISR must check the AD1CON2.BUFS bit when responding to copy the 8 words from the correct half of the ADC1BUFn register array. See Chapter 11 in the book for an example. (adc7scan2 project)

Sampling+conversion will start automatically when ADC is turned on.

Parameters:
u16_ch0ScanMask A bit-mask to select the analog inputs to scan over and convert. See AD1CSSL register and associated definess in pic24_adc.h
u8_autoSampleTime Number of TAD periods for sampling the signal. This value must be 0-31. If greater than 31, then 31TAD will be used.
u8_use12bit If TRUE, set up the ADC into 12 bit mode, else use the 10 bit mode.

Configure the internal ADC

Definition at line 197 of file pic24_adc.c.

void configADC1_AutoScanIrqCH0 ( uint16  u16_ch0ScanMask,
uint8  u8_autoSampleTime,
uint8  u8_use12bit 
)

Configures ADC1 to perform conversions over a number of scanned channels to CH0. The sampling is done against the AVDD and AVSS references and using the internal ADC clock to conserve timer resourses. Samples are obtained continuously once sampling begins. Triggers ADC completion interrupts every u8_NumChannels conversion cycles. Results are written to the first u8_NumChannels locations in the 16 word ADCxBUFn registers.

Sampling+conversion will start automatically when ADC is turned on.

User must provide ISR to copy the 1-16 ADC results from ADC1BUFn before the next conversion completes. See Chapter 11 in the book for an example (adc7scan1 project).

Parameters:
u16_ch0ScanMask A bit-mask to select the analog inputs to scan over and convert. See AD1CSSL register and associated definess in pic24_adc.h
u8_autoSampleTime Number of TAD periods for sampling the signal. This value must be 0-31. If greater than 31, then 31TAD will be used.
u8_use12bit If TRUE, set up the ADC into 12 bit mode, else use the 10 bit mode.

Configure the internal ADC

Definition at line 132 of file pic24_adc.c.

void configADC1_ManualCH0 ( uint16  u16_ch0PositiveMask,
uint8  u8_autoSampleTime,
uint8  u8_use12bit 
)

Configures ADC1 to perform 10-/12-bit conversion on a single channel via CH0. The sampling is done against the AVDD and AVSS references and using the internal ADC clock to conserve timer resourses. User can initiate this manual sampling+conversion by setting the SAMP bit nin AD1CON1. When the DONE bit in AD1CON1 goes high, the conversion is done.

Parameters:
u16_ch0PositiveMask Mask to select the single analog input to convert. See AD1CHS0 register and associated definess in pic24_adc.h
u8_autoSampleTime Number of TAD periods for sampling the signal. This value must be 0-31. If greater than 31, then 31TAD will be used.
u8_use12bit If TRUE, set up the ADC into 12 bit mode, else use the 10 bit mode.

Configure the internal ADC

Definition at line 84 of file pic24_adc.c.

void configADC1_Simul4ChanIrq ( uint8  u8_ch0Select,
uint16  u16_ch123SelectMask,
uint16  u16_numTcyMask 
)

Configures ADC1 to perform simultaneous sampling and (sequential) 10bit conversion on four channels. Sampling is done against the AVDD and AVSS references. Sample duration is determined by the Timer2/3. Conversion clock is created from the internal system instruction clock. This means that this ADC configuration can NOT be used for sleeping ADC operations.

ADC completion interrupts notify user when data is ready. Our four channel conversion values are written into the alternative halves of the ADC1BUFn registers. ADC ISR must "restart" the sample (by setting AD1CON1.SAMP bit) before exit. Sampling will end and conversion will begin on the next Timer2/3 trigger. Conversion values are written into the alternative halves of the ADC1BUFn registers.

Sampling starts when AD1CON1.SAMP bit is written by main.

User must ........ See Chapter 11 in the book for an example (adc4simul project).

Parameters:
u8_ch0Select The number of the ANx channel to sample on CH0 sample-and-hold amplifier. This pin can be the same as a pin sampled on channels 1, 2, and 3. (See next argument.)
u16_ch123SelectMask A bit-mask to select the analog inputs to for channels 1,2, and 3. See AD1CHS123 register and associated definess in pic24_adc.h
u16_numTcyMask A bit-mask to select the number of TCY periods used to create one TCY period. Note that TAD > 75ns. See AD1CON3 register and associated definess in pic24_adc.h

Configure the internal ADC

Definition at line 269 of file pic24_adc.c.

uint16 convertADC1 ( void   ) 

Performs an ADC conversion (assumes ADC is initialized properly to return integer results.

Returns:
Integer value (10- or 12-bit, depending on ADC configuration) corresponding to the ADC conversion result.

Definition at line 55 of file pic24_adc.c.


Generated on Sun Mar 15 11:14:22 2009 for PIC24 Support Libraries by  doxygen 1.5.8