reeeeeeeeeeeeeee
Dependencies: MotionSensor mbed
Fork of Assignment2_ver3 by
Hardware.cpp@7:6dc42e1a2a81, 2016-11-29 (annotated)
- Committer:
- weebgrammers
- Date:
- Tue Nov 29 20:21:45 2016 +0000
- Revision:
- 7:6dc42e1a2a81
- Parent:
- 4:f0a11480f39f
- Child:
- 8:45befd2bb1e5
s
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oopakhooo | 3:641eefd1110b | 1 | #include "Hardware.h" |
oopakhooo | 3:641eefd1110b | 2 | #include "mbed.h" |
oopakhooo | 3:641eefd1110b | 3 | |
weebgrammers | 7:6dc42e1a2a81 | 4 | #define LOW 0 |
weebgrammers | 7:6dc42e1a2a81 | 5 | #define HIGH 1 |
oopakhooo | 4:f0a11480f39f | 6 | DigitalOut output_pin_A(LED3); |
weebgrammers | 7:6dc42e1a2a81 | 7 | DigitalOut output_pin_V(LED2); |
weebgrammers | 7:6dc42e1a2a81 | 8 | /*=== Analog In ===*/ |
weebgrammers | 7:6dc42e1a2a81 | 9 | AnalogIn atrialIn (A0); // Pin A0 |
weebgrammers | 7:6dc42e1a2a81 | 10 | AnalogIn ventricleIn (A1); // Pin A1 |
weebgrammers | 7:6dc42e1a2a81 | 11 | AnalogIn leadImpedence (A2); // Pin A2 |
weebgrammers | 7:6dc42e1a2a81 | 12 | AnalogIn atr_rect_signal (A3); // Pin A3 |
weebgrammers | 7:6dc42e1a2a81 | 13 | AnalogIn vent_rect_signal (A4); // Pin A4 |
weebgrammers | 7:6dc42e1a2a81 | 14 | |
weebgrammers | 7:6dc42e1a2a81 | 15 | /*=== Digital In ===*/ |
weebgrammers | 7:6dc42e1a2a81 | 16 | DigitalIn atria_cmp_detect (PTC16); // Pin D0 |
weebgrammers | 7:6dc42e1a2a81 | 17 | DigitalIn vent_cmp_detect (PTC17); // Pin D1 |
weebgrammers | 7:6dc42e1a2a81 | 18 | |
weebgrammers | 7:6dc42e1a2a81 | 19 | /*=== PWM Out ===*/ |
weebgrammers | 7:6dc42e1a2a81 | 20 | /* DigitalOut is used for the REF Signal |
weebgrammers | 7:6dc42e1a2a81 | 21 | * due to absence of PWM capabilities of Pins D2 and D4 |
weebgrammers | 7:6dc42e1a2a81 | 22 | * on the FRDM-K64F Board |
weebgrammers | 7:6dc42e1a2a81 | 23 | */ |
weebgrammers | 7:6dc42e1a2a81 | 24 | DigitalOut pacing_ref_pwm (PTB9); // Pin D2 (PTB9) |
weebgrammers | 7:6dc42e1a2a81 | 25 | PwmOut vent_ref_pwm (PTA1); // Pin D3 |
weebgrammers | 7:6dc42e1a2a81 | 26 | DigitalOut atria_ref_pwm (PTB23); // Pin D4 |
weebgrammers | 7:6dc42e1a2a81 | 27 | |
weebgrammers | 7:6dc42e1a2a81 | 28 | |
weebgrammers | 7:6dc42e1a2a81 | 29 | /*=== Digital Out ===*/ |
weebgrammers | 7:6dc42e1a2a81 | 30 | DigitalOut pace_charge_ctrl (PTA2); // Pin D5 |
weebgrammers | 7:6dc42e1a2a81 | 31 | DigitalOut z_atria_ctrl (PTC2); // Pin D6 |
weebgrammers | 7:6dc42e1a2a81 | 32 | DigitalOut z_vent_ctrl (PTC3); // Pin D7 |
weebgrammers | 7:6dc42e1a2a81 | 33 | |
weebgrammers | 7:6dc42e1a2a81 | 34 | DigitalOut atr_pace_ctrl (PTC12); // Pin D8 |
weebgrammers | 7:6dc42e1a2a81 | 35 | DigitalOut vent_pace_ctrl (PTC4); // Pin D9 |
weebgrammers | 7:6dc42e1a2a81 | 36 | DigitalOut pace_grnd_ctrl (PTD0); // Pin D10 |
weebgrammers | 7:6dc42e1a2a81 | 37 | DigitalOut atr_grnd_ctrl (PTD2); // Pin D11 |
weebgrammers | 7:6dc42e1a2a81 | 38 | DigitalOut vent_grnd_ctrl (PTD3); // Pin D12 |
weebgrammers | 7:6dc42e1a2a81 | 39 | DigitalOut frontend_ctrl (PTD1); // Pin D13 |
weebgrammers | 7:6dc42e1a2a81 | 40 | |
weebgrammers | 7:6dc42e1a2a81 | 41 | /*=== On-Board Tri-LED ===*/ |
weebgrammers | 7:6dc42e1a2a81 | 42 | DigitalOut rled (LED_RED); |
weebgrammers | 7:6dc42e1a2a81 | 43 | DigitalOut gled (LED_GREEN); |
weebgrammers | 7:6dc42e1a2a81 | 44 | DigitalOut bled (LED_BLUE); |
weebgrammers | 7:6dc42e1a2a81 | 45 | |
weebgrammers | 7:6dc42e1a2a81 | 46 | |
weebgrammers | 7:6dc42e1a2a81 | 47 | void send_data(Serial &pc,PaceHeart &Pacer){ |
weebgrammers | 7:6dc42e1a2a81 | 48 | |
weebgrammers | 7:6dc42e1a2a81 | 49 | pc.printf ("%c",(char)Pacer.get_p_pacingState()); |
weebgrammers | 7:6dc42e1a2a81 | 50 | pc.printf ("%c",(char)Pacer.get_p_pacingMode()); |
weebgrammers | 7:6dc42e1a2a81 | 51 | pc.printf ("%c",(char)Pacer.get_p_hysteresis()); |
weebgrammers | 7:6dc42e1a2a81 | 52 | pc.printf ("%c%c",(char)((int)(Pacer.get_p_hysteresisInterval()/128)),(char)(Pacer.get_p_hysteresisInterval()%128)); |
weebgrammers | 7:6dc42e1a2a81 | 53 | pc.printf ("%c%c",(char)((int)(Pacer.get_p_lowrateInterval()/128)),(char)((int)(Pacer.get_p_lowrateInterval())%128)); |
weebgrammers | 7:6dc42e1a2a81 | 54 | pc.printf ("%c%c",(char)((int)(Pacer.get_p_vPaceAmp())/128),(char)((int)(Pacer.get_p_vPaceAmp())%128)); |
weebgrammers | 7:6dc42e1a2a81 | 55 | pc.printf ("%c%c",(char)((int)(10.0*Pacer.get_p_vPaceWidth())/128),(char)((int)(10.0*Pacer.get_p_vPaceWidth())%128));//10*pace width |
weebgrammers | 7:6dc42e1a2a81 | 56 | pc.printf ("%c%c\n",(char)((int)(Pacer.get_p_VRP()/128)),(char)(Pacer.get_p_VRP()%128)); |
weebgrammers | 7:6dc42e1a2a81 | 57 | return; |
weebgrammers | 7:6dc42e1a2a81 | 58 | } |
weebgrammers | 7:6dc42e1a2a81 | 59 | void request_data(Serial &pc,PaceHeart &Pacer){ //implement limit later |
weebgrammers | 7:6dc42e1a2a81 | 60 | char d[14]; |
weebgrammers | 7:6dc42e1a2a81 | 61 | int e = 0; |
weebgrammers | 7:6dc42e1a2a81 | 62 | pc.scanf("%s",&d); |
weebgrammers | 7:6dc42e1a2a81 | 63 | pc.printf("%c",'e');//end |
weebgrammers | 7:6dc42e1a2a81 | 64 | e = (int)d[0]; |
weebgrammers | 7:6dc42e1a2a81 | 65 | //Pacer.set_p_pacingState(e); |
weebgrammers | 7:6dc42e1a2a81 | 66 | e = (int)d[1]; |
weebgrammers | 7:6dc42e1a2a81 | 67 | // Pacer.set_p_pacingMode(e); |
weebgrammers | 7:6dc42e1a2a81 | 68 | e = (int)d[2]; |
weebgrammers | 7:6dc42e1a2a81 | 69 | Pacer.set_p_hysteresis(e); |
weebgrammers | 7:6dc42e1a2a81 | 70 | e = (int)d[3]*128+(int)d[4]; |
weebgrammers | 7:6dc42e1a2a81 | 71 | Pacer.set_p_hysteresisInterval(e); |
weebgrammers | 7:6dc42e1a2a81 | 72 | e = (int)d[5]*128+(int)d[6]; |
weebgrammers | 7:6dc42e1a2a81 | 73 | Pacer.set_p_lowrateInterval(e); |
weebgrammers | 7:6dc42e1a2a81 | 74 | e = (int)d[7]*128+(int)d[8]; |
weebgrammers | 7:6dc42e1a2a81 | 75 | Pacer.set_p_vPaceAmp((double)e); |
weebgrammers | 7:6dc42e1a2a81 | 76 | e = (int)d[9]*128+(int)d[10]; |
weebgrammers | 7:6dc42e1a2a81 | 77 | Pacer.set_p_vPaceWidth((double)e/10.0); |
weebgrammers | 7:6dc42e1a2a81 | 78 | e = (int)d[11]*128+(int)d[12]; |
weebgrammers | 7:6dc42e1a2a81 | 79 | Pacer.set_p_VRP(e); |
weebgrammers | 7:6dc42e1a2a81 | 80 | } |
weebgrammers | 7:6dc42e1a2a81 | 81 | |
weebgrammers | 7:6dc42e1a2a81 | 82 | |
weebgrammers | 7:6dc42e1a2a81 | 83 | void stream_A(Serial &pc){ |
weebgrammers | 7:6dc42e1a2a81 | 84 | int amp = (int)(3450*vent_rect_signal); |
weebgrammers | 7:6dc42e1a2a81 | 85 | pc.printf("%c%c\n",(char)(amp/128),(char)(amp%128)); |
weebgrammers | 7:6dc42e1a2a81 | 86 | } |
weebgrammers | 7:6dc42e1a2a81 | 87 | |
weebgrammers | 7:6dc42e1a2a81 | 88 | void stream_V(Serial &pc){ |
weebgrammers | 7:6dc42e1a2a81 | 89 | int amp = (int)(3450*ventricleIn); |
weebgrammers | 7:6dc42e1a2a81 | 90 | pc.printf("%c%c\n",(char)(amp/128),(char)(amp%128)); |
weebgrammers | 7:6dc42e1a2a81 | 91 | } |
weebgrammers | 7:6dc42e1a2a81 | 92 | |
weebgrammers | 7:6dc42e1a2a81 | 93 | void stream(Serial &pc, char mode){ |
weebgrammers | 7:6dc42e1a2a81 | 94 | char c; |
weebgrammers | 7:6dc42e1a2a81 | 95 | while(1){ |
weebgrammers | 7:6dc42e1a2a81 | 96 | if(pc.readable()!=0){ |
weebgrammers | 7:6dc42e1a2a81 | 97 | c = pc.getc(); |
weebgrammers | 7:6dc42e1a2a81 | 98 | if(c=='q'){ |
weebgrammers | 7:6dc42e1a2a81 | 99 | stream_A(pc); |
weebgrammers | 7:6dc42e1a2a81 | 100 | output_pin_V=!output_pin_V; |
weebgrammers | 7:6dc42e1a2a81 | 101 | } |
weebgrammers | 7:6dc42e1a2a81 | 102 | else if(c=='w'){ |
weebgrammers | 7:6dc42e1a2a81 | 103 | return; |
weebgrammers | 7:6dc42e1a2a81 | 104 | } |
weebgrammers | 7:6dc42e1a2a81 | 105 | } |
weebgrammers | 7:6dc42e1a2a81 | 106 | } |
weebgrammers | 7:6dc42e1a2a81 | 107 | } |
weebgrammers | 7:6dc42e1a2a81 | 108 | |
weebgrammers | 7:6dc42e1a2a81 | 109 | void Check_serial(Serial &pc,PaceHeart &Pacer){ |
weebgrammers | 7:6dc42e1a2a81 | 110 | char c = pc.getc(); |
weebgrammers | 7:6dc42e1a2a81 | 111 | if(c=='r'){//send params |
weebgrammers | 7:6dc42e1a2a81 | 112 | send_data(pc,Pacer); |
weebgrammers | 7:6dc42e1a2a81 | 113 | } |
weebgrammers | 7:6dc42e1a2a81 | 114 | else if(c=='s') {//set params |
weebgrammers | 7:6dc42e1a2a81 | 115 | request_data(pc,Pacer); |
weebgrammers | 7:6dc42e1a2a81 | 116 | } |
weebgrammers | 7:6dc42e1a2a81 | 117 | else if(c=='q'){ //stream egram |
weebgrammers | 7:6dc42e1a2a81 | 118 | stream(pc,c); |
weebgrammers | 7:6dc42e1a2a81 | 119 | } |
weebgrammers | 7:6dc42e1a2a81 | 120 | } |
weebgrammers | 7:6dc42e1a2a81 | 121 | |
weebgrammers | 7:6dc42e1a2a81 | 122 | |
weebgrammers | 7:6dc42e1a2a81 | 123 | void Output_A(double amp, double wid){ |
weebgrammers | 7:6dc42e1a2a81 | 124 | vent_ref_pwm = 0.5f; |
weebgrammers | 7:6dc42e1a2a81 | 125 | vent_ref_pwm.pulsewidth(2); |
weebgrammers | 7:6dc42e1a2a81 | 126 | /*AnalogOut aout(p18); //sets up pin 18 as an analogue output |
weebgrammers | 7:6dc42e1a2a81 | 127 | AnalogueIn ain(p15); //sets up pin 15 and an analogue input |
weebgrammers | 7:6dc42e1a2a81 | 128 | |
weebgrammers | 7:6dc42e1a2a81 | 129 | int main(){ |
weebgrammers | 7:6dc42e1a2a81 | 130 | aout=0.5; //sets output to 0.5*VCC |
weebgrammers | 7:6dc42e1a2a81 | 131 | while(1){ //sets up a loop |
weebgrammers | 7:6dc42e1a2a81 | 132 | if (ain>0.3){ //tests whether the input is above 0.3 |
weebgrammers | 7:6dc42e1a2a81 | 133 | aout=0; //sets the output to 0 |
weebgrammers | 7:6dc42e1a2a81 | 134 | } |
weebgrammers | 7:6dc42e1a2a81 | 135 | aout = 0.5; |
weebgrammers | 7:6dc42e1a2a81 | 136 | wait(1); |
weebgrammers | 7:6dc42e1a2a81 | 137 | aout = 0;*/ |
weebgrammers | 7:6dc42e1a2a81 | 138 | // test the voltage on the initialized analog pin |
weebgrammers | 7:6dc42e1a2a81 | 139 | // and if greater than 0.3 * VCC set the digital pin |
weebgrammers | 7:6dc42e1a2a81 | 140 | // to a logic 1 otherwise a logic 0 |
weebgrammers | 7:6dc42e1a2a81 | 141 | } |
weebgrammers | 7:6dc42e1a2a81 | 142 | void Output_V(double amp,double wid){ |
weebgrammers | 7:6dc42e1a2a81 | 143 | //vent_ref_pwm = 0.5f; |
weebgrammers | 7:6dc42e1a2a81 | 144 | //vent_ref_pwm.pulsewidth(2); |
weebgrammers | 7:6dc42e1a2a81 | 145 | atr_grnd_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 146 | vent_grnd_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 147 | |
weebgrammers | 7:6dc42e1a2a81 | 148 | /* Stage 1: Ref PWM On */ |
weebgrammers | 7:6dc42e1a2a81 | 149 | pacing_ref_pwm = HIGH; |
weebgrammers | 7:6dc42e1a2a81 | 150 | wait_ms(10); |
weebgrammers | 7:6dc42e1a2a81 | 151 | |
weebgrammers | 7:6dc42e1a2a81 | 152 | /* Stage 2: Charge CTRL on */ |
weebgrammers | 7:6dc42e1a2a81 | 153 | pace_charge_ctrl = HIGH; |
weebgrammers | 7:6dc42e1a2a81 | 154 | wait_ms(10); |
weebgrammers | 7:6dc42e1a2a81 | 155 | |
weebgrammers | 7:6dc42e1a2a81 | 156 | vent_pace_ctrl = HIGH; |
weebgrammers | 7:6dc42e1a2a81 | 157 | |
weebgrammers | 7:6dc42e1a2a81 | 158 | // Pace Duration |
weebgrammers | 7:6dc42e1a2a81 | 159 | wait_us(wid/10); |
weebgrammers | 7:6dc42e1a2a81 | 160 | |
weebgrammers | 7:6dc42e1a2a81 | 161 | // Shut off Pace |
weebgrammers | 7:6dc42e1a2a81 | 162 | vent_pace_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 163 | |
weebgrammers | 7:6dc42e1a2a81 | 164 | atr_pace_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 165 | vent_pace_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 166 | atr_grnd_ctrl = HIGH; |
weebgrammers | 7:6dc42e1a2a81 | 167 | vent_grnd_ctrl = HIGH; |
weebgrammers | 7:6dc42e1a2a81 | 168 | wait_ms(50); |
weebgrammers | 7:6dc42e1a2a81 | 169 | |
weebgrammers | 7:6dc42e1a2a81 | 170 | |
weebgrammers | 7:6dc42e1a2a81 | 171 | /* Stage 2: Ref PWM LOW */ |
weebgrammers | 7:6dc42e1a2a81 | 172 | pacing_ref_pwm = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 173 | wait_ms(100); |
weebgrammers | 7:6dc42e1a2a81 | 174 | |
weebgrammers | 7:6dc42e1a2a81 | 175 | /* Stage 3: Charge CTRL off */ |
weebgrammers | 7:6dc42e1a2a81 | 176 | pace_charge_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 177 | wait_ms(10); |
weebgrammers | 7:6dc42e1a2a81 | 178 | |
weebgrammers | 7:6dc42e1a2a81 | 179 | /* Stage 4: Ground OFF */ |
weebgrammers | 7:6dc42e1a2a81 | 180 | atr_grnd_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 181 | vent_grnd_ctrl = LOW; |
weebgrammers | 7:6dc42e1a2a81 | 182 | |
weebgrammers | 7:6dc42e1a2a81 | 183 | output_pin_V=!output_pin_V; |
weebgrammers | 7:6dc42e1a2a81 | 184 | /*AnalogOut aout(p18); //sets up pin 18 as an analogue output |
weebgrammers | 7:6dc42e1a2a81 | 185 | AnalogueIn ain(p15); //sets up pin 15 and an analogue input |
weebgrammers | 7:6dc42e1a2a81 | 186 | |
weebgrammers | 7:6dc42e1a2a81 | 187 | int main(){ |
weebgrammers | 7:6dc42e1a2a81 | 188 | aout=0.5; //sets output to 0.5*VCC |
weebgrammers | 7:6dc42e1a2a81 | 189 | while(1){ //sets up a loop |
weebgrammers | 7:6dc42e1a2a81 | 190 | if (ain>0.3){ //tests whether the input is above 0.3 |
weebgrammers | 7:6dc42e1a2a81 | 191 | aout=0; //sets the output to 0 |
weebgrammers | 7:6dc42e1a2a81 | 192 | } |
weebgrammers | 7:6dc42e1a2a81 | 193 | aout = 0.5; |
weebgrammers | 7:6dc42e1a2a81 | 194 | wait(1); |
weebgrammers | 7:6dc42e1a2a81 | 195 | aout = 0;*/ |
weebgrammers | 7:6dc42e1a2a81 | 196 | } |