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 VL6180
Fork of TestBenchSerenity-proto_F429ZI by
main.h
00001 #ifndef MAIN_H 00002 #define MAIN_H 00003 00004 #include "mbed.h" 00005 #include "keller_pressure.h" 00006 #include "sensirion_sf04.h" 00007 #include "PID.h" 00008 #include "coil-driver.h" 00009 #include "VL6180.h" 00010 /*Start of Where Additional Code was Added 00011 --------------------------------------------------------------------------------------------------*/ 00012 //Coil shutoff(A1, 5000, 40, 6); // Shutoff valve, 5ms spike time, 25kHz PWM at 15% duty cycle 00013 Coil injector(A0, 200, 40, 3); // Injector valve, 200us spike time, 25kHz PWM at 7.5% duty cycle 00014 00015 InterruptIn dutycycleup(A2); 00016 InterruptIn dutycycledown(D4); 00017 InterruptIn frequencyup(A5); 00018 InterruptIn frequencydown(A4); 00019 00020 Thread Injector_Valve_Control; 00021 00022 double frequency=5.00; 00023 double dutycycle=0.75; 00024 float openvalue=(((1/frequency)*dutycycle)); 00025 float offvalue=(1/frequency)-openvalue; 00026 00027 /* 00028 --------------------------------------------------------------------------------------------------*/ 00029 00030 00031 // Mbed application shield display 00032 #include "C12832A1Z.h" 00033 #include "Small_7.h" 00034 #include "Fonts/ArialR12x14.h" 00035 00036 C12832A1Z lcd(D11, D13, D12, D7, D10); // MOSI, SCK, Reset, A0, CS 00037 // LCD width and height (minus 1) 00038 #define lcdWidth 127 00039 #define lcdHeight 31 00040 00041 // ISO/SEV pressure: 10psi, DES: 25-30psi 00042 #define pumpSetPointPSI 45 00043 #define pumpMinPSI 0 00044 #define pumpMaxPSI 85 00045 //#define pumpHystPSI 2 00046 00047 // Gas flow sensor defines 00048 #define SFM7033_ADDR 0x40 00049 #define SFM7034_ADDR 0x40 00050 // End gas flow sensor defines 00051 00052 // Liquid pump defines 00053 // PID settings 00054 #define pumpPIDRate .2 // Pump PID computation interval (seconds) 00055 float pumpKp = 4.0; 00056 float pumpKi = 1.0; 00057 #define pumpKd 0 00058 00059 #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump 00060 #define pumpTachPoles 6 // 6 pulses per revolution 00061 #define pumpTachPin PA_10 // Pump tach input (green wire) 00062 #define pumpCtrlPin PB_13 // Pump control (white wire) 00063 // End Liquid pump defines 00064 00065 Thread print_process_values_t, update_pressures_t, update_flow1_t, update_flow2_t, update_level_t, update_lcd_t, update_shutoff_t; 00066 Mutex i2c1_m, i2c2_m, i2c3_m, stdio_m; 00067 00068 //DigitalOut myled(LED2); 00069 Serial pc(SERIAL_TX, SERIAL_RX, 250000); // tx, rx, baud 00070 00071 // an I2C sub-class that provides a constructed default 00072 class I2CPreInit : public I2C 00073 { 00074 public: 00075 I2CPreInit(PinName sda, PinName scl, int freq) : I2C(sda, scl) { 00076 frequency(freq); 00077 }; 00078 }; 00079 00080 //I2CPreInit gI2C1(I2C_SDA, I2C_SCL, I2C frequency); 00081 I2CPreInit i2c1(PB_9, PB_8, 100000); 00082 I2CPreInit i2c2(PB_3, PB_10, 100000); 00083 I2CPreInit i2c3(PB_4, PA_8, 100000); 00084 00085 KELLER_PRESSURE pumpPressure(i2c1, 0x40); 00086 00087 // Sensirion gas flow sensor object (i2c object, i2c address, calibration field, resolution 9-16 bit) 00088 // calibration field 1: Air, 2: O2, 3: N2O 00089 SF04 mainflow(i2c2, SFM7033_ADDR, 0, 9); // Gas flow sensor (SFM7033) 00090 SF04 loopflow(i2c3, SFM7034_ADDR, 0, 9); 00091 // Mbed application shield 00092 //AnalogIn pot1(A0); 00093 AnalogIn pot2(A1); 00094 00095 PwmOut pump(pumpCtrlPin); 00096 00097 //pump.period(.001); 00098 00099 PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate); 00100 00101 InterruptIn pumpTach(pumpTachPin); 00102 int pumpTachCounts = 0; 00103 float pumpRpm = 0; 00104 00105 //PwmOut ledRed(PE_11); 00106 //PwmOut ledGrn(PD_15); 00107 //DigitalOut ledBlu(PF_12); 00108 00109 // Level sensor 00110 //VL6180 level(i2c1); //I2C object 00111 //float agentlevel = 0; 00112 Ticker pump_tach_ticker, pump_pid_ticker, print_process_values_ticker, lcd_update_ticker; 00113 #endif
Generated on Mon Jul 18 2022 04:11:26 by
