Pump Progress so far

Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of TestBenchSerenity-proto_F429ZI1 by jack kemnitz

Files at this revision

API Documentation at this revision

Comitter:
iwolf32
Date:
Thu Aug 31 14:10:02 2017 +0000
Parent:
7:b385e6a3f622
Commit message:
Pump Progress so far

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 b385e6a3f622 -r 962b78253710 main.cpp
--- a/main.cpp	Thu Aug 03 19:07:43 2017 +0000
+++ b/main.cpp	Thu Aug 31 14:10:02 2017 +0000
@@ -1,69 +1,56 @@
 #include "main.h"
 //---------------------------
-void dutycycleincrease()
-{
+
+EventQueue queue;
+
+void dutycycleincrease(){
     dutycycle=dutycycle+0.01;
 }
 
-void dutycycledecrease()
-{
+void dutycycledecrease(){
     dutycycle=dutycycle-0.01;
 }
 
-void frequencyincrease()
-{
+void frequencyincrease(){
     frequency=frequency+1;
 }
-void frequencydecrease()
-{
+
+void frequencydecrease(){
     frequency=frequency-1;
 }
+
 void injectorvalvecontrol(){
-
-while(true){
-float openvalue=(((1/frequency)*dutycycle));
-float offvalue=(1/frequency)-openvalue;
-    
-injector.on();
-wait(openvalue);
-injector.off();
-wait(offvalue);
-}
+    while(true) {
+        float openvalue=(((1/frequency)*dutycycle));
+        float offvalue=(1/frequency)-openvalue;
+        injector.on();
+        wait(openvalue);
+        injector.off();
+        wait(offvalue);
+    }
 }
 
 //-----------------------------
-void pumpTachTrigger()
-{
-    
+void pumpTachTrigger(){
     pumpTachCounts++;
 }
 
-void pump_tach_update()
-{
+void pump_tach_update(){
     float i = pumpTachCounts; // In case it triggers mid-calculation
     pumpTachCounts=0;
     pumpRpm = (i/pumpTachPoles)*60;
 }
 
-void pump_init()
-{
+void pump_init(){
     pump.period(.001); // 1kHz PWM
     pump = 0;
-    
-    
-    //ledGrn.period(.001);
-
-    
-    
-
     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);
     pump_control_PID.setSetPoint(((double)pot2)*pumpMaxPSI); // pump setpoint based on pot 2*/
 }
 
-void pump_pid_update(char error)
-{
+void pump_pid_update(char error){
     if (pumpPressure.status != 0x40) {
         pump = 0;
         pump_control_PID.reset();
@@ -74,13 +61,10 @@
         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()
-{
+void update_pressures(){
     Timer timer;
     timer.start();
     char error;
@@ -96,98 +80,63 @@
     }
 }
 
-/*void update_flow1()
-{
-    Timer timer;
-    timer.start();
-    char error;
-    while (true) {
-        i2c2_m.lock();
-        timer.reset();
-        error = mainflow.Measure(FLOW);
-        int wait = (200 - timer.read_ms());
-        i2c2_m.unlock();
-        Thread::wait(wait);
-    }
-}
-
-//------------------------------------------------
-void update_flow2()
-{
-    Timer timer;
-    timer.start();
-    char error;
-    while (true) {
-        i2c3_m.lock();
-        timer.reset();
-        error = loopflow.Measure(FLOW);
-        int wait = (200 - timer.read_ms());
-        i2c3_m.unlock();
-        Thread::wait(wait);
-    }
-}*/
-//------------------------------------------------   
-
 void print_process_values()
 {
-    //Thread::wait(100); // Wait initially to allow sensors to update, prevents a zero reading from going to serial
+    Thread::wait(100); // Wait initially to allow sensors to update, prevents a zero reading from going to serial
     Timer timer;
     timer.start();
     while (true) {
         stdio_m.lock();
         timer.reset();
-
-        pc.printf(" %.02fprespsi %.01fsetpsi %.0fRPM %.02fHz %.02f\r\n",
-                   pumpPressure.pressurePSI, ((double)pot2-.002)*pumpMaxPSI, pumpRpm,
-                  frequency, dutycycle);//, agentlevel;
-        int wait = (1000 - timer.read_ms());
-
+        pc.printf(" %.02f\t %.01f\t %.0f\t %.02f\t %i\t %.02f\r\n",
+                  pumpPressure.pressurePSI, ((double)pot2-.002)*pumpMaxPSI, pumpRpm,
+                  frequency, x, dutycycle);//, agentlevel;
+        int wait = (100 - timer.read_ms());
         stdio_m.unlock();
         Thread::wait(wait);
     }
 }
 
+
+void dutycycleint()
+{
+stdio_m.lock();
+pc.printf("Hello");
+x=x+1;
+stdio_m.unlock();
+    return;
+    }
+
 // 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");
-//--------------------------------------------
-dutycycleup.rise(&dutycycleincrease);
-dutycycledown.rise(&dutycycledecrease);
-frequencyup.rise(&frequencyincrease);
-frequencydown.rise(&frequencydecrease);
-pumpTach.rise(&pumpTachTrigger); 
-pump_tach_ticker.attach(&pump_tach_update, 1.0);  
+    dutycycleup.rise(&dutycycleincrease);
+    dutycycledown.rise(&dutycycledecrease);
+    frequencyup.rise(&frequencyincrease);
+    frequencydown.rise(&frequencydecrease);
+    pumpTach.rise(&pumpTachTrigger);
+    pump_tach_ticker.attach(&pump_tach_update, 1.0);
+    
+    //Interrupt for Duty Cycle
+    Thread eventThread;
+    eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
+    pc.attach(&dutycycleint);
 
     //Thread to execute injector valve control
     Injector_Valve_Control.set_priority(osPriorityHigh);
     Injector_Valve_Control.start(injectorvalvecontrol);
-//--------------------------------------------
 
     // 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);
+    update_pressures_t.start(update_pressures);
 
     // 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.set_priority(osPriorityLow);
+    //print_process_values_t.start(&print_process_values);
     
-    
+    while(1){}
+}
 
 
-         
-        
-    
-}
-
diff -r b385e6a3f622 -r 962b78253710 main.h
--- a/main.h	Thu Aug 03 19:07:43 2017 +0000
+++ b/main.h	Thu Aug 31 14:10:02 2017 +0000
@@ -23,6 +23,8 @@
 double dutycycle=0.75;
 float openvalue=(((1/frequency)*dutycycle));
 float offvalue=(1/frequency)-openvalue;
+int x=0;
+char ch;
 
 /*
 --------------------------------------------------------------------------------------------------*/
@@ -66,7 +68,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