Based the Library PwmIn by Simon Ford expanded with enable_irq and disable_irq for separate input signals. Program gives no real advantage above the original Library.
Diff: main.cpp
- Revision:
- 1:4bd14d5374c3
- Parent:
- 0:18d069b5f9f4
- Child:
- 2:79b52803da22
diff -r 18d069b5f9f4 -r 4bd14d5374c3 main.cpp --- a/main.cpp Wed Jan 01 12:25:57 2014 +0000 +++ b/main.cpp Thu Jan 02 14:01:30 2014 +0000 @@ -1,4 +1,10 @@ +////////////////////////////////////// +// basen on PwmIn Library +// Basis is to disable the interrupts +// of the other PwmIn inputs +/////////////////////////////////////// #include "mbed.h" +#include "InterruptIn.h" #define NR 20 class PwmIn @@ -8,6 +14,7 @@ float period(); float pulsewidth(); float dutycycle(); + void disable(); protected: void rise(); @@ -15,7 +22,7 @@ InterruptIn _p; Timer _t; - float _pulsewidth, _period; + volatile float _pulsewidth, _period; }; PwmIn::PwmIn(PinName p) : _p(p) @@ -27,8 +34,8 @@ _t.start(); } +PwmIn a(PTD2); // Sensor 1 X direction PwmIn b(PTA17); // Sensor 1 Y direction -PwmIn d(PTA16); // Sensor 2 Y direction Serial pc(USBTX, USBRX); // tx, rx float PwmIn::period() @@ -46,6 +53,11 @@ return _pulsewidth / _period; } +void PwmIn::disable() +{ + // _p.enable_irq(); +} + void PwmIn::rise() { _period = _t.read(); @@ -63,25 +75,21 @@ float duty; } acc_a[NR], acc_b[NR], acc_c[NR],acc_d[NR]; + int main() { char pbuffer[60]="---"; int i; while(1) { - //d.disable(); + // a.disable(); // Stop interrupts for sensor B for (i=0; i<NR; i++) { + acc_a[i].duty= a.dutycycle(); // Sensor A acc_b[i].duty= b.dutycycle(); - //acc_d[i].duty= d.dutycycle(); } for (i=0; i<NR; i++) { - //acc_b[i].duty= b.dutycycle(); - acc_d[i].duty= d.dutycycle(); - } - - for (i=0; i<NR; i++) { - sprintf(pbuffer, " b= %f, d= %f \n\r", acc_b[i].duty, acc_d[i].duty); + sprintf(pbuffer, " a= %f, b= %f \n\r", acc_a[i].duty, acc_b[i].duty); pc.puts(pbuffer); } }