Dependents: InjectorValveFourthMicro InjectorValveFourthMicro1 InjectorValveFourthMicro2 ReadingInLines_copy
Fork of PWM-Coil-driver by
coil-driver.cpp@1:cdb7aba111ce, 2017-06-02 (annotated)
- Committer:
- dmwahl
- Date:
- Fri Jun 02 17:23:13 2017 +0000
- Revision:
- 1:cdb7aba111ce
- Parent:
- valve-driver.cpp@0:eb16d6847d9e
- Child:
- 2:6df05ae10a1a
Updated file names to be more generic (coil instead of valve)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmwahl | 0:eb16d6847d9e | 1 | #include "valve-driver.h" |
dmwahl | 0:eb16d6847d9e | 2 | |
dmwahl | 0:eb16d6847d9e | 3 | // Default constructor |
dmwahl | 0:eb16d6847d9e | 4 | Valve::Valve(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 | 0:eb16d6847d9e | 10 | controlOut.write(0.0); // Ensure valve 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 | 0:eb16d6847d9e | 15 | void Valve::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 | 0:eb16d6847d9e | 22 | void Valve::off() |
dmwahl | 0:eb16d6847d9e | 23 | { |
dmwahl | 0:eb16d6847d9e | 24 | controlOut.write(0.0); |
dmwahl | 0:eb16d6847d9e | 25 | } |