oulib/src/adc_interrupt_enable.c 0000644 0003753 0003753 00000000463 11317316720 015704 0 ustar fagg fagg #include "oulib.h"
/**
Enable/disable the ADC ISR.
@param cmd ADC_INTERRUPT_DISABLE: disables the ISR (default)
ADC_INTERRUPT_ENABLE: enable the ISR
@author Andrew H. Fagg
\ingroup adc
*/
void adc_interrupt_enable(uint8_t cmd)
{
ADCSRA = (ADCSRA & 0xF7) | ((cmd & 0x1) << 3);
};
oulib/src/adc_read.c 0000644 0003753 0003753 00000001416 11317441421 013251 0 ustar fagg fagg #include "oulib.h"
/*!
Read the analog-to-digital converter. This function blocks (waits) until
a value is available to be read from the ADC.
Assumptions: a conversion is ongoing or has completed, and adlar = ADC_ADLAR_RIGHT
@return The value read from the analog-to-digital converter (0 ... 0x3ff) @author Andrew H. Fagg \ingroup adc */ uint16_t adc_read(void) { uint16_t out; uint8_t sreg; // Disable global interrupts if they are enabled sreg = SREG; cli(); // Wait for ADC data to be ready while(!adc_interrupt_flag()){}; // Read out the value: order of register access is important! out = (uint16_t) ADCL; out |= (((uint16_t) (ADCH&0x3)) << 8); // Restore global interrupt state SREG = sreg; return(out); }; oulib/src/adc_set_adlar.c 0000644 0003753 0003753 00000000603 11317441453 014276 0 ustar fagg fagg #include "oulib.h" /** Configure the position of the 10-bit ADC value in the 16-bit output register
@param adlar ADC_ADLAR_RIGHT: Right-adjust the 10-bit value (default configuration)
ADC_ADLAR_LEFT: Left-adjust the 10-bit value
@author Andrew H. Fagg
\ingroup adc
*/
void adc_set_adlar(uint8_t adlar)
{
ADMUX = (ADMUX & 0xDF) | ((adlar & 0x1) <<5);
}
oulib/src/adc_set_auto_trigger.c 0000644 0003753 0003753 00000000637 11317441502 015710 0 ustar fagg fagg #include "oulib.h"
/**
Set the ADC auto trigger state. If enabled, the ADC will
automatically initiate the collection of the next sample after the current
one is complete.
@param cmd ADC_AUTO_TRIGGER_DISABLE: disabled (default)
ADC_AUTO_TRIGGER_ENABLE: enabled
@author Andrew H. Fagg
\ingroup adc
*/
void adc_set_auto_trigger(uint8_t cmd)
{
ADCSRA = (ADCSRA & 0xDF) | ((cmd & 0x1) << 5);
}
oulib/src/adc_set_channel.c 0000644 0003753 0003753 00000001432 11600405123 014611 0 ustar fagg fagg #include "oulib.h"
/**
Select the ADC channel for the next conversion. If a
conversion is already ongoing, this change will not affect it.
@param chan A channel number. Acceptable values are 0 .. 15, however
useful values will vary between specific chips. For the mega8, viable
values are:
ADC_CHANNEL_0 (default), ... ADC_CHANNEL_7, ADC_CHANNEL_1p23V (1.23V reference), and ADC_CHANNEL_0V (0V reference)
@author Andrew H. Fagg
\ingroup adc
*/
// Channel selection
void adc_set_channel(uint8_t chan)
{
#ifdef ADC_CHANS_16
// Have 5 bits to specify the input configuration
ADMUX = (ADMUX & 0xE0) | ((chan & 0x1F));
ADCSRB = (ADCSRB & ~(1<