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

Dependencies:   mbed

Committer:
johannes_otto
Date:
Tue Oct 13 15:14:02 2015 +0000
Revision:
1:f99510926784
Parent:
0:46797506f6f3
Child:
2:469b3daa6b98
ignition is purely based on timers now;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johannes_otto 0:46797506f6f3 1 #include "mbed.h"
johannes_otto 1:f99510926784 2
johannes_otto 0:46797506f6f3 3 InterruptIn interruptor(D2);
johannes_otto 0:46797506f6f3 4 Timer t;
johannes_otto 0:46797506f6f3 5 DigitalOut ignition(D3);
johannes_otto 1:f99510926784 6 Timeout ignition_timer;
johannes_otto 1:f99510926784 7
johannes_otto 1:f99510926784 8 int round_time;
johannes_otto 1:f99510926784 9 float offset=34.14f;
johannes_otto 1:f99510926784 10 float def_ignition=26.13f;
johannes_otto 1:f99510926784 11 int ign_delay;
johannes_otto 1:f99510926784 12
johannes_otto 1:f99510926784 13
johannes_otto 1:f99510926784 14 int ignition_length=100;
johannes_otto 1:f99510926784 15 int ignition_delay;
johannes_otto 1:f99510926784 16
johannes_otto 1:f99510926784 17 int get_delay(int round_time)
johannes_otto 1:f99510926784 18 {
johannes_otto 1:f99510926784 19 return round_time*(offset-def_ignition)/360;
johannes_otto 1:f99510926784 20 }
johannes_otto 1:f99510926784 21
johannes_otto 1:f99510926784 22 void ignition_off()
johannes_otto 1:f99510926784 23 {
johannes_otto 1:f99510926784 24 ignition=0;
johannes_otto 1:f99510926784 25 }
johannes_otto 1:f99510926784 26
johannes_otto 1:f99510926784 27 void ignition_on()
johannes_otto 1:f99510926784 28 {
johannes_otto 1:f99510926784 29 ignition=1;
johannes_otto 1:f99510926784 30 ignition_timer.attach_us(&ignition_off,ignition_length);
johannes_otto 1:f99510926784 31 }
johannes_otto 0:46797506f6f3 32
johannes_otto 0:46797506f6f3 33 void ignite()
johannes_otto 0:46797506f6f3 34 {
johannes_otto 0:46797506f6f3 35 round_time=t.read_us();
johannes_otto 1:f99510926784 36 t.reset();
johannes_otto 1:f99510926784 37 ignition_delay=get_delay(round_time);
johannes_otto 1:f99510926784 38 ignition_timer.attach_us(&ignition_on,ignition_delay-t.read_us());
johannes_otto 1:f99510926784 39 }
johannes_otto 1:f99510926784 40
johannes_otto 1:f99510926784 41
johannes_otto 1:f99510926784 42 void setup()
johannes_otto 1:f99510926784 43 {
johannes_otto 1:f99510926784 44 interruptor.mode(PullUp);
johannes_otto 1:f99510926784 45 t.reset();
johannes_otto 0:46797506f6f3 46 t.start();
johannes_otto 0:46797506f6f3 47 }
johannes_otto 0:46797506f6f3 48
johannes_otto 1:f99510926784 49
johannes_otto 0:46797506f6f3 50 int main()
johannes_otto 0:46797506f6f3 51 {
johannes_otto 1:f99510926784 52 setup();
johannes_otto 0:46797506f6f3 53 while(1) {
johannes_otto 0:46797506f6f3 54 interruptor.rise(&ignite);
johannes_otto 0:46797506f6f3 55 }
johannes_otto 0:46797506f6f3 56 }