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.

Fork of FastAnalogIn by Erik -

Obsolete!

Has been already merged with Erik's original repository => take the original!

  • Added support for LPC4088.
  • Fixed linker error (missing definition of static member "channel_usage")

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Sat May 11 08:56:22 2013 +0000
Parent:
0:c2a7b899e6c7
Child:
2:9b61d0792927
Commit message:
Read_u16 left alligned now, same as normal mbed lib (lower 4 bits = upper 4 bits)

Changed in this revision

FastAnalogIn.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FastAnalogIn.cpp	Thu May 09 17:46:32 2013 +0000
+++ b/FastAnalogIn.cpp	Sat May 11 08:56:22 2013 +0000
@@ -91,17 +91,15 @@
 
 unsigned short FastAnalogIn::read_u16( void )
 {
+    volatile unsigned int retval;
     //If object is enabled return current value of datareg
-    if (running ) {
-        unsigned int retval = *datareg;
-        retval = retval >> 4;
-        retval = retval & 4095;
-        return retval;
-    }
+    if (running )
+        retval = *datareg;
+ 
     //If it isn't running, enable it and wait until new value is written to datareg
     else {
         //Force a read to clear done bit, enable the ADC channel
-        volatile unsigned int retval = *datareg;
+        retval = *datareg;
         enable();
         //Wait until it is converted
         while(1) {
@@ -121,16 +119,17 @@
 
         //Disable again
         disable();
-        retval = retval >> 4;
-        retval = retval & 4095;
-        return retval;
     }
-
+    
+    //Do same thing as standard mbed lib, unused bit 0-3, replicate 4-7 in it
+    retval &= ~0xFFFF000F;
+    retval |= (retval >> 8) & 0x000F;
+    return retval;
 
 };
 
 float FastAnalogIn::read( void )
 {
     unsigned short value = read_u16();
-    return (float)value/4095;
+    return (float)value/65535;
 }