Dependencies: KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180
Fork of PUMP_SCRIPT by
Revision 9:20092ef77dab, committed 2017-09-07
- Comitter:
- iwolf32
- Date:
- Thu Sep 07 20:53:17 2017 +0000
- Parent:
- 8:bf86306ce7bf
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r bf86306ce7bf -r 20092ef77dab main.cpp --- a/main.cpp Tue Sep 05 19:27:50 2017 +0000 +++ b/main.cpp Thu Sep 07 20:53:17 2017 +0000 @@ -1,10 +1,6 @@ #include "main.h" -//--------------------------- - -//----------------------------- void pumpTachTrigger() -{ - +{ pumpTachCounts++; } @@ -18,14 +14,7 @@ void pump_init() { pump.period(.001); // 1kHz PWM - pump = 0; - - - //ledGrn.period(.001); - - - - + pump = 0; pump_control_PID.setInputLimits(pumpMinPSI, pumpMaxPSI); pump_control_PID.setOutputLimits(0.0, 1.0); // Output is a PWM signal ranging from 0-1 pump_control_PID.setMode(AUTO_MODE); @@ -39,16 +28,12 @@ pump_control_PID.reset(); } else { pump_control_PID.setSetPoint(((double)pot2)*pumpMaxPSI); - - //Update the process variable. + //Update the process variable. pump_control_PID.setProcessValue(pumpPressure.pressurePSI); //PID calculation and set the new output value. pump = pump_control_PID.compute(); - //pump = 0.1; - //ledGrn = ((float)1.0-pump.read()); } } - void update_pressures() { Timer timer; @@ -58,16 +43,12 @@ i2c1_m.lock(); timer.reset(); error = pumpPressure.readPT(); - //error |= mixerPressure.readPT(); int wait = (200 - timer.read_ms()); i2c1_m.unlock(); Thread::wait(wait); pump_pid_update(error); } } - -//------------------------------------------------ - void print_process_values() { //Thread::wait(100); // Wait initially to allow sensors to update, prevents a zero reading from going to serial @@ -76,51 +57,26 @@ while (true) { stdio_m.lock(); timer.reset(); - - pc.printf(" %.02f\t %.01f\t %.0f\r\n", - pumpPressure.pressurePSI, ((double)pot2-.002)*pumpMaxPSI, pumpRpm); + pc.printf(" %.02f\t %.01f\t %.0f\r\n", pumpPressure.pressurePSI, ((double)pot2-.002)*pumpMaxPSI, pumpRpm); int wait = (1000 - timer.read_ms()); - stdio_m.unlock(); Thread::wait(wait); } } -// main() runs in its own thread in the OS int main() { pump_init(); pump_tach_update(); - //ledBlu = 1; - pc.printf("Serenity Starting up...\n\r"); -//-------------------------------------------- - -pumpTach.rise(&pumpTachTrigger); -pump_tach_ticker.attach(&pump_tach_update, 1.0); - -//-------------------------------------------- + pumpTach.rise(&pumpTachTrigger); + pump_tach_ticker.attach(&pump_tach_update, 1.0); // Thread to poll pressure sensors update_pressures_t.set_priority(osPriorityNormal); update_pressures_t.start(update_pressures); - // Thread to poll flow sensor - //update_flow1_t.set_priority(osPriorityNormal); - //update_flow1_t.start(update_flow1); - - //Thread to poll flow sensor - //update_flow2_t.set_priority(osPriorityNormal); - //update_flow2_t.start(update_flow2); - // Thread to send process values to serial port print_process_values_t.set_priority(osPriorityLow); - print_process_values_t.start(&print_process_values); - + print_process_values_t.start(&print_process_values); - - - - - -} - +} \ No newline at end of file
diff -r bf86306ce7bf -r 20092ef77dab main.h --- a/main.h Tue Sep 05 19:27:50 2017 +0000 +++ b/main.h Thu Sep 07 20:53:17 2017 +0000 @@ -66,7 +66,7 @@ Mutex i2c1_m, i2c2_m, i2c3_m, stdio_m; //DigitalOut myled(LED2); -Serial pc(SERIAL_TX, SERIAL_RX, 250000); // tx, rx, baud +Serial pc(SERIAL_TX, SERIAL_RX, 115200); // tx, rx, baud // an I2C sub-class that provides a constructed default class I2CPreInit : public I2C