This file defines a useful set of functions for ADC on AVR UC3 devices.
Definition in file adc.c.
#include <avr32/io.h>
#include "compiler.h"
#include "adc.h"
Go to the source code of this file.
Functions | |
Bool | adc_check_eoc (volatile avr32_adc_t *adc, unsigned short channel) |
Check channel conversion status. | |
Bool | adc_check_ovr (volatile avr32_adc_t *adc, unsigned short channel) |
Check channel conversion overrun error. | |
void | adc_configure (volatile avr32_adc_t *adc) |
Configure ADC. Mandatory to call. If not called, ADC channels will have side effects. | |
void | adc_disable (volatile avr32_adc_t *adc, unsigned short channel) |
Disable channel. | |
void | adc_enable (volatile avr32_adc_t *adc, unsigned short channel) |
Enable channel. | |
unsigned long | adc_get_latest_value (volatile avr32_adc_t *adc) |
Wait for the next converted data and return its value. | |
Bool | adc_get_status (volatile avr32_adc_t *adc, unsigned short channel) |
Get channel 0 to 7 status. | |
unsigned long | adc_get_value (volatile avr32_adc_t *adc, unsigned short channel) |
Get channel value. | |
void | adc_start (volatile avr32_adc_t *adc) |
Start analog to digital conversion. |
Bool adc_check_eoc | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Check channel conversion status.
*adc | Base address of the ADC | |
channel | channel to check (0 to 7) |
Definition at line 103 of file adc.c.
Referenced by adc_get_value().
00104 { 00105 Assert( adc!=NULL ); 00106 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00107 00108 // get SR register : EOC bit for channel 00109 return ((adc->sr & (1 << channel)) ? HIGH : LOW); 00110 }
Bool adc_check_ovr | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Check channel conversion overrun error.
*adc | Base address of the ADC | |
channel | channel to check (0 to 7) |
Definition at line 112 of file adc.c.
00113 { 00114 Assert( adc!=NULL ); 00115 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00116 00117 // get SR register : OVR bit for channel 00118 return ((adc->sr & (1 << (channel + 8))) ? FAIL : PASS); 00119 }
void adc_configure | ( | volatile avr32_adc_t * | adc | ) |
Configure ADC. Mandatory to call. If not called, ADC channels will have side effects.
*adc | Base address of the ADC |
Definition at line 53 of file adc.c.
Referenced by main().
00054 { 00055 Assert( adc!=NULL ); 00056 00057 #ifdef USE_ADC_8_BITS 00058 adc->mr |= 1<<AVR32_ADC_LOWRES_OFFSET; 00059 #endif 00060 // set Sample/Hold time to max so that the ADC capacitor should be loaded entirely 00061 adc->mr |= 0xF << AVR32_ADC_SHTIM_OFFSET; 00062 // set Startup to max so that the ADC capacitor should be loaded entirely 00063 adc->mr |= 0x1F << AVR32_ADC_STARTUP_OFFSET; 00064 }
void adc_disable | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Disable channel.
*adc | Base address of the ADC | |
channel | channel to disable (0 to 7) |
Definition at line 83 of file adc.c.
References adc_get_status().
Referenced by main().
00084 { 00085 Assert( adc!=NULL ); 00086 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00087 00088 if (adc_get_status(adc, channel) == ENABLED) 00089 { 00090 // disable channel 00091 adc->chdr |= (1 << channel); 00092 } 00093 }
void adc_enable | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Enable channel.
*adc | Base address of the ADC | |
channel | channel to enable (0 to 7) |
Definition at line 74 of file adc.c.
Referenced by main().
00075 { 00076 Assert( adc!=NULL ); 00077 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00078 00079 // enable channel 00080 adc->cher = (1 << channel); 00081 }
unsigned long adc_get_latest_value | ( | volatile avr32_adc_t * | adc | ) |
Wait for the next converted data and return its value.
*adc | Base address of the ADC |
Definition at line 132 of file adc.c.
00133 { 00134 Assert( adc!=NULL ); 00135 00136 // Wait for the data ready flag 00137 while((adc->sr & AVR32_ADC_DRDY_MASK) != AVR32_ADC_DRDY_MASK); 00138 return adc->lcdr; 00139 }
Bool adc_get_status | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Get channel 0 to 7 status.
*adc | Base address of the ADC | |
channel | channel to handle (0 to 7) |
Definition at line 95 of file adc.c.
Referenced by adc_disable().
00096 { 00097 Assert( adc!=NULL ); 00098 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00099 00100 return ((adc->chsr & (1 << channel)) ? ENABLED : DISABLED); 00101 }
unsigned long adc_get_value | ( | volatile avr32_adc_t * | adc, | |
unsigned short | channel | |||
) |
Get channel value.
*adc | Base address of the ADC | |
channel | channel to handle (0 to 7) |
Definition at line 121 of file adc.c.
References adc_check_eoc().
Referenced by main().
00122 { 00123 Assert( adc!=NULL ); 00124 Assert( channel <= AVR32_ADC_CHANNELS_MSB ); // check if channel exist 00125 00126 // wait for end of conversion 00127 while(adc_check_eoc(adc, channel) != HIGH); 00128 return *((unsigned long * )((&(adc->cdr0)) + channel)); 00129 }
void adc_start | ( | volatile avr32_adc_t * | adc | ) |