Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of PUMP_SCRIPT1 by Ian Wolf

Committer:
dmwahl
Date:
Mon Jul 24 15:38:39 2017 +0000
Revision:
3:9ff79ea3a294
Parent:
1:d58df8cb271d
Child:
4:79b23d1fbcd1
Shutoff and injector valve running

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmwahl 0:67debf2ccbc2 1 #ifndef MAIN_H
dmwahl 0:67debf2ccbc2 2 #define MAIN_H
dmwahl 0:67debf2ccbc2 3
dmwahl 0:67debf2ccbc2 4 #include "mbed.h"
dmwahl 0:67debf2ccbc2 5 #include "keller_pressure.h"
dmwahl 0:67debf2ccbc2 6 #include "sensirion_sf04.h"
dmwahl 0:67debf2ccbc2 7 #include "PID.h"
dmwahl 0:67debf2ccbc2 8 #include "coil-driver.h"
dmwahl 1:d58df8cb271d 9 #include "VL6180.h"
dmwahl 1:d58df8cb271d 10
dmwahl 3:9ff79ea3a294 11 Coil shutoff(PE_5, 5000, 40, 6); // Shutoff valve, 5ms spike time, 25kHz PWM at 15% duty cycle
dmwahl 3:9ff79ea3a294 12 Coil injector(PF_8, 200, 40, 3); // Injector valve, 200us spike time, 25kHz PWM at 7.5% duty cycle
dmwahl 1:d58df8cb271d 13
dmwahl 0:67debf2ccbc2 14
dmwahl 0:67debf2ccbc2 15 // Mbed application shield display
dmwahl 0:67debf2ccbc2 16 #include "C12832A1Z.h"
dmwahl 0:67debf2ccbc2 17 #include "Small_7.h"
dmwahl 0:67debf2ccbc2 18 #include "Fonts/ArialR12x14.h"
dmwahl 0:67debf2ccbc2 19
dmwahl 0:67debf2ccbc2 20 C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS
dmwahl 0:67debf2ccbc2 21 // LCD width and height (minus 1)
dmwahl 0:67debf2ccbc2 22 #define lcdWidth 127
dmwahl 0:67debf2ccbc2 23 #define lcdHeight 31
dmwahl 0:67debf2ccbc2 24
dmwahl 0:67debf2ccbc2 25 // ISO/SEV pressure: 10psi, DES: 25-30psi
dmwahl 0:67debf2ccbc2 26 #define pumpSetPointPSI 45
dmwahl 0:67debf2ccbc2 27 #define pumpMinPSI 0
dmwahl 0:67debf2ccbc2 28 #define pumpMaxPSI 85
dmwahl 0:67debf2ccbc2 29 //#define pumpHystPSI 2
dmwahl 0:67debf2ccbc2 30
dmwahl 0:67debf2ccbc2 31 // Gas flow sensor defines
dmwahl 0:67debf2ccbc2 32 #define SFM7033_ADDR 0x40
dmwahl 0:67debf2ccbc2 33 // End gas flow sensor defines
dmwahl 0:67debf2ccbc2 34
dmwahl 0:67debf2ccbc2 35 // Liquid pump defines
dmwahl 0:67debf2ccbc2 36 // PID settings
dmwahl 0:67debf2ccbc2 37 #define pumpPIDRate .2 // Pump PID computation interval (seconds)
dmwahl 0:67debf2ccbc2 38 float pumpKp = 4.0;
dmwahl 0:67debf2ccbc2 39 float pumpKi = 1.0;
dmwahl 0:67debf2ccbc2 40 #define pumpKd 0
dmwahl 0:67debf2ccbc2 41
dmwahl 0:67debf2ccbc2 42 #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump
dmwahl 0:67debf2ccbc2 43 #define pumpTachPoles 6 // 6 pulses per revolution
dmwahl 0:67debf2ccbc2 44 #define pumpTachPin PE_7 // Pump tach input (green wire)
dmwahl 0:67debf2ccbc2 45 #define pumpCtrlPin PE_10 // Pump control (white wire)
dmwahl 0:67debf2ccbc2 46 // End Liquid pump defines
dmwahl 0:67debf2ccbc2 47
dmwahl 1:d58df8cb271d 48 Thread print_process_values_t, update_pressures_t, update_airflow_t, update_level_t, update_lcd_t, update_shutoff_t;
dmwahl 0:67debf2ccbc2 49 Mutex i2c1_m, i2c2_m, stdio_m;
dmwahl 0:67debf2ccbc2 50
dmwahl 0:67debf2ccbc2 51 //DigitalOut myled(LED2);
dmwahl 0:67debf2ccbc2 52 Serial pc(USBTX, USBRX, 250000); // tx, rx, baud
dmwahl 0:67debf2ccbc2 53
dmwahl 0:67debf2ccbc2 54 // an I2C sub-class that provides a constructed default
dmwahl 0:67debf2ccbc2 55 class I2CPreInit : public I2C
dmwahl 0:67debf2ccbc2 56 {
dmwahl 0:67debf2ccbc2 57 public:
dmwahl 0:67debf2ccbc2 58 I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) {
dmwahl 0:67debf2ccbc2 59 frequency(freq);
dmwahl 0:67debf2ccbc2 60 };
dmwahl 0:67debf2ccbc2 61 };
dmwahl 0:67debf2ccbc2 62
dmwahl 0:67debf2ccbc2 63 //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency);
dmwahl 0:67debf2ccbc2 64 I2CPreInit i2c1(PB_9, PB_8, 100000);
dmwahl 0:67debf2ccbc2 65 I2CPreInit i2c2(PB_11, PB_10, 100000);
dmwahl 0:67debf2ccbc2 66
dmwahl 0:67debf2ccbc2 67 KELLER_PRESSURE pumpPressure(i2c1, 0x40);
dmwahl 3:9ff79ea3a294 68 KELLER_PRESSURE mixerPressure(i2c1, 0x41);
dmwahl 3:9ff79ea3a294 69
dmwahl 3:9ff79ea3a294 70
dmwahl 0:67debf2ccbc2 71
dmwahl 0:67debf2ccbc2 72 // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit)
dmwahl 0:67debf2ccbc2 73 // calibration field 1: Air, 2: O2, 3: N2O
dmwahl 3:9ff79ea3a294 74 SF04 sfm7033(i2c2, SFM7033_ADDR, 1, 14); // Gas flow sensor (SFM7033)
dmwahl 0:67debf2ccbc2 75
dmwahl 0:67debf2ccbc2 76 // Mbed application shield
dmwahl 0:67debf2ccbc2 77 AnalogIn pot1(A0);
dmwahl 0:67debf2ccbc2 78 AnalogIn pot2(A1);
dmwahl 0:67debf2ccbc2 79
dmwahl 0:67debf2ccbc2 80 PwmOut pump(pumpCtrlPin);
dmwahl 0:67debf2ccbc2 81 //pump.period(.001);
dmwahl 0:67debf2ccbc2 82
dmwahl 0:67debf2ccbc2 83 PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate);
dmwahl 0:67debf2ccbc2 84
dmwahl 0:67debf2ccbc2 85 //InterruptIn pumpTach(pumpTachPin);
dmwahl 0:67debf2ccbc2 86 volatile int pumpTachCounts = 0;
dmwahl 0:67debf2ccbc2 87 volatile float pumpRpm = 0;
dmwahl 0:67debf2ccbc2 88
dmwahl 0:67debf2ccbc2 89 PwmOut ledRed(PE_11);
dmwahl 0:67debf2ccbc2 90 PwmOut ledGrn(PD_15);
dmwahl 0:67debf2ccbc2 91 DigitalOut ledBlu(PF_12);
dmwahl 1:d58df8cb271d 92
dmwahl 1:d58df8cb271d 93 // Level sensor
dmwahl 1:d58df8cb271d 94 VL6180 level(i2c1); //I2C object
dmwahl 1:d58df8cb271d 95 float agentlevel = 0;
dmwahl 0:67debf2ccbc2 96 #endif