ClearCore Library
List of all members | Public Types | Public Member Functions | Static Public Attributes
ClearCore::AdcManager Class Reference

Detailed Description

ADC Peripheral Manager for the ClearCore Board.

This class manages the ADC peripheral on the Teknic ClearCore.

Utilizes DMA sequence to configure channels, trigger conversion, and read results.

Uses DMAC Channels: 0,1

ADC Peripheral Manager for the ClearCore Board. More...

#include <AdcManager.h>

Public Types

enum  AdcChannels {
  ADC_VSUPPLY_MON = 0, ADC_AIN12, ADC_5VOB_MON, ADC_AIN11,
  ADC_AIN10, ADC_AIN09, ADC_SDRVR3_IMON, ADC_SDRVR2_IMON,
  ADC_CHANNEL_COUNT
}
 
enum  FilterUnits { FILTER_UNIT_RAW, FILTER_UNIT_MS, FILTER_UNIT_SAMPLES }
 Units for the filter time constant. More...
 

Public Member Functions

bool AdcResolution (uint8_t resolution)
 Configure the ADC conversion resolution. More...
 
volatile const uint8_t & AdcResolution ()
 Returns the resolution of the ADC. More...
 
volatile const uint16_t & FilteredResult (AdcChannels adcChannel)
 Returns the filtered ADC result of a specific channel. More...
 
volatile const uint16_t & ConvertedResult (AdcChannels adcChannel)
 Returns the converted ADC result of a specific channel. More...
 
bool FilterTc (AdcChannels adcChannel, uint16_t tc, FilterUnits theUnits)
 Sets the IIR filter time constant for an ADC channel. More...
 
uint16_t FilterTc (AdcChannels adcChannel, FilterUnits theUnits)
 Gets the IIR filter time constant of an ADC channel. More...
 
bool FilterReset (AdcChannels adcChannel, uint16_t newSetting)
 Resets the filter for an ADC Channel. More...
 
void AdcTimeoutLimit (uint8_t timeout)
 Configure the ADC conversion timeout. More...
 
volatile const bool & AdcTimeout ()
 Determine whether the ADC has timed out. More...
 
float AnalogVoltage (AdcChannels adcChannel)
 Returns the filtered ADC result of a specific channel in volts. More...
 

Static Public Attributes

static const uint8_t ADC_RESOLUTION_DEFAULT = 12
 
static const uint8_t ADC_TIMEOUT_DEFAULT = 3
 
static const uint32_t ADC_IIR_FILTER_TC_MS = 2
 

Member Enumeration Documentation

ADC conversion channels.

Note
These are currently assumed to be unsigned values.
Enumerator
ADC_VSUPPLY_MON 

Supply voltage monitor.

ADC_AIN12 

Analog input A-12.

ADC_5VOB_MON 

5V off-board monitor

ADC_AIN11 

Analog input A-11.

ADC_AIN10 

Analog input A-10.

ADC_AIN09 

Analog input A-9.

ADC_SDRVR3_IMON 

Screwdriver M-3 current monitor.

ADC_SDRVR2_IMON 

Screwdriver M-2 current monitor.

Units for the filter time constant.

Note
One sample time is 200 microseconds, so 1 ms = 5 sample times.
Enumerator
FILTER_UNIT_RAW 

Raw units.

FILTER_UNIT_MS 

Milliseconds.

FILTER_UNIT_SAMPLES 

Sample times.

Member Function Documentation

bool ClearCore::AdcManager::AdcResolution ( uint8_t  resolution)

Configure the ADC conversion resolution.

ADC naturally supports 12-bit operation. Lower resolution is used to decrease sample time.

Passing an unsupported resolution yields no change and returns false.

Acceptable Inputs:

  • 8-bit
  • 10-bit
  • 12-bit
Note
The default resolution is 12-bit.
// Set the ADC resolution to 10-bit
Parameters
resolutionBit resolution. Acceptable values: 8, 10, and 12.
Returns
Success
Examples:
AnalogIOExamples/ReadAnalogInput/ReadAnalogInput.cpp.
volatile const uint8_t& ClearCore::AdcManager::AdcResolution ( )
inline

Returns the resolution of the ADC.

Possible values are: 8, 10, and 12.

// Save the ADC resolution
uint8_t currentResolution = AdcMgr.AdcResolution();
volatile const bool& ClearCore::AdcManager::AdcTimeout ( )
inline

Determine whether the ADC has timed out.

// The ADC has timed out
}
Returns
true if the ADC has time out, false otherwise.
void ClearCore::AdcManager::AdcTimeoutLimit ( uint8_t  timeout)
inline

Configure the ADC conversion timeout.

The ADC will post an error to the StatusReg if it is unable to complete a conversion within the number of samples specified by the input of this function.

// Sets the timeout to 10 samples
Parameters
[in]timeoutThe length of the timeout in samples.
float ClearCore::AdcManager::AnalogVoltage ( AdcChannels  adcChannel)
inline

Returns the filtered ADC result of a specific channel in volts.

// Save the filtered voltage reading on A-10.
Parameters
[in]adcChannelADC channel to get the voltage reading of.
Returns
Voltage on the given ADC channel.
Note
For performance reasons, does not perform any bounds checking.
volatile const uint16_t& ClearCore::AdcManager::ConvertedResult ( AdcChannels  adcChannel)
inline

Returns the converted ADC result of a specific channel.

// Save the converted ADC reading of analog input A-10.
Parameters
[in]adcChannelADC channel to get the results of.
Returns
Converted result.
Note
For performance reasons, does not perform any bounds checking.
volatile const uint16_t& ClearCore::AdcManager::FilteredResult ( AdcChannels  adcChannel)
inline

Returns the filtered ADC result of a specific channel.

// Save the filtered ADC reading of analog input A-10.
Parameters
[in]adcChannelADC channel to get the filtered results of.
Returns
Filtered result.
Note
For performance reasons, does not perform any bounds checking.
bool ClearCore::AdcManager::FilterReset ( AdcChannels  adcChannel,
uint16_t  newSetting 
)
inline

Resets the filter for an ADC Channel.

// Resets the filter for A-10 and saves the success status.
Parameters
[in]adcChannelADC Channel filter to reset.
[in]newSettingThe initial filter value.
Returns
Success.
bool ClearCore::AdcManager::FilterTc ( AdcChannels  adcChannel,
uint16_t  tc,
FilterUnits  theUnits 
)

Sets the IIR filter time constant for an ADC channel.

// Set the filter time constant of A-10 to 15ms and save its success
// status.
bool succeeded = AdcMgr.FilterTc(AdcManager::ADC_AIN10, 15,
Parameters
[in]adcChannelADC channel to set filter constant for
[in]tcThe new filter time constant (99% step change time)
[in]theUnitsThe units of the time constant tc. See FilterUnits.
Returns
Success.
uint16_t ClearCore::AdcManager::FilterTc ( AdcChannels  adcChannel,
FilterUnits  theUnits 
)

Gets the IIR filter time constant of an ADC channel.

// Save the time constant in ms for A-10.
Parameters
[in]adcChannelADC channel to get filter constant for.
[in]theUnitsThe units of the returned time constant. See FilterUnits.
Returns
Time constant value in the specified units, or 0 if the ADC channel is invalid.

Member Data Documentation

const uint32_t ClearCore::AdcManager::ADC_IIR_FILTER_TC_MS = 2
static

The default ADC filter time constant, in milliseconds.

const uint8_t ClearCore::AdcManager::ADC_RESOLUTION_DEFAULT = 12
static

The default resolution of the ADC, in bits.

const uint8_t ClearCore::AdcManager::ADC_TIMEOUT_DEFAULT = 3
static

The default timeout for waiting on an ADC conversion, in samples.


The documentation for this class was generated from the following file: