Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

A/D Converter Function Library (a2d.c)
[Drivers (for AVR peripherals)]


Detailed Description

 #include "a2d.h" 
Overview
This library provides an easy interface to the analog-to-digital converter available on many AVR processors. Updated to support the ATmega128.


Defines

#define ADC_PRESCALE_DIV2   0x00
 0x01,0x00 -> CPU clk/2
#define ADC_PRESCALE_DIV4   0x02
 0x02 -> CPU clk/4
#define ADC_PRESCALE_DIV8   0x03
 0x03 -> CPU clk/8
#define ADC_PRESCALE_DIV16   0x04
 0x04 -> CPU clk/16
#define ADC_PRESCALE_DIV32   0x05
 0x05 -> CPU clk/32
#define ADC_PRESCALE_DIV64   0x06
 0x06 -> CPU clk/64
#define ADC_PRESCALE_DIV128   0x07
 0x07 -> CPU clk/128
#define ADC_PRESCALE   ADC_PRESCALE_DIV64
#define ADC_PRESCALE_MASK   0x07
#define ADC_REFERENCE_AREF   0x00
 0x00 -> AREF pin, internal VREF turned off
#define ADC_REFERENCE_AVCC   0x01
 0x01 -> AVCC pin, internal VREF turned off
#define ADC_REFERENCE_RSVD   0x02
 0x02 -> Reserved
#define ADC_REFERENCE_256V   0x03
 0x03 -> Internal 2.56V VREF
#define ADC_REFERENCE   ADC_REFERENCE_AVCC
#define ADC_REFERENCE_MASK   0xC0
#define ADC_MUX_MASK   0x1F
#define ADC_CH_ADC0   0x00
#define ADC_CH_ADC1   0x01
#define ADC_CH_ADC2   0x02
#define ADC_CH_ADC3   0x03
#define ADC_CH_ADC4   0x04
#define ADC_CH_ADC5   0x05
#define ADC_CH_ADC6   0x06
#define ADC_CH_ADC7   0x07
#define ADC_CH_122V   0x1E
 1.22V voltage reference
#define ADC_CH_AGND   0x1F
 AGND.
#define ADC_CH_0_0_DIFF10X   0x08
#define ADC_CH_1_0_DIFF10X   0x09
#define ADC_CH_0_0_DIFF200X   0x0A
#define ADC_CH_1_0_DIFF200X   0x0B
#define ADC_CH_2_2_DIFF10X   0x0C
#define ADC_CH_3_2_DIFF10X   0x0D
#define ADC_CH_2_2_DIFF200X   0x0E
#define ADC_CH_3_2_DIFF200X   0x0F
#define ADC_CH_0_1_DIFF1X   0x10
#define ADC_CH_1_1_DIFF1X   0x11
#define ADC_CH_2_1_DIFF1X   0x12
#define ADC_CH_3_1_DIFF1X   0x13
#define ADC_CH_4_1_DIFF1X   0x14
#define ADC_CH_5_1_DIFF1X   0x15
#define ADC_CH_6_1_DIFF1X   0x16
#define ADC_CH_7_1_DIFF1X   0x17
#define ADC_CH_0_2_DIFF1X   0x18
#define ADC_CH_1_2_DIFF1X   0x19
#define ADC_CH_2_2_DIFF1X   0x1A
#define ADC_CH_3_2_DIFF1X   0x1B
#define ADC_CH_4_2_DIFF1X   0x1C
#define ADC_CH_5_2_DIFF1X   0x1D

Functions

void a2dInit (void)
void a2dOff (void)
 Turn off A/D converter.
void a2dSetPrescaler (unsigned char prescale)
void a2dSetReference (unsigned char ref)
void a2dSetChannel (unsigned char ch)
 sets the a2d input channel
void a2dStartConvert (void)
 start a conversion on the current a2d input channel
u08 a2dIsComplete (void)
 return TRUE if conversion is complete
unsigned short a2dConvert10bit (unsigned char ch)
unsigned char a2dConvert8bit (unsigned char ch)


Function Documentation

unsigned short a2dConvert10bit unsigned char  ch  ) 
 

Starts a conversion on A/D channel# ch, returns the 10-bit value of the conversion when it is finished.

Definition at line 87 of file a2d.c.

unsigned char a2dConvert8bit unsigned char  ch  ) 
 

Starts a conversion on A/D channel# ch, returns the 8-bit value of the conversion when it is finished.

Definition at line 103 of file a2d.c.

void a2dInit void   ) 
 

Initializes the A/D converter. Turns ADC on and prepares it for use.

Definition at line 33 of file a2d.c.

void a2dSetPrescaler unsigned char  prescale  ) 
 

Sets the division ratio of the A/D converter clock. This function is automatically called from a2dInit() with a default value.

Definition at line 55 of file a2d.c.

void a2dSetReference unsigned char  ref  ) 
 

Configures which voltage reference the A/D converter uses. This function is automatically called from a2dInit() with a default value.

Definition at line 61 of file a2d.c.


Generated on Sun Oct 29 03:41:09 2006 for Procyon AVRlib by  doxygen 1.4.2