rre

Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of TestBenchSerenity-proto_F429ZI by jack kemnitz

Files at this revision

API Documentation at this revision

Comitter:
212600191
Date:
Thu Aug 03 19:07:43 2017 +0000
Parent:
5:f2cb21046678
Commit message:
jfkdd;

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
--- a/main.cpp	Wed Aug 02 21:08:10 2017 +0000
+++ b/main.cpp	Thu Aug 03 19:07:43 2017 +0000
@@ -34,13 +34,14 @@
 //-----------------------------
 void pumpTachTrigger()
 {
+    
     pumpTachCounts++;
 }
 
 void pump_tach_update()
 {
     float i = pumpTachCounts; // In case it triggers mid-calculation
-    pumpTachCounts = 0;
+    pumpTachCounts=0;
     pumpRpm = (i/pumpTachPoles)*60;
 }
 
@@ -48,10 +49,12 @@
 {
     pump.period(.001); // 1kHz PWM
     pump = 0;
+    
+    
     //ledGrn.period(.001);
 
-    InterruptIn pumpTach(pumpTachPin);
-    pumpTach.rise(&pumpTachTrigger);
+    
+    
 
     pump_control_PID.setInputLimits(pumpMinPSI, pumpMaxPSI);
     pump_control_PID.setOutputLimits(0.0, 1.0); // Output is a PWM signal ranging from 0-1
@@ -134,8 +137,8 @@
         stdio_m.lock();
         timer.reset();
 
-        pc.printf(" %.02fprespsi %.01fsetpsi% .02fHz %.02f\r\n",
-                   pumpPressure.pressurePSI, ((double)pot2-.002)*pumpMaxPSI,
+        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());
 
@@ -148,13 +151,16 @@
 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);    
+frequencydown.rise(&frequencydecrease);
+pumpTach.rise(&pumpTachTrigger); 
+pump_tach_ticker.attach(&pump_tach_update, 1.0);  
 
     //Thread to execute injector valve control
     Injector_Valve_Control.set_priority(osPriorityHigh);
@@ -176,10 +182,12 @@
     // Thread to send process values to serial port
     print_process_values_t.set_priority(osPriorityLow);
     print_process_values_t.start(&print_process_values);
+    
+    
 
-    while (true) {
-         pump_tach_update();
+
+         
         
-    }
+    
 }
 
--- a/main.h	Wed Aug 02 21:08:10 2017 +0000
+++ b/main.h	Thu Aug 03 19:07:43 2017 +0000
@@ -58,7 +58,7 @@
 
 #define pumpPwmFrequency 1000 // Frequency of PWM signal supplied to pump
 #define pumpTachPoles 6 // 6 pulses per revolution
-#define pumpTachPin PB_15 // Pump tach input (green wire)
+#define pumpTachPin PA_10 // Pump tach input (green wire)
 #define pumpCtrlPin PB_13 // Pump control (white wire)
 // End Liquid pump defines
 
@@ -66,7 +66,7 @@
 Mutex i2c1_m, i2c2_m, i2c3_m, stdio_m;
 
 //DigitalOut myled(LED2);
-Serial pc(USBTX, USBRX, 250000); // tx, rx, baud
+Serial pc(SERIAL_TX, SERIAL_RX, 250000); // tx, rx, baud
 
 // an I2C sub-class that provides a constructed default
 class I2CPreInit : public I2C
@@ -93,13 +93,14 @@
 AnalogIn pot2(A1);
 
 PwmOut pump(pumpCtrlPin);
+
 //pump.period(.001);
 
 PID pump_control_PID(pumpKp, pumpKi, pumpKd, pumpPIDRate);
 
-//InterruptIn pumpTach(pumpTachPin);
-volatile int pumpTachCounts = 0;
-volatile float pumpRpm = 0;
+InterruptIn pumpTach(pumpTachPin);
+int pumpTachCounts = 0;
+float pumpRpm = 0;
 
 //PwmOut ledRed(PE_11);
 //PwmOut ledGrn(PD_15);
@@ -108,4 +109,5 @@
 // Level sensor
 //VL6180 level(i2c1); //I2C object
 //float agentlevel = 0;
+Ticker pump_tach_ticker, pump_pid_ticker, print_process_values_ticker, lcd_update_ticker;
 #endif
\ No newline at end of file