Analog Inputs
[Core]

The AnalogIn subsystem converts 0-3.3V signals to 10-bit digital values. More...


Functions

int AnalogIn_SetActive (int index, int state)
 Sets whether the specified channel is active.
int AnalogIn_GetActive (int index)
 Returns the active state of a channel.
int AnalogIn_GetValue (int index)
 Read the value of an analog input.
int AnalogIn_GetValueMulti (int mask, int values[])
 Read the value of several of the analog inputs.
int AnalogIn_GetValueWait (int index)
 Read the value of an analog input without the use of any OS services.

Detailed Description

The AnalogIn subsystem converts 0-3.3V signals to 10-bit digital values.

The analog to digital converters read incoming signals from 0 - 3.3V. They are rated as 5V tolerant, and indeed can momentarily withstand higher voltages, but will not return meaningful values for anything above 3.3V.

Converting the 0 - 1023 reading of the AnalogIn channel into a voltage is performed as follows:

v = 3.3 * ( a / 1023.0 ) 
where a is the AnalogIn value

This is of course a floating point operation (slowish) using a division (slowish). Fixed point versions may be more suitable for some applications. Where reduced accuracy is acceptable, the following can be used to get the input as a percentage of 3.3V:

p = ( 100 * a ) / 1023 

Initializing the controller's AnalogIn system is pretty involved (see AnalogIn_Init() in AnalogIn->c). There are a lot of different options - different converter speeds, DMA access, etc. We've chosen something pretty simple here. More ambitious users may wish to alter the implementation.

Todo:
Provide multi-channel conversion routines

Function Documentation

int AnalogIn_GetActive ( int  index  ) 

Returns the active state of a channel.

Parameters:
index An integer specifying the ANALOGIN channel (0 - 7).
Returns:
State - 1/non-zero (active) or 0 (inactive).
Example
  int active = AnalogIn_GetActive( 0 ) // check whether analogin 0 is active

Definition at line 142 of file analogin.c.

int AnalogIn_GetValue ( int  index  ) 

Read the value of an analog input.

Parameters:
index An integer specifying which input (0-7).
Returns:
The value as an integer (0 - 1023).
Example
  int analogin1 = AnalogIn_GetValue( 1 );

Definition at line 162 of file analogin.c.

int AnalogIn_GetValueMulti ( int  mask,
int  values[] 
)

Read the value of several of the analog inputs.

Due to the current ISR handling, this isn't too much quicker than making calls to each of the channels individually.

Parameters:
mask A bit mask specifying which channels to read.
values A pointer to an int array to be filled with the values.
Returns:
0 on success, otherwise non-zero.
Example
  int mask = 0xFF;
  int samples[8];
  AnalogIn_GetValueMulti( mask, samples ); // now samples is filled with all the analogin values

Definition at line 216 of file analogin.c.

int AnalogIn_GetValueWait ( int  index  ) 

Read the value of an analog input without the use of any OS services.

Note that this is not thread safe and shouldn't be used if another part of the code might be using it or the thread safe versions.

Parameters:
index An integer specifying which input (0-7).
Returns:
The value as an integer (0 - 1023).
Example
  int analogin1 = AnalogIn_GetValueWait( 1 );

Definition at line 274 of file analogin.c.

int AnalogIn_SetActive ( int  index,
int  state 
)

Sets whether the specified channel is active.

This initializes the AnalogIn system and gets a lock on its IO lines. It only needs to be called once.

Parameters:
index An integer specifying the channel (0 - 7).
state An integer specifying the active state - 1 (active) or 0 (inactive).
Returns:
Zero on success.
Example
  if( AnalogIn_SetActive( 0, 1 )  == CONTROLLER_OK ) // set analogin 0 to active
    // then continue processing
  else
    // some error occurred

Definition at line 104 of file analogin.c.