Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Pinscape_Controller
Fork of FastAnalogIn by
Revision 1:575f4d2d6e9c, committed 2013-05-11
- 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;
}
