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@2:469b3daa6b98, 2015-10-13 (annotated)
- Committer:
- johannes_otto
- Date:
- Tue Oct 13 16:41:04 2015 +0000
- Revision:
- 2:469b3daa6b98
- Parent:
- 1:f99510926784
- Child:
- 3:5efd78be4662
pured functions into a class -> IgnMod;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:f99510926784 | 4 | |
johannes_otto | 1:f99510926784 | 5 | float offset=34.14f; |
johannes_otto | 1:f99510926784 | 6 | float def_ignition=26.13f; |
johannes_otto | 1:f99510926784 | 7 | |
johannes_otto | 1:f99510926784 | 8 | |
johannes_otto | 2:469b3daa6b98 | 9 | class IgnMod |
johannes_otto | 1:f99510926784 | 10 | { |
johannes_otto | 2:469b3daa6b98 | 11 | private: |
johannes_otto | 2:469b3daa6b98 | 12 | Timeout ignition_timer; |
johannes_otto | 2:469b3daa6b98 | 13 | Timer t; |
johannes_otto | 2:469b3daa6b98 | 14 | |
johannes_otto | 2:469b3daa6b98 | 15 | DigitalOut *pin; |
johannes_otto | 2:469b3daa6b98 | 16 | |
johannes_otto | 2:469b3daa6b98 | 17 | int ignition_length; |
johannes_otto | 2:469b3daa6b98 | 18 | int round_time; |
johannes_otto | 2:469b3daa6b98 | 19 | int ignition_delay; |
johannes_otto | 2:469b3daa6b98 | 20 | |
johannes_otto | 2:469b3daa6b98 | 21 | void on() { |
johannes_otto | 2:469b3daa6b98 | 22 | pin->write(1); |
johannes_otto | 2:469b3daa6b98 | 23 | ignition_timer.attach_us(this,&IgnMod::off,ignition_length); |
johannes_otto | 2:469b3daa6b98 | 24 | } |
johannes_otto | 2:469b3daa6b98 | 25 | void off() { |
johannes_otto | 2:469b3daa6b98 | 26 | pin->write(0); |
johannes_otto | 2:469b3daa6b98 | 27 | } |
johannes_otto | 0:46797506f6f3 | 28 | |
johannes_otto | 2:469b3daa6b98 | 29 | int get_delay(int round_time) { |
johannes_otto | 2:469b3daa6b98 | 30 | return round_time*(offset-def_ignition)/360; |
johannes_otto | 2:469b3daa6b98 | 31 | } |
johannes_otto | 2:469b3daa6b98 | 32 | public: |
johannes_otto | 2:469b3daa6b98 | 33 | IgnMod() { |
johannes_otto | 2:469b3daa6b98 | 34 | ignition_length=100; |
johannes_otto | 2:469b3daa6b98 | 35 | DigitalOut pin(D3); |
johannes_otto | 2:469b3daa6b98 | 36 | t.start(); |
johannes_otto | 2:469b3daa6b98 | 37 | } |
johannes_otto | 2:469b3daa6b98 | 38 | void ignite() { |
johannes_otto | 2:469b3daa6b98 | 39 | round_time=t.read_us(); |
johannes_otto | 2:469b3daa6b98 | 40 | t.reset(); |
johannes_otto | 2:469b3daa6b98 | 41 | ignition_delay=get_delay(round_time); |
johannes_otto | 2:469b3daa6b98 | 42 | ignition_timer.attach_us(this,&IgnMod::on,ignition_delay-t.read_us()); |
johannes_otto | 2:469b3daa6b98 | 43 | } |
johannes_otto | 2:469b3daa6b98 | 44 | }; |
johannes_otto | 1:f99510926784 | 45 | |
johannes_otto | 2:469b3daa6b98 | 46 | IgnMod ignition; |
johannes_otto | 1:f99510926784 | 47 | |
johannes_otto | 0:46797506f6f3 | 48 | int main() |
johannes_otto | 0:46797506f6f3 | 49 | { |
johannes_otto | 2:469b3daa6b98 | 50 | interruptor.mode(PullUp); |
johannes_otto | 2:469b3daa6b98 | 51 | interruptor.rise(&ignition,&IgnMod::ignite); |
johannes_otto | 2:469b3daa6b98 | 52 | while(1) { |
johannes_otto | 0:46797506f6f3 | 53 | } |
johannes_otto | 0:46797506f6f3 | 54 | } |