Dependents: InjectorValveFourthMicro InjectorValveFourthMicro1 InjectorValveFourthMicro2 ReadingInLines_copy
Fork of PWM-Coil-driver by
coil-driver.cpp@3:0b1f41462b97, 2017-06-20 (annotated)
- Committer:
- dmwahl
- Date:
- Tue Jun 20 19:45:42 2017 +0000
- Revision:
- 3:0b1f41462b97
- Parent:
- 2:6df05ae10a1a
- Child:
- 4:ca7107dff643
Renamed to "coil" driver to be more generic. Useful for driving any inductive load.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmwahl | 2:6df05ae10a1a | 1 | #include "coil-driver.h" |
dmwahl | 0:eb16d6847d9e | 2 | |
dmwahl | 0:eb16d6847d9e | 3 | // Default constructor |
dmwahl | 3:0b1f41462b97 | 4 | Coil::Coil(PinName _controlPin, uint16_t _spikeus, uint16_t _holdperiod_us, uint16_t _holdpulse_us) |
dmwahl | 0:eb16d6847d9e | 5 | : controlOut(_controlPin), |
dmwahl | 0:eb16d6847d9e | 6 | spikeus(_spikeus), |
dmwahl | 0:eb16d6847d9e | 7 | holdperiod_us(_holdperiod_us), |
dmwahl | 0:eb16d6847d9e | 8 | holdpulse_us(_holdpulse_us) |
dmwahl | 0:eb16d6847d9e | 9 | { |
dmwahl | 3:0b1f41462b97 | 10 | controlOut.write(0.0); // Ensure coil output is off by default |
dmwahl | 0:eb16d6847d9e | 11 | controlOut.period_us(holdperiod_us); // PWM control period (uint16_t microseconds) |
dmwahl | 0:eb16d6847d9e | 12 | |
dmwahl | 0:eb16d6847d9e | 13 | }; |
dmwahl | 0:eb16d6847d9e | 14 | |
dmwahl | 3:0b1f41462b97 | 15 | void Coil::on() |
dmwahl | 0:eb16d6847d9e | 16 | { |
dmwahl | 0:eb16d6847d9e | 17 | controlOut.write(1.0); |
dmwahl | 0:eb16d6847d9e | 18 | wait_us(spikeus); |
dmwahl | 0:eb16d6847d9e | 19 | controlOut.pulsewidth_us(holdpulse_us); |
dmwahl | 0:eb16d6847d9e | 20 | } |
dmwahl | 0:eb16d6847d9e | 21 | |
dmwahl | 3:0b1f41462b97 | 22 | void Coil::off() |
dmwahl | 0:eb16d6847d9e | 23 | { |
dmwahl | 0:eb16d6847d9e | 24 | controlOut.write(0.0); |
dmwahl | 0:eb16d6847d9e | 25 | } |