A simple program to read an analoge channel on the Freedom Kl25Z using the ticker object to control timing. The data is written into a circular buffer, which is read by the main loop and sent down the serial line.

Dependencies:   FastAnalogIn mbed

Note that the Baud rate is set as 57600 rather than the default 9600.

Files at this revision

API Documentation at this revision

Comitter:
sas37
Date:
Wed Jul 23 16:46:41 2014 +0000
Child:
1:c424a90749e1
Commit message:
Version now running;

Changed in this revision

FastAnalogIn.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FastAnalogIn.lib	Wed Jul 23 16:46:41 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/humlet/code/FastAnalogIn/#55274430c8df
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 23 16:46:41 2014 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "FastAnalogIn.h"
+
+/*
+Simple program which uses a ticker object to record and analoge value and store it in a cicular buffer.
+The ticker delay sets the sampling rate. 
+
+The FastAnalogIn Library is used (http://mbed.org/users/Sissors/code/FastAnalogIn/) to rapidly sample 
+a single channel. 
+
+In the main loop a busy loop is used to send read the data from the cicular buffer and send down the serial line
+
+
+*/
+
+//size of cicular buffer
+#define BuffSize 255
+
+using namespace mbed;
+
+FastAnalogIn Ain(PTC2);
+
+Serial pc(USBTX, USBRX);
+Timer t;
+Ticker tock;
+
+//set the delay used by the ticker
+float delay = 0.01;
+
+//some circular buffers
+
+float data[BuffSize];
+float time_[BuffSize];
+long i =0;
+int j=0;
+long k =0;
+ 
+void ana()
+{
+   if(i<k+BuffSize)
+    {j = i%BuffSize;
+    //time_[j]=t.read();
+    data[j]=Ain.read();
+    time_[j]=t.read();
+    i++;
+    }
+}
+
+
+int main()
+{
+    pc.baud(57600);
+    t.start();
+    tock.attach(&ana,delay); 
+    while (true) {        
+       if(k<i)
+        {
+        pc.printf("%f,%f\n",time_[k%BuffSize],data[k%BuffSize]);
+        k++;
+        }
+        
+  
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 23 16:46:41 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file