Dependents:   InjectorValveFourthMicro InjectorValveFourthMicro1 InjectorValveFourthMicro2 ReadingInLines_copy

Fork of PWM-Coil-driver by David Wahl

Committer:
dmwahl
Date:
Fri Jun 02 17:24:38 2017 +0000
Revision:
2:6df05ae10a1a
Parent:
1:cdb7aba111ce
Child:
3:0b1f41462b97
Fixed typo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmwahl 2:6df05ae10a1a 1 #include "coil-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 }