Bradley Kohler
/
FRDM_Pacemaker
a pacemaker
Revision 3:334300ac49e5, committed 2016-10-26
- Comitter:
- kohlerba
- Date:
- Wed Oct 26 18:20:43 2016 +0000
- Parent:
- 2:ab8469051a2d
- Commit message:
- Changed the functions and modules.;
Changed in this revision
--- a/clock.cpp Wed Oct 26 14:04:14 2016 +0000 +++ b/clock.cpp Wed Oct 26 18:20:43 2016 +0000 @@ -1,17 +1,89 @@ #include "clock.h" -Ticker tick; +Ticker counter_ticker; +Ticker toggle_ticker; + double counter = 0; +int atrial_logic = 0; +double atrial_counter = 0; +double atrial_pulse_start_time = 0; +int ventricle_logic = 0; +double ventricle_counter = 0; +double ventricle_pulse_start_time = 0; +int toggle_switch = 0; int start_clock(void){ - tick.attach(&count_time, 0.0001); + counter_ticker.attach(&increment_counter, 0.0001); + return 1; + } + +int start_toggler(double switch_time){ + toggle_ticker.attach(&toggler, switch_time); return 1; } -void count_time(void){ +void increment_counter(void){ counter += 0.0001; + + //records time at the rising edge of an atrial pulse (most recent only) + if ((atrial_logic != 0) && (atrial_counter == 0)){ + atrial_pulse_start_time = get_time(); + } + + if (atrial_logic != 0){ + atrial_counter += 0.0001; + } + else { + atrial_counter = 0; + } + + //records time at the rising edge of a ventricle pulse (most recent only) + if ((ventricle_logic != 0) && (ventricle_counter == 0)){ + ventricle_pulse_start_time = get_time(); + } + + if (ventricle_logic != 0){ + ventricle_counter += 0.0001; + } + + else { + ventricle_counter = 0; + } + } + +void toggler(void){ + if(!toggle_switch){ + toggle_switch = 1;} + else{ + toggle_switch = 0;} } double get_time(void){ return counter; } + +int get_atrial_logic(void){ + return atrial_logic; + } + +int set_atrial_logic(int logic){ + atrial_logic = logic; + return 1; + } + +int get_ventricle_logic(void){ + return ventricle_logic; + } + +int set_ventricle_logic(int logic){ + ventricle_logic = logic; + return 1; + } + +double get_ventricle_counter(void){ + return ventricle_counter; + } + +double get_atrial_counter(void){ + return atrial_counter; + }
--- a/clock.h Wed Oct 26 14:04:14 2016 +0000 +++ b/clock.h Wed Oct 26 18:20:43 2016 +0000 @@ -1,10 +1,28 @@ #include "mbed.h" -//Starts the clock +//A ticker that calls the function toggler at a scheduled time length int start_clock(void); +//A ticker that calls the function toggler at a scheduled time length +int start_toggler(double switch_time); + //A counter that updates to the current time -void count_time(void); +void increment_counter(void); + +//Updates the varible toggle_switch +void toggler(void); //Returns the clock time double get_time(void); + +int get_atrial_logic(void); + +int get_ventricle_logic(void); + +int set_atrial_logic(int logic); + +int set_ventricle_logic(int logic); + +double get_atrial_counter(void); + +double get_ventricle_counter(void); \ No newline at end of file
--- a/main.cpp Wed Oct 26 14:04:14 2016 +0000 +++ b/main.cpp Wed Oct 26 18:20:43 2016 +0000 @@ -8,18 +8,23 @@ ledb = 0; pc.printf("connecting..."); pc.printf("\n\n"); + start_clock(); wait(3); ledb = 1; wait(1); - start_clock(); while (true) { - pc.printf("%d" , get_time()); + pc.printf("%2.4f" , get_time()); pc.printf("\n"); - ledg = 0; - v_pace_sq(5 , 0.08); - ledg = 1; - pc.printf("%d" , get_time()); - pc.printf("\n"); + set_ventricle_logic(1); + while (true){ + v_pace_sq(34.2 , 0.08); + ledg = 0; + if (get_ventricle_logic() == 0){ + ledg = 1; + break; + } + wait(0.01); + } wait(0.92); } } \ No newline at end of file
--- a/pacing.cpp Wed Oct 26 14:04:14 2016 +0000 +++ b/pacing.cpp Wed Oct 26 18:20:43 2016 +0000 @@ -1,5 +1,13 @@ #include "pacing.h" +PinName atrial_pin; +PinName ventricle_pin; + +void assign_pins(PinName pin_a , PinName pin_v){ + atrial_pin = pin_a; + ventricle_pin = pin_v; + } + void write_to_pin(PinName pin , int to_write){ DigitalOut(pin , to_write); }
--- a/v_pacing.cpp Wed Oct 26 14:04:14 2016 +0000 +++ b/v_pacing.cpp Wed Oct 26 18:20:43 2016 +0000 @@ -12,11 +12,11 @@ } int v_pace_sq(double amp , double pulse_width){ - assert (get_time() != 0); - double clock_freeze = get_time(); - while((get_time() - clock_freeze) < pulse_width){ - set_v_pace(amp); - } - v_pace = 0; - return 1; + if (get_ventricle_counter() > pulse_width){ + set_ventricle_logic(0); + } + else{ + v_pace = amp; + } + return 0; }