Pump Progress so far

Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of TestBenchSerenity-proto_F429ZI1 by jack kemnitz

Committer:
iwolf32
Date:
Thu Aug 31 14:10:02 2017 +0000
Revision:
8:962b78253710
Parent:
7:b385e6a3f622
Pump Progress so far

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 8:962b78253710 26 int x=0;
iwolf32 8:962b78253710 27 char ch;
iwolf32 4:79b23d1fbcd1 28
iwolf32 4:79b23d1fbcd1 29 /*
iwolf32 4:79b23d1fbcd1 30 --------------------------------------------------------------------------------------------------*/
dmwahl 1:d58df8cb271d 31
dmwahl 0:67debf2ccbc2 32
dmwahl 0:67debf2ccbc2 33 // Mbed application shield display
dmwahl 0:67debf2ccbc2 34 #include "C12832A1Z.h"
dmwahl 0:67debf2ccbc2 35 #include "Small_7.h"
dmwahl 0:67debf2ccbc2 36 #include "Fonts/ArialR12x14.h"
dmwahl 0:67debf2ccbc2 37
dmwahl 0:67debf2ccbc2 38 C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS
dmwahl 0:67debf2ccbc2 39 // LCD width and height (minus 1)
dmwahl 0:67debf2ccbc2 40 #define lcdWidth 127
dmwahl 0:67debf2ccbc2 41 #define lcdHeight 31
dmwahl 0:67debf2ccbc2 42
dmwahl 0:67debf2ccbc2 43 // ISO/SEV pressure: 10psi, DES: 25-30psi
dmwahl 0:67debf2ccbc2 44 #define pumpSetPointPSI 45
dmwahl 0:67debf2ccbc2 45 #define pumpMinPSI 0
dmwahl 0:67debf2ccbc2 46 #define pumpMaxPSI 85
dmwahl 0:67debf2ccbc2 47 //#define pumpHystPSI 2
dmwahl 0:67debf2ccbc2 48
dmwahl 0:67debf2ccbc2 49 // Gas flow sensor defines
dmwahl 0:67debf2ccbc2 50 #define SFM7033_ADDR 0x40
iwolf32 4:79b23d1fbcd1 51 #define SFM7034_ADDR 0x40
dmwahl 0:67debf2ccbc2 52 // End gas flow sensor defines
dmwahl 0:67debf2ccbc2 53
dmwahl 0:67debf2ccbc2 54 // Liquid pump defines
dmwahl 0:67debf2ccbc2 55 // PID settings
dmwahl 0:67debf2ccbc2 56 #define pumpPIDRate .2 // Pump PID computation interval (seconds)
dmwahl 0:67debf2ccbc2 57 float pumpKp = 4.0;
dmwahl 0:67debf2ccbc2 58 float pumpKi = 1.0;
dmwahl 0:67debf2ccbc2 59 #define pumpKd 0
dmwahl 0:67debf2ccbc2 60
dmwahl 0:67debf2ccbc2 61 #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump
dmwahl 0:67debf2ccbc2 62 #define pumpTachPoles 6 // 6 pulses per revolution
212600191 7:b385e6a3f622 63 #define pumpTachPin PA_10 // Pump tach input (green wire)
iwolf32 4:79b23d1fbcd1 64 #define pumpCtrlPin PB_13 // Pump control (white wire)
dmwahl 0:67debf2ccbc2 65 // End Liquid pump defines
dmwahl 0:67debf2ccbc2 66
iwolf32 4:79b23d1fbcd1 67 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 68 Mutex i2c1_m, i2c2_m, i2c3_m, stdio_m;
dmwahl 0:67debf2ccbc2 69
dmwahl 0:67debf2ccbc2 70 //DigitalOut myled(LED2);
iwolf32 8:962b78253710 71 Serial pc(SERIAL_TX, SERIAL_RX, 115200); // tx, rx, baud
dmwahl 0:67debf2ccbc2 72
dmwahl 0:67debf2ccbc2 73 // an I2C sub-class that provides a constructed default
dmwahl 0:67debf2ccbc2 74 class I2CPreInit : public I2C
dmwahl 0:67debf2ccbc2 75 {
dmwahl 0:67debf2ccbc2 76 public:
dmwahl 0:67debf2ccbc2 77 I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) {
dmwahl 0:67debf2ccbc2 78 frequency(freq);
dmwahl 0:67debf2ccbc2 79 };
dmwahl 0:67debf2ccbc2 80 };
dmwahl 0:67debf2ccbc2 81
dmwahl 0:67debf2ccbc2 82 //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency);
dmwahl 0:67debf2ccbc2 83 I2CPreInit i2c1(PB_9, PB_8, 100000);
iwolf32 4:79b23d1fbcd1 84 I2CPreInit i2c2(PB_3, PB_10, 100000);
iwolf32 4:79b23d1fbcd1 85 I2CPreInit i2c3(PB_4, PA_8, 100000);
dmwahl 0:67debf2ccbc2 86
dmwahl 0:67debf2ccbc2 87 KELLER_PRESSURE pumpPressure(i2c1, 0x40);
dmwahl 0:67debf2ccbc2 88
dmwahl 0:67debf2ccbc2 89 // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit)
dmwahl 0:67debf2ccbc2 90 // calibration field 1: Air, 2: O2, 3: N2O
iwolf32 4:79b23d1fbcd1 91 SF04 mainflow(i2c2, SFM7033_ADDR, 0, 9); // Gas flow sensor (SFM7033)
iwolf32 4:79b23d1fbcd1 92 SF04 loopflow(i2c3, SFM7034_ADDR, 0, 9);
dmwahl 0:67debf2ccbc2 93 // Mbed application shield
iwolf32 4:79b23d1fbcd1 94 //AnalogIn pot1(A0);
dmwahl 0:67debf2ccbc2 95 AnalogIn pot2(A1);
dmwahl 0:67debf2ccbc2 96
dmwahl 0:67debf2ccbc2 97 PwmOut pump(pumpCtrlPin);
212600191 7:b385e6a3f622 98
dmwahl 0:67debf2ccbc2 99 //pump.period(.001);
dmwahl 0:67debf2ccbc2 100
dmwahl 0:67debf2ccbc2 101 PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate);
dmwahl 0:67debf2ccbc2 102
212600191 7:b385e6a3f622 103 InterruptIn pumpTach(pumpTachPin);
212600191 7:b385e6a3f622 104 int pumpTachCounts = 0;
212600191 7:b385e6a3f622 105 float pumpRpm = 0;
dmwahl 0:67debf2ccbc2 106
iwolf32 4:79b23d1fbcd1 107 //PwmOut ledRed(PE_11);
iwolf32 4:79b23d1fbcd1 108 //PwmOut ledGrn(PD_15);
iwolf32 4:79b23d1fbcd1 109 //DigitalOut ledBlu(PF_12);
dmwahl 1:d58df8cb271d 110
dmwahl 1:d58df8cb271d 111 // Level sensor
iwolf32 4:79b23d1fbcd1 112 //VL6180 level(i2c1); //I2C object
iwolf32 4:79b23d1fbcd1 113 //float agentlevel = 0;
212600191 7:b385e6a3f622 114 Ticker pump_tach_ticker, pump_pid_ticker, print_process_values_ticker, lcd_update_ticker;
dmwahl 0:67debf2ccbc2 115 #endif