Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04
main.h@4:49852dc27066, 2017-09-08 (annotated)
- Committer:
- dmwahl
- Date:
- Fri Sep 08 21:27:10 2017 +0000
- Revision:
- 4:49852dc27066
- Parent:
- 3:9ff79ea3a294
Pressure setpoint rounded to nearest integer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmwahl | 0:67debf2ccbc2 | 1 | #ifndef MAIN_H |
dmwahl | 0:67debf2ccbc2 | 2 | #define MAIN_H |
dmwahl | 0:67debf2ccbc2 | 3 | |
dmwahl | 4:49852dc27066 | 4 | #define pressureWait 100 |
dmwahl | 4:49852dc27066 | 5 | #define airflowWait 100 |
dmwahl | 4:49852dc27066 | 6 | |
dmwahl | 0:67debf2ccbc2 | 7 | #include "mbed.h" |
dmwahl | 0:67debf2ccbc2 | 8 | #include "keller_pressure.h" |
dmwahl | 0:67debf2ccbc2 | 9 | #include "sensirion_sf04.h" |
dmwahl | 0:67debf2ccbc2 | 10 | #include "PID.h" |
dmwahl | 0:67debf2ccbc2 | 11 | #include "coil-driver.h" |
dmwahl | 4:49852dc27066 | 12 | //#include "VL6180.h" |
dmwahl | 0:67debf2ccbc2 | 13 | |
dmwahl | 0:67debf2ccbc2 | 14 | // Mbed application shield display |
dmwahl | 0:67debf2ccbc2 | 15 | #include "C12832A1Z.h" |
dmwahl | 0:67debf2ccbc2 | 16 | #include "Small_7.h" |
dmwahl | 0:67debf2ccbc2 | 17 | #include "Fonts/ArialR12x14.h" |
dmwahl | 0:67debf2ccbc2 | 18 | |
dmwahl | 4:49852dc27066 | 19 | Coil shutoff(PE_5, 5000, 40, 6); // Shutoff valve, 5ms spike time, 25kHz PWM at 15% duty cycle |
dmwahl | 4:49852dc27066 | 20 | Coil injector(PF_8, 200, 40, 3); // Injector valve, 200us spike time, 25kHz PWM at 7.5% duty cycle |
dmwahl | 4:49852dc27066 | 21 | |
dmwahl | 0:67debf2ccbc2 | 22 | C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS |
dmwahl | 0:67debf2ccbc2 | 23 | // LCD width and height (minus 1) |
dmwahl | 0:67debf2ccbc2 | 24 | #define lcdWidth 127 |
dmwahl | 0:67debf2ccbc2 | 25 | #define lcdHeight 31 |
dmwahl | 0:67debf2ccbc2 | 26 | |
dmwahl | 0:67debf2ccbc2 | 27 | // ISO/SEV pressure: 10psi, DES: 25-30psi |
dmwahl | 4:49852dc27066 | 28 | float pumpSetPointPSI=0; |
dmwahl | 0:67debf2ccbc2 | 29 | #define pumpMinPSI 0 |
dmwahl | 0:67debf2ccbc2 | 30 | #define pumpMaxPSI 85 |
dmwahl | 0:67debf2ccbc2 | 31 | //#define pumpHystPSI 2 |
dmwahl | 0:67debf2ccbc2 | 32 | |
dmwahl | 0:67debf2ccbc2 | 33 | // Gas flow sensor defines |
dmwahl | 0:67debf2ccbc2 | 34 | #define SFM7033_ADDR 0x40 |
dmwahl | 0:67debf2ccbc2 | 35 | // End gas flow sensor defines |
dmwahl | 0:67debf2ccbc2 | 36 | |
dmwahl | 0:67debf2ccbc2 | 37 | // Liquid pump defines |
dmwahl | 0:67debf2ccbc2 | 38 | // PID settings |
dmwahl | 4:49852dc27066 | 39 | #define pumpPIDRate pressureWait/1000.0 // Pump PID computation interval (seconds) |
dmwahl | 4:49852dc27066 | 40 | float pumpKp = 2.0; |
dmwahl | 0:67debf2ccbc2 | 41 | float pumpKi = 1.0; |
dmwahl | 0:67debf2ccbc2 | 42 | #define pumpKd 0 |
dmwahl | 0:67debf2ccbc2 | 43 | |
dmwahl | 0:67debf2ccbc2 | 44 | #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump |
dmwahl | 0:67debf2ccbc2 | 45 | #define pumpTachPoles 6 // 6 pulses per revolution |
dmwahl | 0:67debf2ccbc2 | 46 | #define pumpTachPin PE_7 // Pump tach input (green wire) |
dmwahl | 0:67debf2ccbc2 | 47 | #define pumpCtrlPin PE_10 // Pump control (white wire) |
dmwahl | 0:67debf2ccbc2 | 48 | // End Liquid pump defines |
dmwahl | 0:67debf2ccbc2 | 49 | |
dmwahl | 1:d58df8cb271d | 50 | Thread print_process_values_t, update_pressures_t, update_airflow_t, update_level_t, update_lcd_t, update_shutoff_t; |
dmwahl | 0:67debf2ccbc2 | 51 | Mutex i2c1_m, i2c2_m, stdio_m; |
dmwahl | 0:67debf2ccbc2 | 52 | |
dmwahl | 0:67debf2ccbc2 | 53 | //DigitalOut myled(LED2); |
dmwahl | 4:49852dc27066 | 54 | Serial pc(USBTX, USBRX, 115200); // tx, rx, baud |
dmwahl | 0:67debf2ccbc2 | 55 | |
dmwahl | 0:67debf2ccbc2 | 56 | // an I2C sub-class that provides a constructed default |
dmwahl | 0:67debf2ccbc2 | 57 | class I2CPreInit : public I2C |
dmwahl | 0:67debf2ccbc2 | 58 | { |
dmwahl | 0:67debf2ccbc2 | 59 | public: |
dmwahl | 0:67debf2ccbc2 | 60 | I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) { |
dmwahl | 0:67debf2ccbc2 | 61 | frequency(freq); |
dmwahl | 0:67debf2ccbc2 | 62 | }; |
dmwahl | 0:67debf2ccbc2 | 63 | }; |
dmwahl | 0:67debf2ccbc2 | 64 | |
dmwahl | 0:67debf2ccbc2 | 65 | //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency); |
dmwahl | 0:67debf2ccbc2 | 66 | I2CPreInit i2c1(PB_9, PB_8, 100000); |
dmwahl | 0:67debf2ccbc2 | 67 | I2CPreInit i2c2(PB_11, PB_10, 100000); |
dmwahl | 0:67debf2ccbc2 | 68 | |
dmwahl | 0:67debf2ccbc2 | 69 | KELLER_PRESSURE pumpPressure(i2c1, 0x40); |
dmwahl | 3:9ff79ea3a294 | 70 | KELLER_PRESSURE mixerPressure(i2c1, 0x41); |
dmwahl | 3:9ff79ea3a294 | 71 | |
dmwahl | 3:9ff79ea3a294 | 72 | |
dmwahl | 0:67debf2ccbc2 | 73 | |
dmwahl | 0:67debf2ccbc2 | 74 | // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit) |
dmwahl | 0:67debf2ccbc2 | 75 | // calibration field 1: Air, 2: O2, 3: N2O |
dmwahl | 3:9ff79ea3a294 | 76 | SF04 sfm7033(i2c2, SFM7033_ADDR, 1, 14); // Gas flow sensor (SFM7033) |
dmwahl | 0:67debf2ccbc2 | 77 | |
dmwahl | 0:67debf2ccbc2 | 78 | // Mbed application shield |
dmwahl | 0:67debf2ccbc2 | 79 | AnalogIn pot1(A0); |
dmwahl | 0:67debf2ccbc2 | 80 | AnalogIn pot2(A1); |
dmwahl | 0:67debf2ccbc2 | 81 | |
dmwahl | 0:67debf2ccbc2 | 82 | PwmOut pump(pumpCtrlPin); |
dmwahl | 0:67debf2ccbc2 | 83 | //pump.period(.001); |
dmwahl | 0:67debf2ccbc2 | 84 | |
dmwahl | 0:67debf2ccbc2 | 85 | PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate); |
dmwahl | 0:67debf2ccbc2 | 86 | |
dmwahl | 4:49852dc27066 | 87 | int pumpTachCounts = 0; |
dmwahl | 4:49852dc27066 | 88 | float pumpRpm = 0; |
dmwahl | 4:49852dc27066 | 89 | InterruptIn pumpTach(pumpTachPin); |
dmwahl | 0:67debf2ccbc2 | 90 | |
dmwahl | 0:67debf2ccbc2 | 91 | PwmOut ledRed(PE_11); |
dmwahl | 0:67debf2ccbc2 | 92 | PwmOut ledGrn(PD_15); |
dmwahl | 0:67debf2ccbc2 | 93 | DigitalOut ledBlu(PF_12); |
dmwahl | 1:d58df8cb271d | 94 | |
dmwahl | 1:d58df8cb271d | 95 | // Level sensor |
dmwahl | 4:49852dc27066 | 96 | //VL6180 level(i2c1); //I2C object |
dmwahl | 4:49852dc27066 | 97 | //float agentlevel = 0; |
dmwahl | 4:49852dc27066 | 98 | |
dmwahl | 4:49852dc27066 | 99 | //Timer t; // Runtime timer |
dmwahl | 4:49852dc27066 | 100 | //float runtime; |
dmwahl | 4:49852dc27066 | 101 | |
dmwahl | 4:49852dc27066 | 102 | bool completed = false; |
dmwahl | 0:67debf2ccbc2 | 103 | #endif |