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.
main.cpp
- Committer:
- GerritPathuis
- Date:
- 2014-01-02
- Revision:
- 1:4bd14d5374c3
- Parent:
- 0:18d069b5f9f4
- Child:
- 2:79b52803da22
File content as of revision 1:4bd14d5374c3:
////////////////////////////////////// // 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 { public: PwmIn(PinName p); float period(); float pulsewidth(); float dutycycle(); void disable(); protected: void rise(); void fall(); InterruptIn _p; Timer _t; volatile float _pulsewidth, _period; }; PwmIn::PwmIn(PinName p) : _p(p) { _p.rise(this, &PwmIn::rise); _p.fall(this, &PwmIn::fall); _period = 0.0; _pulsewidth = 0.0; _t.start(); } PwmIn a(PTD2); // Sensor 1 X direction PwmIn b(PTA17); // Sensor 1 Y direction Serial pc(USBTX, USBRX); // tx, rx float PwmIn::period() { return _period; } float PwmIn::pulsewidth() { return _pulsewidth; } float PwmIn::dutycycle() { return _pulsewidth / _period; } void PwmIn::disable() { // _p.enable_irq(); } void PwmIn::rise() { _period = _t.read(); _t.reset(); } void PwmIn::fall() { _pulsewidth = _t.read(); } struct product { float pulse; float width; float duty; } acc_a[NR], acc_b[NR], acc_c[NR],acc_d[NR]; int main() { char pbuffer[60]="---"; int i; while(1) { // 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(); } for (i=0; i<NR; i++) { sprintf(pbuffer, " a= %f, b= %f \n\r", acc_a[i].duty, acc_b[i].duty); pc.puts(pbuffer); } } }