Pacemaker code Implementation for SFWRENG 3K04
Dependencies: mbed Queue mbed-rtos FXOS8700Q
Fork of Pacemaker by
SWFRENG 3K04 Project to design, develop, and document a functional pacemaker.
The project uses the Freescale K64F Microcontroller and C++ mbed library.
pulse.cpp@32:69cd1390bc21, 2016-12-06 (annotated)
- Committer:
- noahzwiep
- Date:
- Tue Dec 06 20:57:56 2016 +0000
- Revision:
- 32:69cd1390bc21
- Parent:
- 21:fc6c33206152
- Child:
- 33:686a1a0c690f
Updated interface and pulse classes - Noah
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noahzwiep | 32:69cd1390bc21 | 1 | #pragma once |
noahzwiep | 32:69cd1390bc21 | 2 | #include "mbed.h" |
noahzwiep | 32:69cd1390bc21 | 3 | #include "pulse.h" |
noahzwiep | 32:69cd1390bc21 | 4 | |
FiveDollar | 0:b2b3955cd77b | 5 | #pragma once |
FiveDollar | 0:b2b3955cd77b | 6 | #include "mbed.h" |
FiveDollar | 0:b2b3955cd77b | 7 | #include "pulse.h" |
FiveDollar | 0:b2b3955cd77b | 8 | |
noahzwiep | 32:69cd1390bc21 | 9 | pulse::pulse(): |
noahzwiep | 32:69cd1390bc21 | 10 | atrialIn(A0), // Pin A0 |
noahzwiep | 32:69cd1390bc21 | 11 | ventricleIn(A1), // Pin A1 |
noahzwiep | 32:69cd1390bc21 | 12 | leadImpedence(A2), // Pin A2 |
noahzwiep | 32:69cd1390bc21 | 13 | atr_rect_signal(A3), // Pin A3 |
noahzwiep | 32:69cd1390bc21 | 14 | vent_rect_signal(A4), // Pin A4 |
noahzwiep | 32:69cd1390bc21 | 15 | |
noahzwiep | 32:69cd1390bc21 | 16 | /*=== Digital In ===*/ |
noahzwiep | 32:69cd1390bc21 | 17 | atria_cmp_detect(PTC16), // Pin D0 |
noahzwiep | 32:69cd1390bc21 | 18 | vent_cmp_detect(PTC17), // Pin D1 |
noahzwiep | 32:69cd1390bc21 | 19 | |
noahzwiep | 32:69cd1390bc21 | 20 | /*=== PWM Out ===*/ |
noahzwiep | 32:69cd1390bc21 | 21 | /* is used for the REF Signal |
noahzwiep | 32:69cd1390bc21 | 22 | * due to absence of PWM capabilities of Pins D2 and D4 |
noahzwiep | 32:69cd1390bc21 | 23 | * on the FRDM-K64F Board |
noahzwiep | 32:69cd1390bc21 | 24 | */ |
noahzwiep | 32:69cd1390bc21 | 25 | pacing_ref_pwm(PTB9), // Pin D2 (PTB9) |
noahzwiep | 32:69cd1390bc21 | 26 | vent_ref_pwm(PTA1), // Pin D3 |
noahzwiep | 32:69cd1390bc21 | 27 | atria_ref_pwm(PTB23), // Pin D4 |
noahzwiep | 32:69cd1390bc21 | 28 | |
noahzwiep | 32:69cd1390bc21 | 29 | |
noahzwiep | 32:69cd1390bc21 | 30 | /*=== Digital Out ===*/ |
noahzwiep | 32:69cd1390bc21 | 31 | pace_charge_ctrl(PTA2), // Pin D5 |
noahzwiep | 32:69cd1390bc21 | 32 | z_atria_ctrl(PTC2), // Pin D6 |
noahzwiep | 32:69cd1390bc21 | 33 | z_vent_ctrl(PTC3), // Pin D7 |
noahzwiep | 32:69cd1390bc21 | 34 | |
noahzwiep | 32:69cd1390bc21 | 35 | atr_pace_ctrl(PTC12), // Pin D8 |
noahzwiep | 32:69cd1390bc21 | 36 | vent_pace_ctrl(PTC4), // Pin D9 |
noahzwiep | 32:69cd1390bc21 | 37 | pace_grnd_ctrl(PTD0), // Pin D10 |
noahzwiep | 32:69cd1390bc21 | 38 | atr_grnd_ctrl(PTD2), // Pin D11 |
noahzwiep | 32:69cd1390bc21 | 39 | vent_grnd_ctrl(PTD3), // Pin D12 |
noahzwiep | 32:69cd1390bc21 | 40 | frontend_ctrl(PTD1) // Pin D13 |
noahzwiep | 32:69cd1390bc21 | 41 | {} |
FiveDollar | 0:b2b3955cd77b | 42 | |
noahzwiep | 32:69cd1390bc21 | 43 | pulse::pulse(chamberData* chamber, hardware* IOpins):/*=== Analog In ===*/ |
noahzwiep | 32:69cd1390bc21 | 44 | atrialIn(A0), // Pin A0 |
noahzwiep | 32:69cd1390bc21 | 45 | ventricleIn(A1), // Pin A1 |
noahzwiep | 32:69cd1390bc21 | 46 | leadImpedence(A2), // Pin A2 |
noahzwiep | 32:69cd1390bc21 | 47 | atr_rect_signal(A3), // Pin A3 |
noahzwiep | 32:69cd1390bc21 | 48 | vent_rect_signal(A4), // Pin A4 |
noahzwiep | 32:69cd1390bc21 | 49 | |
noahzwiep | 32:69cd1390bc21 | 50 | /*=== Digital In ===*/ |
noahzwiep | 32:69cd1390bc21 | 51 | atria_cmp_detect(PTC16), // Pin D0 |
noahzwiep | 32:69cd1390bc21 | 52 | vent_cmp_detect(PTC17), // Pin D1 |
noahzwiep | 32:69cd1390bc21 | 53 | |
noahzwiep | 32:69cd1390bc21 | 54 | /*=== PWM Out ===*/ |
noahzwiep | 32:69cd1390bc21 | 55 | /* is used for the REF Signal |
noahzwiep | 32:69cd1390bc21 | 56 | * due to absence of PWM capabilities of Pins D2 and D4 |
noahzwiep | 32:69cd1390bc21 | 57 | * on the FRDM-K64F Board |
noahzwiep | 32:69cd1390bc21 | 58 | */ |
noahzwiep | 32:69cd1390bc21 | 59 | pacing_ref_pwm(PTB9), // Pin D2 (PTB9) |
noahzwiep | 32:69cd1390bc21 | 60 | vent_ref_pwm(PTA1), // Pin D3 |
noahzwiep | 32:69cd1390bc21 | 61 | atria_ref_pwm(PTB23), // Pin D4 |
noahzwiep | 32:69cd1390bc21 | 62 | |
noahzwiep | 32:69cd1390bc21 | 63 | |
noahzwiep | 32:69cd1390bc21 | 64 | /*=== Digital Out ===*/ |
noahzwiep | 32:69cd1390bc21 | 65 | pace_charge_ctrl(PTA2), // Pin D5 |
noahzwiep | 32:69cd1390bc21 | 66 | z_atria_ctrl(PTC2), // Pin D6 |
noahzwiep | 32:69cd1390bc21 | 67 | z_vent_ctrl(PTC3), // Pin D7 |
noahzwiep | 32:69cd1390bc21 | 68 | |
noahzwiep | 32:69cd1390bc21 | 69 | atr_pace_ctrl(PTC12), // Pin D8 |
noahzwiep | 32:69cd1390bc21 | 70 | vent_pace_ctrl(PTC4), // Pin D9 |
noahzwiep | 32:69cd1390bc21 | 71 | pace_grnd_ctrl(PTD0), // Pin D10 |
noahzwiep | 32:69cd1390bc21 | 72 | atr_grnd_ctrl(PTD2), // Pin D11 |
noahzwiep | 32:69cd1390bc21 | 73 | vent_grnd_ctrl(PTD3), // Pin D12 |
noahzwiep | 32:69cd1390bc21 | 74 | frontend_ctrl(PTD1) // Pin D13 |
noahzwiep | 32:69cd1390bc21 | 75 | { |
FiveDollar | 0:b2b3955cd77b | 76 | myIOpins = IOpins; |
FiveDollar | 0:b2b3955cd77b | 77 | myChamber = chamber; |
FiveDollar | 2:fbba2687ddfe | 78 | // myPaceWidth = 0; //mSec, width of ventricular pace |
FiveDollar | 0:b2b3955cd77b | 79 | // myPaceAmp = 0; //mV, amplitude of ventricular pace |
FiveDollar | 0:b2b3955cd77b | 80 | // myRP = 0; //mSec, duration of refractory period |
FiveDollar | 0:b2b3955cd77b | 81 | // p_hysteresisInterval = 0; |
FiveDollar | 0:b2b3955cd77b | 82 | // p_lowrateInterval = 0; |
FiveDollar | 0:b2b3955cd77b | 83 | // p_hysteresis = false; |
FiveDollar | 0:b2b3955cd77b | 84 | |
FiveDollar | 0:b2b3955cd77b | 85 | } |
FiveDollar | 0:b2b3955cd77b | 86 | |
FiveDollar | 0:b2b3955cd77b | 87 | pulse::~pulse(){ |
FiveDollar | 0:b2b3955cd77b | 88 | delete myChamber; |
FiveDollar | 0:b2b3955cd77b | 89 | delete myIOpins; |
FiveDollar | 0:b2b3955cd77b | 90 | delete pc; |
FiveDollar | 0:b2b3955cd77b | 91 | delete aOut; |
FiveDollar | 0:b2b3955cd77b | 92 | } |
FiveDollar | 0:b2b3955cd77b | 93 | |
trane3 | 21:fc6c33206152 | 94 | //void pulse::setChamber(chamberData* c){ |
trane3 | 21:fc6c33206152 | 95 | // myChamber = c; |
trane3 | 21:fc6c33206152 | 96 | // } |
trane3 | 8:75c1dd8b0d61 | 97 | |
noahzwiep | 32:69cd1390bc21 | 98 | void pulse::pace_charge_shutdown() { |
noahzwiep | 32:69cd1390bc21 | 99 | /* Stage 1: Switch-OFF/Ground-ON */ |
noahzwiep | 32:69cd1390bc21 | 100 | atr_pace_ctrl.write(0); |
noahzwiep | 32:69cd1390bc21 | 101 | vent_pace_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 102 | atr_grnd_ctrl .write(1);; |
noahzwiep | 32:69cd1390bc21 | 103 | vent_grnd_ctrl.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 104 | wait_ms(50); |
noahzwiep | 32:69cd1390bc21 | 105 | |
noahzwiep | 32:69cd1390bc21 | 106 | |
noahzwiep | 32:69cd1390bc21 | 107 | /* Stage 2: Ref PWM LOW */ |
noahzwiep | 32:69cd1390bc21 | 108 | pacing_ref_pwm.write(0);; |
noahzwiep | 32:69cd1390bc21 | 109 | wait_ms(100); |
noahzwiep | 32:69cd1390bc21 | 110 | |
noahzwiep | 32:69cd1390bc21 | 111 | /* Stage 3: Charge CTRL off */ |
noahzwiep | 32:69cd1390bc21 | 112 | pace_charge_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 113 | wait_ms(10); |
noahzwiep | 32:69cd1390bc21 | 114 | |
noahzwiep | 32:69cd1390bc21 | 115 | /* Stage 4: Ground OFF */ |
noahzwiep | 32:69cd1390bc21 | 116 | atr_grnd_ctrl .write(0);; |
noahzwiep | 32:69cd1390bc21 | 117 | vent_grnd_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 118 | } |
noahzwiep | 32:69cd1390bc21 | 119 | |
noahzwiep | 32:69cd1390bc21 | 120 | void pulse::vent_pace_prime() { |
noahzwiep | 32:69cd1390bc21 | 121 | /* Redundant code to close ground switches, |
noahzwiep | 32:69cd1390bc21 | 122 | * prevents accidentally shorting the pacemaker |
noahzwiep | 32:69cd1390bc21 | 123 | */ |
noahzwiep | 32:69cd1390bc21 | 124 | atr_grnd_ctrl .write(0);; |
noahzwiep | 32:69cd1390bc21 | 125 | vent_grnd_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 126 | |
noahzwiep | 32:69cd1390bc21 | 127 | /* Stage 1: Ref PWM On */ |
noahzwiep | 32:69cd1390bc21 | 128 | pacing_ref_pwm.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 129 | wait_ms(10); |
noahzwiep | 32:69cd1390bc21 | 130 | |
noahzwiep | 32:69cd1390bc21 | 131 | /* Stage 2: Charge CTRL on */ |
noahzwiep | 32:69cd1390bc21 | 132 | pace_charge_ctrl.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 133 | wait_ms(10); |
noahzwiep | 32:69cd1390bc21 | 134 | } |
noahzwiep | 32:69cd1390bc21 | 135 | |
noahzwiep | 32:69cd1390bc21 | 136 | void pulse::atr_pace_prime() { |
noahzwiep | 32:69cd1390bc21 | 137 | /* Redundant code to close ground switches, |
noahzwiep | 32:69cd1390bc21 | 138 | * prevents accidentally shorting the pacemaker |
noahzwiep | 32:69cd1390bc21 | 139 | */ |
noahzwiep | 32:69cd1390bc21 | 140 | atr_grnd_ctrl .write(0);; |
noahzwiep | 32:69cd1390bc21 | 141 | vent_grnd_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 142 | |
noahzwiep | 32:69cd1390bc21 | 143 | /* Stage 4: Ref PWM On */ |
noahzwiep | 32:69cd1390bc21 | 144 | pacing_ref_pwm.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 145 | wait_ms(10); |
noahzwiep | 32:69cd1390bc21 | 146 | |
noahzwiep | 32:69cd1390bc21 | 147 | /* Stage 5: Charge CTRL on */ |
noahzwiep | 32:69cd1390bc21 | 148 | pace_charge_ctrl.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 149 | wait_ms(10); |
noahzwiep | 32:69cd1390bc21 | 150 | } |
noahzwiep | 32:69cd1390bc21 | 151 | |
noahzwiep | 32:69cd1390bc21 | 152 | void pulse::pace_vent(double pulse_width_us) { |
noahzwiep | 32:69cd1390bc21 | 153 | vent_pace_prime(); |
noahzwiep | 32:69cd1390bc21 | 154 | |
noahzwiep | 32:69cd1390bc21 | 155 | // Begin Pace Event Output |
noahzwiep | 32:69cd1390bc21 | 156 | vent_pace_ctrl.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 157 | |
noahzwiep | 32:69cd1390bc21 | 158 | // Pace Duration |
noahzwiep | 32:69cd1390bc21 | 159 | wait(pulse_width_us); |
noahzwiep | 32:69cd1390bc21 | 160 | |
noahzwiep | 32:69cd1390bc21 | 161 | // Shut off Pace |
noahzwiep | 32:69cd1390bc21 | 162 | vent_pace_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 163 | |
noahzwiep | 32:69cd1390bc21 | 164 | pace_charge_shutdown (); |
noahzwiep | 32:69cd1390bc21 | 165 | } |
noahzwiep | 32:69cd1390bc21 | 166 | |
noahzwiep | 32:69cd1390bc21 | 167 | void pulse::pace_atr(double pulse_width_us) { |
noahzwiep | 32:69cd1390bc21 | 168 | atr_pace_prime(); |
noahzwiep | 32:69cd1390bc21 | 169 | |
noahzwiep | 32:69cd1390bc21 | 170 | // Begin Pace Event Output |
noahzwiep | 32:69cd1390bc21 | 171 | atr_pace_ctrl.write(myChamber->getPaceAmp());; |
noahzwiep | 32:69cd1390bc21 | 172 | |
noahzwiep | 32:69cd1390bc21 | 173 | // Pace Duration |
noahzwiep | 32:69cd1390bc21 | 174 | wait(pulse_width_us); |
noahzwiep | 32:69cd1390bc21 | 175 | |
noahzwiep | 32:69cd1390bc21 | 176 | // Shut off Pace |
noahzwiep | 32:69cd1390bc21 | 177 | atr_pace_ctrl.write(0);; |
noahzwiep | 32:69cd1390bc21 | 178 | |
noahzwiep | 32:69cd1390bc21 | 179 | pace_charge_shutdown (); |
noahzwiep | 32:69cd1390bc21 | 180 | } |
noahzwiep | 32:69cd1390bc21 | 181 | |
FiveDollar | 0:b2b3955cd77b | 182 | |
FiveDollar | 0:b2b3955cd77b | 183 | void pulse::startPulse(){ |
noahzwiep | 32:69cd1390bc21 | 184 | pulse::pace_charge_shutdown(); |
noahzwiep | 32:69cd1390bc21 | 185 | char a = myChamber->getChamberType(); |
noahzwiep | 32:69cd1390bc21 | 186 | if(a = 'a'){ |
noahzwiep | 32:69cd1390bc21 | 187 | pulse::pace_vent(myChamber->getPaceWidth()); |
noahzwiep | 32:69cd1390bc21 | 188 | } |
noahzwiep | 32:69cd1390bc21 | 189 | else{ |
noahzwiep | 32:69cd1390bc21 | 190 | pulse::pace_vent(myChamber->getPaceWidth()); |
noahzwiep | 32:69cd1390bc21 | 191 | |
FiveDollar | 0:b2b3955cd77b | 192 | } |
FiveDollar | 0:b2b3955cd77b | 193 |