asdf
Dependencies: KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180
Fork of TestBenchSerenity-proto_F429ZI by
main.h@0:67debf2ccbc2, 2017-07-07 (annotated)
- Committer:
- dmwahl
- Date:
- Fri Jul 07 20:52:31 2017 +0000
- Revision:
- 0:67debf2ccbc2
- Child:
- 1:d58df8cb271d
Pressure sensors, display, airflow, input pots working
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 | 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 | 0:67debf2ccbc2 | 9 | |
dmwahl | 0:67debf2ccbc2 | 10 | // Mbed application shield display |
dmwahl | 0:67debf2ccbc2 | 11 | #include "C12832A1Z.h" |
dmwahl | 0:67debf2ccbc2 | 12 | #include "Small_7.h" |
dmwahl | 0:67debf2ccbc2 | 13 | #include "Fonts/ArialR12x14.h" |
dmwahl | 0:67debf2ccbc2 | 14 | |
dmwahl | 0:67debf2ccbc2 | 15 | C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS |
dmwahl | 0:67debf2ccbc2 | 16 | // LCD width and height (minus 1) |
dmwahl | 0:67debf2ccbc2 | 17 | #define lcdWidth 127 |
dmwahl | 0:67debf2ccbc2 | 18 | #define lcdHeight 31 |
dmwahl | 0:67debf2ccbc2 | 19 | |
dmwahl | 0:67debf2ccbc2 | 20 | // ISO/SEV pressure: 10psi, DES: 25-30psi |
dmwahl | 0:67debf2ccbc2 | 21 | #define pumpSetPointPSI 45 |
dmwahl | 0:67debf2ccbc2 | 22 | #define pumpMinPSI 0 |
dmwahl | 0:67debf2ccbc2 | 23 | #define pumpMaxPSI 85 |
dmwahl | 0:67debf2ccbc2 | 24 | //#define pumpHystPSI 2 |
dmwahl | 0:67debf2ccbc2 | 25 | |
dmwahl | 0:67debf2ccbc2 | 26 | // Gas flow sensor defines |
dmwahl | 0:67debf2ccbc2 | 27 | #define SFM7033_ADDR 0x40 |
dmwahl | 0:67debf2ccbc2 | 28 | // End gas flow sensor defines |
dmwahl | 0:67debf2ccbc2 | 29 | |
dmwahl | 0:67debf2ccbc2 | 30 | // Liquid pump defines |
dmwahl | 0:67debf2ccbc2 | 31 | // PID settings |
dmwahl | 0:67debf2ccbc2 | 32 | #define pumpPIDRate .2 // Pump PID computation interval (seconds) |
dmwahl | 0:67debf2ccbc2 | 33 | float pumpKp = 4.0; |
dmwahl | 0:67debf2ccbc2 | 34 | float pumpKi = 1.0; |
dmwahl | 0:67debf2ccbc2 | 35 | #define pumpKd 0 |
dmwahl | 0:67debf2ccbc2 | 36 | |
dmwahl | 0:67debf2ccbc2 | 37 | #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump |
dmwahl | 0:67debf2ccbc2 | 38 | #define pumpTachPoles 6 // 6 pulses per revolution |
dmwahl | 0:67debf2ccbc2 | 39 | #define pumpTachPin PE_7 // Pump tach input (green wire) |
dmwahl | 0:67debf2ccbc2 | 40 | #define pumpCtrlPin PE_10 // Pump control (white wire) |
dmwahl | 0:67debf2ccbc2 | 41 | // End Liquid pump defines |
dmwahl | 0:67debf2ccbc2 | 42 | |
dmwahl | 0:67debf2ccbc2 | 43 | Thread print_process_values_t, update_pressures_t, update_airflow_t, update_lcd_t; |
dmwahl | 0:67debf2ccbc2 | 44 | Mutex i2c1_m, i2c2_m, stdio_m; |
dmwahl | 0:67debf2ccbc2 | 45 | |
dmwahl | 0:67debf2ccbc2 | 46 | //DigitalOut myled(LED2); |
dmwahl | 0:67debf2ccbc2 | 47 | Serial pc(USBTX, USBRX, 250000); // tx, rx, baud |
dmwahl | 0:67debf2ccbc2 | 48 | |
dmwahl | 0:67debf2ccbc2 | 49 | // an I2C sub-class that provides a constructed default |
dmwahl | 0:67debf2ccbc2 | 50 | class I2CPreInit : public I2C |
dmwahl | 0:67debf2ccbc2 | 51 | { |
dmwahl | 0:67debf2ccbc2 | 52 | public: |
dmwahl | 0:67debf2ccbc2 | 53 | I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) { |
dmwahl | 0:67debf2ccbc2 | 54 | frequency(freq); |
dmwahl | 0:67debf2ccbc2 | 55 | }; |
dmwahl | 0:67debf2ccbc2 | 56 | }; |
dmwahl | 0:67debf2ccbc2 | 57 | |
dmwahl | 0:67debf2ccbc2 | 58 | //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency); |
dmwahl | 0:67debf2ccbc2 | 59 | I2CPreInit i2c1(PB_9, PB_8, 100000); |
dmwahl | 0:67debf2ccbc2 | 60 | I2CPreInit i2c2(PB_11, PB_10, 100000); |
dmwahl | 0:67debf2ccbc2 | 61 | |
dmwahl | 0:67debf2ccbc2 | 62 | KELLER_PRESSURE pumpPressure(i2c1, 0x40); |
dmwahl | 0:67debf2ccbc2 | 63 | |
dmwahl | 0:67debf2ccbc2 | 64 | // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit) |
dmwahl | 0:67debf2ccbc2 | 65 | // calibration field 1: Air, 2: O2, 3: N2O |
dmwahl | 0:67debf2ccbc2 | 66 | SF04 sfm7033(i2c2, SFM7033_ADDR, 1, 12); // Gas flow sensor (SFM7033) |
dmwahl | 0:67debf2ccbc2 | 67 | |
dmwahl | 0:67debf2ccbc2 | 68 | // Mbed application shield |
dmwahl | 0:67debf2ccbc2 | 69 | AnalogIn pot1(A0); |
dmwahl | 0:67debf2ccbc2 | 70 | AnalogIn pot2(A1); |
dmwahl | 0:67debf2ccbc2 | 71 | |
dmwahl | 0:67debf2ccbc2 | 72 | PwmOut pump(pumpCtrlPin); |
dmwahl | 0:67debf2ccbc2 | 73 | //pump.period(.001); |
dmwahl | 0:67debf2ccbc2 | 74 | |
dmwahl | 0:67debf2ccbc2 | 75 | PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate); |
dmwahl | 0:67debf2ccbc2 | 76 | |
dmwahl | 0:67debf2ccbc2 | 77 | //InterruptIn pumpTach(pumpTachPin); |
dmwahl | 0:67debf2ccbc2 | 78 | volatile int pumpTachCounts = 0; |
dmwahl | 0:67debf2ccbc2 | 79 | volatile float pumpRpm = 0; |
dmwahl | 0:67debf2ccbc2 | 80 | |
dmwahl | 0:67debf2ccbc2 | 81 | PwmOut ledRed(PE_11); |
dmwahl | 0:67debf2ccbc2 | 82 | PwmOut ledGrn(PD_15); |
dmwahl | 0:67debf2ccbc2 | 83 | DigitalOut ledBlu(PF_12); |
dmwahl | 0:67debf2ccbc2 | 84 | #endif |