A simple Oscilloscope that log each pin's data change Please dump log and analyze using Excel x-y chart type!

/media/uploads/steeven/mbed_sco.jpg

Committer:
steeven
Date:
Sun May 10 13:16:26 2015 +0000
Revision:
0:6c6d961dc8b3
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
steeven 0:6c6d961dc8b3 1 /*
steeven 0:6c6d961dc8b3 2 * BreathLed.h
steeven 0:6c6d961dc8b3 3 *
steeven 0:6c6d961dc8b3 4 * Created on: 2015/4/6
steeven 0:6c6d961dc8b3 5 * Author: steeven@gmail.com
steeven 0:6c6d961dc8b3 6 */
steeven 0:6c6d961dc8b3 7
steeven 0:6c6d961dc8b3 8 #ifndef SCOPE_H_
steeven 0:6c6d961dc8b3 9 #define SCOPE_H_
steeven 0:6c6d961dc8b3 10
steeven 0:6c6d961dc8b3 11 #include "mbed.h"
steeven 0:6c6d961dc8b3 12 #include "BufferedSerial/BufferedSerial.h"
steeven 0:6c6d961dc8b3 13
steeven 0:6c6d961dc8b3 14 #define SCOPE_PINS 16
steeven 0:6c6d961dc8b3 15
steeven 0:6c6d961dc8b3 16 namespace steeven {
steeven 0:6c6d961dc8b3 17
steeven 0:6c6d961dc8b3 18 /** A simple Oscilloscope that log each pin's data change
steeven 0:6c6d961dc8b3 19 * Please dump log and analyze using excel x-y chart type!
steeven 0:6c6d961dc8b3 20 */
steeven 0:6c6d961dc8b3 21
steeven 0:6c6d961dc8b3 22 typedef struct {
steeven 0:6c6d961dc8b3 23 char id; //bit 7: val, bit 0-6:id
steeven 0:6c6d961dc8b3 24 float time;
steeven 0:6c6d961dc8b3 25 } ScopeData;
steeven 0:6c6d961dc8b3 26
steeven 0:6c6d961dc8b3 27 class Scope {
steeven 0:6c6d961dc8b3 28 public:
steeven 0:6c6d961dc8b3 29 Scope(int buf_len);
steeven 0:6c6d961dc8b3 30
steeven 0:6c6d961dc8b3 31 void add(PinName pin, const char *name);
steeven 0:6c6d961dc8b3 32
steeven 0:6c6d961dc8b3 33 void log(char id, int v);
steeven 0:6c6d961dc8b3 34
steeven 0:6c6d961dc8b3 35 void dump( BufferedSerial *logger);
steeven 0:6c6d961dc8b3 36
steeven 0:6c6d961dc8b3 37 protected:
steeven 0:6c6d961dc8b3 38 const char *_names[SCOPE_PINS];
steeven 0:6c6d961dc8b3 39 int _cnt;
steeven 0:6c6d961dc8b3 40
steeven 0:6c6d961dc8b3 41 Timer _timer;
steeven 0:6c6d961dc8b3 42
steeven 0:6c6d961dc8b3 43 ScopeData *_buf;
steeven 0:6c6d961dc8b3 44 int _buf_len;
steeven 0:6c6d961dc8b3 45 int _buf_cnt;
steeven 0:6c6d961dc8b3 46 };
steeven 0:6c6d961dc8b3 47
steeven 0:6c6d961dc8b3 48 class ScopePin {
steeven 0:6c6d961dc8b3 49
steeven 0:6c6d961dc8b3 50 public:
steeven 0:6c6d961dc8b3 51 ScopePin(PinName pin, char id, Scope *scope);
steeven 0:6c6d961dc8b3 52
steeven 0:6c6d961dc8b3 53 protected:
steeven 0:6c6d961dc8b3 54 void on_fall();
steeven 0:6c6d961dc8b3 55 void on_rise();
steeven 0:6c6d961dc8b3 56
steeven 0:6c6d961dc8b3 57 InterruptIn _pin;
steeven 0:6c6d961dc8b3 58 char _id;
steeven 0:6c6d961dc8b3 59 Scope *_scope;
steeven 0:6c6d961dc8b3 60 };
steeven 0:6c6d961dc8b3 61
steeven 0:6c6d961dc8b3 62 }
steeven 0:6c6d961dc8b3 63 ;
steeven 0:6c6d961dc8b3 64
steeven 0:6c6d961dc8b3 65 #endif