Pacemaker code Implementation for SFWRENG 3K04

Dependencies:   mbed Queue mbed-rtos FXOS8700Q

Fork of Pacemaker by Eric dollar

SWFRENG 3K04 Project to design, develop, and document a functional pacemaker.

The project uses the Freescale K64F Microcontroller and C++ mbed library.

Files at this revision

API Documentation at this revision

Comitter:
noahzwiep
Date:
Sun Dec 18 02:29:59 2016 +0000
Parent:
35:fa164704f0ca
Commit message:
All ogre.

Changed in this revision

VVI.cpp Show annotated file Show diff for this revision Revisions of this file
interface.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
motion.cpp Show annotated file Show diff for this revision Revisions of this file
pulse.cpp Show annotated file Show diff for this revision Revisions of this file
pulse.h Show annotated file Show diff for this revision Revisions of this file
sense.cpp Show annotated file Show diff for this revision Revisions of this file
sense.h Show annotated file Show diff for this revision Revisions of this file
--- a/VVI.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/VVI.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -7,7 +7,6 @@
 #include "VVI.h"
 #include "sense.h"
 
-
 DigitalOut green(LED_GREEN);
 
 pulse* chamberPulse;
--- a/interface.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/interface.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -145,8 +145,7 @@
                             double myInt = (myDataStruct->getData());
                             pc->printf("%f\n", myInt);
                             pc->printf("%c\n", atrData->getMarker());
-                            //rled = !rled; 
-                            Thread::wait(4);
+                            wait_ms(4);
                         }
                         break;
                     }
--- a/main.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/main.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -19,17 +19,16 @@
     pulse* atrPulse = new pulse(atrium,io);
     sense* isSense = new sense(generalData);
     
-//    Thread motionThread(osPriorityNormal);
-//    initialize_motion ();
-//    motion_set_chamber(0, ventricle);
-//    motionThread.start(motion_thread);
     
     Thread vviThread(osPriorityNormal);
     vvi_set_chamber(atrPulse,atrium,isSense);
     vviThread.start(start_VVI);
     
-//    Thread egramThread(osPriorityNormal);
-//    egramThread.start(storeData);
+    Thread motionThread(osPriorityBelowNormal);
+    initialize_motion ();
+    motion_set_chamber(0, ventricle);
+    motionThread.start(motion_thread);
+
     
     interface a(io->getSerial() , ventPulse , generalData, atrium , ventricle,io); 
     
--- a/motion.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/motion.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -12,6 +12,7 @@
 
 /* Constants and Declares */
 int numCount;
+int numCount2;
 chamberData* ventChamber;
 chamberData* atrChamber;
 int const MAX_NUM_COUNTS = 3;
@@ -52,24 +53,26 @@
 
     if (numCount >= MAX_NUM_COUNTS) {
         ventChamber->chngPaceWidth(ventChamber->getPaceWidth() - 0.01);
-        //red = !red;   // toggle LEDs to show acceleration threshold reached
+        numCount = 0;
+ //       red = !red;   // toggle LEDs to show acceleration threshold reached
         
         motion_exceeded_threshold = 1;
     }
 }
 
 void b_count(){
-    numCount++;
+    numCount2++;
     
-    if (numCount >= MIN_NUM_COUNTS){
+    if (numCount2 >= MIN_NUM_COUNTS){
         ventChamber->chngPaceWidth(ventChamber->getPaceWidth() + 0.01);
-        //red = !red;
+        numCount2 = 0;
+  //      red = !red;
     }
 }
 
 void motion_thread () {
     while(true) {
-
+  //      red = !red;
         float xAcc, yAcc, zAcc;
         acc.getX(&xAcc);
         acc.getY(&yAcc);
@@ -80,7 +83,7 @@
             a_count();      // increment acceleration event counter
         }
 
-        if (magtd < 1.0f){
+        if (magtd < 1.5f){
             b_count();
         Thread::wait(TIMING_PERIOD); 
         }
--- a/pulse.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/pulse.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -1,6 +1,7 @@
 #pragma once
 #include "mbed.h"
 #include "pulse.h"
+#include "rtos.h"
 
 #pragma once
 #include "mbed.h"
@@ -22,8 +23,8 @@
  * due to absence of PWM capabilities of Pins D2 and D4
  * on the FRDM-K64F Board
  */
- pacing_ref_pwm(PTB9),    // Pin D2 (PTB9)
- vent_ref_pwm(PTA1),    // Pin D3
+ pacing_ref_pwm(PTA1),    // Pin D2 (PTB9)
+ vent_ref_pwm(PTB9),    // Pin D3
  atria_ref_pwm(PTB23),   // Pin D4
 
 
@@ -56,8 +57,8 @@
  * due to absence of PWM capabilities of Pins D2 and D4
  * on the FRDM-K64F Board
  */
- pacing_ref_pwm(PTB9),    // Pin D2 (PTB9)
- vent_ref_pwm(PTA1),    // Pin D3
+ pacing_ref_pwm(PTA1),    // Pin D2 (PTB9)
+ vent_ref_pwm(PTB9),    // Pin D3
  atria_ref_pwm(PTB23),   // Pin D4
 
 
@@ -101,16 +102,16 @@
     vent_pace_ctrl.write(0);
     atr_grnd_ctrl .write(1);
     vent_grnd_ctrl.write(1);
-    wait_ms(50);
+    Thread::wait(50);
     
 
     /* Stage 2: Ref PWM LOW */
     pacing_ref_pwm.write(0);
-    wait_ms(100);
+    Thread::wait(100);
 
     /* Stage 3: Charge CTRL off */
     pace_charge_ctrl.write(0);
-    wait_ms(10);
+    Thread::wait(10);
     
     /* Stage 4: Ground OFF */
     atr_grnd_ctrl.write(0);
@@ -126,11 +127,11 @@
     
     /* Stage 1: Ref PWM On */
     pacing_ref_pwm.write(myChamber->getPaceAmp());
-    wait_ms(10);
+    Thread::wait(10);
 
     /* Stage 2: Charge CTRL on */
     pace_charge_ctrl.write(1);
-    wait_ms(10);
+    Thread::wait(10);
 }
 
 void pulse::atr_pace_prime() {
@@ -142,11 +143,11 @@
     
     /* Stage 4: Ref PWM On */
     pacing_ref_pwm.write(myChamber->getPaceAmp());
-    wait_ms(10);
+    Thread::wait(10);
 
     /* Stage 5: Charge CTRL on */
     pace_charge_ctrl.write(1);
-    wait_ms(10);
+    Thread::wait(10);
 }
 
 void pulse::pace_vent(double pulse_width_us) {
--- a/pulse.h	Tue Dec 13 04:34:36 2016 +0000
+++ b/pulse.h	Sun Dec 18 02:29:59 2016 +0000
@@ -43,8 +43,8 @@
      * due to absence of PWM capabilities of Pins D2 and D4
      * on the FRDM-K64F Board
      */
-    DigitalOut pacing_ref_pwm;    // Pin D2 (PTB9)
-    PwmOut vent_ref_pwm;    // Pin D3
+    PwmOut pacing_ref_pwm;    // Pin D2 (PTB9)
+    DigitalOut vent_ref_pwm;    // Pin D3
     DigitalOut atria_ref_pwm;   // Pin D4
     
     
--- a/sense.cpp	Tue Dec 13 04:34:36 2016 +0000
+++ b/sense.cpp	Sun Dec 18 02:29:59 2016 +0000
@@ -3,7 +3,7 @@
 #include "sense.h"
 #include "VVI.h"
 
-sense::sense(genData* a){
+sense::sense(genData* a): mySense(PTB2){
     myGenData = a; 
     isSensed = false; 
     }
@@ -12,6 +12,7 @@
 
 bool sense::returnedSense(){
     timeout = false;
+    isSensed = false;
     mbed::Timer t;
     t.start();
     while(!timeout){
@@ -27,10 +28,10 @@
             }
         }
         //Here we have to check the pin and see if it is above threshold. 
-/*        if(PINNAME.read() == 1){
+        if(mySense.read() > 0.995){
             isSensed = true;
             timeout = true;
-        }*/
+        }
     }
     t.stop();
     return isSensed; 
--- a/sense.h	Tue Dec 13 04:34:36 2016 +0000
+++ b/sense.h	Sun Dec 18 02:29:59 2016 +0000
@@ -14,4 +14,5 @@
         bool isSensed;
         bool timeout;
         genData* myGenData; 
+        AnalogIn mySense;
 };
\ No newline at end of file