Class similar to AnalogIn that uses burst mode to run continious background conversions so when the input is read, the last value can immediatly be returned. This slightly modified version allows NC pins.

Dependents:   Pinscape_Controller

Fork of FastAnalogIn by Erik Olieman

Embed: (wiki syntax)

« Back to documentation index

FastAnalogIn Class Reference

FastAnalogIn Class Reference

A class similar to AnalogIn, only faster, for LPC1768, LPC408X and KLxx. More...

#include <FastAnalogIn.h>

Public Member Functions

 FastAnalogIn (PinName pin, bool enabled=true)
 Create a FastAnalogIn, connected to the specified pin.
void enable (bool enabled=true)
 Enable the ADC channel.
void disable (void)
 Disable the ADC channel.
unsigned short read_u16 (void)
 Returns the raw value.
float read (void)
 Returns the scaled value.
 operator float ()
 An operator shorthand for read()

Detailed Description

A class similar to AnalogIn, only faster, for LPC1768, LPC408X and KLxx.

AnalogIn does a single conversion when you read a value (actually several conversions and it takes the median of that). This library runns the ADC conversion automatically in the background. When read is called, it immediatly returns the last sampled value.

LPC1768 / LPC4088 Using more ADC pins in continuous mode will decrease the conversion rate (LPC1768:200kHz/LPC4088:400kHz). If you need to sample one pin very fast and sometimes also need to do AD conversions on another pin, you can disable the continuous conversion on that ADC channel and still read its value.

KLXX Multiple Fast instances can be declared of which only ONE can be continuous (all others must be non-continuous).

When continuous conversion is disabled, a read will block until the conversion is complete (much like the regular AnalogIn library does). Each ADC channel can be enabled/disabled separately.

IMPORTANT : It does not play nicely with regular AnalogIn objects, so either use this library or AnalogIn, not both at the same time!!

Example for the KLxx processors:

 // Print messages when the AnalogIn is greater than 50%

 #include "mbed.h"

 FastAnalogIn temperature(PTC2); //Fast continuous sampling on PTC2
 FastAnalogIn speed(PTB3, 0);    //Fast non-continuous sampling on PTB3

 int main() {
     while(1) {
         if(temperature > 0.5) {
             printf("Too hot! (%f) at speed %f", temperature.read(), speed.read());
         }
     }
 }

Example for the LPC1768 processor:

 // Print messages when the AnalogIn is greater than 50%

 #include "mbed.h"

 FastAnalogIn temperature(p20);

 int main() {
     while(1) {
         if(temperature > 0.5) {
             printf("Too hot! (%f)", temperature.read());
         }
     }
 }

Definition at line 68 of file FastAnalogIn.h.


Constructor & Destructor Documentation

FastAnalogIn ( PinName  pin,
bool  enabled = true 
)

Create a FastAnalogIn, connected to the specified pin.

Parameters:
pinAnalogIn pin to connect to
enabledEnable the ADC channel (default = true)

Definition at line 25 of file FastAnalogIn_KLXX_K20D50M.cpp.


Member Function Documentation

void disable ( void   )

Disable the ADC channel.

Disabling unused channels speeds up conversion in used channels. When disabled you can still call read, that will do a single conversion (actually two since the first one always returns 0 for unknown reason). Then the function blocks until the value is read. This is handy when you sometimes needs a single conversion besides the automatic conversion

Definition at line 88 of file FastAnalogIn_KLXX_K20D50M.cpp.

void enable ( bool  enabled = true )

Enable the ADC channel.

Parameters:
enabledBool that is true for enable, false is equivalent to calling disable

Definition at line 74 of file FastAnalogIn_KLXX_K20D50M.cpp.

operator float (  )

An operator shorthand for read()

Definition at line 115 of file FastAnalogIn.h.

float read ( void   )

Returns the scaled value.

Parameters:
returnFloat with scaled converted value to 0.0-1.0

Definition at line 107 of file FastAnalogIn.h.

unsigned short read_u16 ( void   )

Returns the raw value.

Parameters:
returnUnsigned integer with converted value

Definition at line 97 of file FastAnalogIn_KLXX_K20D50M.cpp.