programmable ignition for an mz ts 150. The interruptor needs to be replaced by an hall effect sensor

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
johannes_otto
Date:
Sun Oct 25 16:58:59 2015 +0000
Parent:
2:469b3daa6b98
Commit message:
constructor requires stroke now, it accepts mm values instead of degree (its easier and more accurate to measure). The angles are computed automatically

Changed in this revision

IgnitionModule.h 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
diff -r 469b3daa6b98 -r 5efd78be4662 IgnitionModule.h
--- a/IgnitionModule.h	Tue Oct 13 16:41:04 2015 +0000
+++ b/IgnitionModule.h	Sun Oct 25 16:58:59 2015 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+
+static const float PI = 3.141592653589793238;
+
+class IgnMod
+{
+private:
+    Timeout ignition_timer;
+    Timer t;
+
+    DigitalOut _pin;
+
+    int ignition_length;
+    int round_time;
+    int ignition_delay;
+
+    float offset;
+    float def_ignition;
+
+    void on() {
+        _pin.write(1);
+        ignition_timer.attach_us(this,&IgnMod::off,ignition_length);
+    }
+    void off() {
+        _pin.write(0);
+    }
+
+    int get_delay(int round_time) {
+        int delay=0;
+        int rpm=60e6/round_time;
+        
+        if (rpm>7000) delay=-4;
+        else if (rpm>6000) delay=-4;
+        else if (rpm>5000) delay=-4;
+        else if (rpm>4000) delay=-4;
+        else if (rpm>3000) delay=-2;
+        else if (rpm>2000) delay=-2;
+        else if (rpm>1000) delay=-2;
+        else delay=-2;
+
+        return round_time*(offset-def_ignition+delay)/360;
+    }
+public:
+    IgnMod(PinName pin,int il,float of_mm, float di_mm, float h) : _pin(pin) {
+        float r=h/2;
+        ignition_length=il;
+        offset=acos((r-of_mm)/r)*180/PI;
+        def_ignition=acos((r-di_mm)/r)*180/PI;
+        t.start();
+    }
+    void ignite() {
+        round_time=t.read_us();
+        t.reset();
+        ignition_delay=get_delay(round_time);
+        ignition_timer.attach_us(this,&IgnMod::on,ignition_delay-t.read_us());
+    }
+};
\ No newline at end of file
diff -r 469b3daa6b98 -r 5efd78be4662 main.cpp
--- a/main.cpp	Tue Oct 13 16:41:04 2015 +0000
+++ b/main.cpp	Sun Oct 25 16:58:59 2015 +0000
@@ -1,54 +1,14 @@
 #include "mbed.h"
-
-InterruptIn interruptor(D2);
-
-float offset=34.14f;
-float def_ignition=26.13f;
-
-
-class IgnMod
-{
-private:
-    Timeout ignition_timer;
-    Timer t;
-
-    DigitalOut *pin;
-
-    int ignition_length;
-    int round_time;
-    int ignition_delay;
+#include "IgnitionModule.h"
 
-    void on() {
-        pin->write(1);
-        ignition_timer.attach_us(this,&IgnMod::off,ignition_length);
-    }
-    void off() {
-        pin->write(0);
-    }
-
-    int get_delay(int round_time) {
-        return round_time*(offset-def_ignition)/360;
-    }
-public:
-    IgnMod() {
-        ignition_length=100;
-        DigitalOut pin(D3);
-        t.start();
-    }
-    void ignite() {
-        round_time=t.read_us();
-        t.reset();
-        ignition_delay=get_delay(round_time);
-        ignition_timer.attach_us(this,&IgnMod::on,ignition_delay-t.read_us());
-    }
-};
-
-IgnMod ignition;
+InterruptIn interruptor(D15);
+IgnMod ignition(D4,100,6.0f,3.0f,58.0f);
 
 int main()
-{
+{    
+    wait(1);
+    interruptor.rise(&ignition,&IgnMod::ignite);
     interruptor.mode(PullUp);
-    interruptor.rise(&ignition,&IgnMod::ignite);
-    while(1) {        
+    while(1) {
     }
 }
\ No newline at end of file