asdf

Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of TestBenchSerenity-proto_F429ZI by Ian Wolf

Committer:
iwolf32
Date:
Wed Jul 26 14:03:10 2017 +0000
Revision:
4:79b23d1fbcd1
Parent:
3:9ff79ea3a294
Child:
5:e3eff8a04b25
REV2;

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"
iwolf32 4:79b23d1fbcd1 10 /*Start of Where Additional Code was Added
iwolf32 4:79b23d1fbcd1 11 --------------------------------------------------------------------------------------------------*/
iwolf32 4:79b23d1fbcd1 12 //Coil shutoff(A1, 5000, 40, 6); // Shutoff valve, 5ms spike time, 25kHz PWM at 15% duty cycle
iwolf32 4:79b23d1fbcd1 13 Coil injector(A0, 200, 40, 3); // Injector valve, 200us spike time, 25kHz PWM at 7.5% duty cycle
dmwahl 1:d58df8cb271d 14
iwolf32 4:79b23d1fbcd1 15 InterruptIn dutycycleup(A2);
iwolf32 4:79b23d1fbcd1 16 InterruptIn dutycycledown(D4);
iwolf32 4:79b23d1fbcd1 17 InterruptIn frequencyup(A5);
iwolf32 4:79b23d1fbcd1 18 InterruptIn frequencydown(A4);
iwolf32 4:79b23d1fbcd1 19
iwolf32 4:79b23d1fbcd1 20 Thread Injector_Valve_Control;
iwolf32 4:79b23d1fbcd1 21
iwolf32 4:79b23d1fbcd1 22 double frequency=5.00;
iwolf32 4:79b23d1fbcd1 23 double dutycycle=0.75;
iwolf32 4:79b23d1fbcd1 24 float openvalue=(((1/frequency)*dutycycle));
iwolf32 4:79b23d1fbcd1 25 float offvalue=(1/frequency)-openvalue;
iwolf32 4:79b23d1fbcd1 26
iwolf32 4:79b23d1fbcd1 27 /*
iwolf32 4:79b23d1fbcd1 28 --------------------------------------------------------------------------------------------------*/
dmwahl 1:d58df8cb271d 29
dmwahl 0:67debf2ccbc2 30
dmwahl 0:67debf2ccbc2 31 // Mbed application shield display
dmwahl 0:67debf2ccbc2 32 #include "C12832A1Z.h"
dmwahl 0:67debf2ccbc2 33 #include "Small_7.h"
dmwahl 0:67debf2ccbc2 34 #include "Fonts/ArialR12x14.h"
dmwahl 0:67debf2ccbc2 35
dmwahl 0:67debf2ccbc2 36 C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS
dmwahl 0:67debf2ccbc2 37 // LCD width and height (minus 1)
dmwahl 0:67debf2ccbc2 38 #define lcdWidth 127
dmwahl 0:67debf2ccbc2 39 #define lcdHeight 31
dmwahl 0:67debf2ccbc2 40
dmwahl 0:67debf2ccbc2 41 // ISO/SEV pressure: 10psi, DES: 25-30psi
dmwahl 0:67debf2ccbc2 42 #define pumpSetPointPSI 45
dmwahl 0:67debf2ccbc2 43 #define pumpMinPSI 0
dmwahl 0:67debf2ccbc2 44 #define pumpMaxPSI 85
dmwahl 0:67debf2ccbc2 45 //#define pumpHystPSI 2
dmwahl 0:67debf2ccbc2 46
dmwahl 0:67debf2ccbc2 47 // Gas flow sensor defines
dmwahl 0:67debf2ccbc2 48 #define SFM7033_ADDR 0x40
iwolf32 4:79b23d1fbcd1 49 #define SFM7034_ADDR 0x40
dmwahl 0:67debf2ccbc2 50 // End gas flow sensor defines
dmwahl 0:67debf2ccbc2 51
dmwahl 0:67debf2ccbc2 52 // Liquid pump defines
dmwahl 0:67debf2ccbc2 53 // PID settings
dmwahl 0:67debf2ccbc2 54 #define pumpPIDRate .2 // Pump PID computation interval (seconds)
dmwahl 0:67debf2ccbc2 55 float pumpKp = 4.0;
dmwahl 0:67debf2ccbc2 56 float pumpKi = 1.0;
dmwahl 0:67debf2ccbc2 57 #define pumpKd 0
dmwahl 0:67debf2ccbc2 58
dmwahl 0:67debf2ccbc2 59 #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump
dmwahl 0:67debf2ccbc2 60 #define pumpTachPoles 6 // 6 pulses per revolution
iwolf32 4:79b23d1fbcd1 61 #define pumpTachPin PB_15 // Pump tach input (green wire)
iwolf32 4:79b23d1fbcd1 62 #define pumpCtrlPin PB_13 // Pump control (white wire)
dmwahl 0:67debf2ccbc2 63 // End Liquid pump defines
dmwahl 0:67debf2ccbc2 64
iwolf32 4:79b23d1fbcd1 65 Thread print_process_values_t, update_pressures_t, update_flow1_t, update_flow2_t, update_level_t, update_lcd_t, update_shutoff_t;
iwolf32 4:79b23d1fbcd1 66 Mutex i2c1_m, i2c2_m, i2c3_m, stdio_m;
dmwahl 0:67debf2ccbc2 67
dmwahl 0:67debf2ccbc2 68 //DigitalOut myled(LED2);
dmwahl 0:67debf2ccbc2 69 Serial pc(USBTX, USBRX, 250000); // tx, rx, baud
dmwahl 0:67debf2ccbc2 70
dmwahl 0:67debf2ccbc2 71 // an I2C sub-class that provides a constructed default
dmwahl 0:67debf2ccbc2 72 class I2CPreInit : public I2C
dmwahl 0:67debf2ccbc2 73 {
dmwahl 0:67debf2ccbc2 74 public:
dmwahl 0:67debf2ccbc2 75 I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) {
dmwahl 0:67debf2ccbc2 76 frequency(freq);
dmwahl 0:67debf2ccbc2 77 };
dmwahl 0:67debf2ccbc2 78 };
dmwahl 0:67debf2ccbc2 79
dmwahl 0:67debf2ccbc2 80 //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency);
dmwahl 0:67debf2ccbc2 81 I2CPreInit i2c1(PB_9, PB_8, 100000);
iwolf32 4:79b23d1fbcd1 82 I2CPreInit i2c2(PB_3, PB_10, 100000);
iwolf32 4:79b23d1fbcd1 83 I2CPreInit i2c3(PB_4, PA_8, 100000);
dmwahl 0:67debf2ccbc2 84
dmwahl 0:67debf2ccbc2 85 KELLER_PRESSURE pumpPressure(i2c1, 0x40);
dmwahl 0:67debf2ccbc2 86
dmwahl 0:67debf2ccbc2 87 // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit)
dmwahl 0:67debf2ccbc2 88 // calibration field 1: Air, 2: O2, 3: N2O
iwolf32 4:79b23d1fbcd1 89 SF04 mainflow(i2c2, SFM7033_ADDR, 0, 9); // Gas flow sensor (SFM7033)
iwolf32 4:79b23d1fbcd1 90 SF04 loopflow(i2c3, SFM7034_ADDR, 0, 9);
dmwahl 0:67debf2ccbc2 91 // Mbed application shield
iwolf32 4:79b23d1fbcd1 92 //AnalogIn pot1(A0);
dmwahl 0:67debf2ccbc2 93 AnalogIn pot2(A1);
dmwahl 0:67debf2ccbc2 94
dmwahl 0:67debf2ccbc2 95 PwmOut pump(pumpCtrlPin);
dmwahl 0:67debf2ccbc2 96 //pump.period(.001);
dmwahl 0:67debf2ccbc2 97
dmwahl 0:67debf2ccbc2 98 PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate);
dmwahl 0:67debf2ccbc2 99
dmwahl 0:67debf2ccbc2 100 //InterruptIn pumpTach(pumpTachPin);
dmwahl 0:67debf2ccbc2 101 volatile int pumpTachCounts = 0;
dmwahl 0:67debf2ccbc2 102 volatile float pumpRpm = 0;
dmwahl 0:67debf2ccbc2 103
iwolf32 4:79b23d1fbcd1 104 //PwmOut ledRed(PE_11);
iwolf32 4:79b23d1fbcd1 105 //PwmOut ledGrn(PD_15);
iwolf32 4:79b23d1fbcd1 106 //DigitalOut ledBlu(PF_12);
dmwahl 1:d58df8cb271d 107
dmwahl 1:d58df8cb271d 108 // Level sensor
iwolf32 4:79b23d1fbcd1 109 //VL6180 level(i2c1); //I2C object
iwolf32 4:79b23d1fbcd1 110 //float agentlevel = 0;
dmwahl 0:67debf2ccbc2 111 #endif