Johannes Otto
/
simple_stm_ignition
programmable ignition for an mz ts 150. The interruptor needs to be replaced by an hall effect sensor
main.cpp@0:46797506f6f3, 2015-10-12 (annotated)
- Committer:
- johannes_otto
- Date:
- Mon Oct 12 12:16:44 2015 +0000
- Revision:
- 0:46797506f6f3
- Child:
- 1:f99510926784
initial;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johannes_otto | 0:46797506f6f3 | 1 | #include "mbed.h" |
johannes_otto | 0:46797506f6f3 | 2 | InterruptIn interruptor(D2); |
johannes_otto | 0:46797506f6f3 | 3 | Timer t; |
johannes_otto | 0:46797506f6f3 | 4 | long round_time; |
johannes_otto | 0:46797506f6f3 | 5 | float offset=34.14; |
johannes_otto | 0:46797506f6f3 | 6 | float def_ignition=26.13; |
johannes_otto | 0:46797506f6f3 | 7 | long ign_delay; |
johannes_otto | 0:46797506f6f3 | 8 | DigitalOut ignition(D3); |
johannes_otto | 0:46797506f6f3 | 9 | |
johannes_otto | 0:46797506f6f3 | 10 | void ignite() |
johannes_otto | 0:46797506f6f3 | 11 | { |
johannes_otto | 0:46797506f6f3 | 12 | t.stop(); |
johannes_otto | 0:46797506f6f3 | 13 | round_time=t.read_us(); |
johannes_otto | 0:46797506f6f3 | 14 | t.start(); |
johannes_otto | 0:46797506f6f3 | 15 | ign_delay=round_time*(offset-def_ignition)/360; |
johannes_otto | 0:46797506f6f3 | 16 | wait_us(ign_delay-t.read_us()); |
johannes_otto | 0:46797506f6f3 | 17 | ignition.write(1); |
johannes_otto | 0:46797506f6f3 | 18 | wait_us(100); |
johannes_otto | 0:46797506f6f3 | 19 | ignition.write(0); |
johannes_otto | 0:46797506f6f3 | 20 | } |
johannes_otto | 0:46797506f6f3 | 21 | |
johannes_otto | 0:46797506f6f3 | 22 | int main() |
johannes_otto | 0:46797506f6f3 | 23 | { |
johannes_otto | 0:46797506f6f3 | 24 | t.start(); |
johannes_otto | 0:46797506f6f3 | 25 | while(1) { |
johannes_otto | 0:46797506f6f3 | 26 | interruptor.rise(&ignite); |
johannes_otto | 0:46797506f6f3 | 27 | } |
johannes_otto | 0:46797506f6f3 | 28 | } |