Test for mike

Dependencies:   mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces

Committer:
kstokely
Date:
Tue Aug 17 19:29:28 2021 +0000
Revision:
11:4367b8eefa6c
Parent:
10:bf195171d850
Test for Mike;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kstokely 11:4367b8eefa6c 1 /*
kstokely 11:4367b8eefa6c 2 Known issues with mbed program for future reference
kstokely 11:4367b8eefa6c 3 1.
kstokely 11:4367b8eefa6c 4 2.
kstokely 11:4367b8eefa6c 5 3.
kstokely 11:4367b8eefa6c 6
kstokely 11:4367b8eefa6c 7 */
kstokely 11:4367b8eefa6c 8
kstokely 10:bf195171d850 9
wbeaumont 1:d175631a5803 10 /** example program for the use of the MCP4728 class and DACInterface.h classes
wbeaumont 1:d175631a5803 11 *
wbeaumont 1:d175631a5803 12 * V 1.0 : tested on the KL05z but without the MCP4728 connected \
kstokely 11:4367b8eefa6c 13 * (C) Wim Beaumont Universiteit Antwerpen 2016
kstokely 11:4367b8eefa6c 14 */
wbeaumont 1:d175631a5803 15
wbeaumont 3:e12e21dcd16a 16 #define MCP4728EXAMPLEVER "2.04"
kstokely 7:e649bb2b6187 17 #define TARGET_MBED 1
wbeaumont 1:d175631a5803 18
wbeaumont 0:5bc0f4bd5aa0 19 #include "mbed.h"
kstokely 7:e649bb2b6187 20 #include <string>
kstokely 10:bf195171d850 21 #include <cstring>
wbeaumont 0:5bc0f4bd5aa0 22
wbeaumont 0:5bc0f4bd5aa0 23 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
kstokely 11:4367b8eefa6c 24 PinName const SDA = PTE25;
kstokely 11:4367b8eefa6c 25 PinName const SCL = PTE24;
wbeaumont 0:5bc0f4bd5aa0 26 #elif defined (TARGET_KL05Z)
kstokely 11:4367b8eefa6c 27 PinName const SDA = PTB4;
kstokely 11:4367b8eefa6c 28 PinName const SCL = PTB3;
wbeaumont 0:5bc0f4bd5aa0 29 #elif defined (TARGET_K20D50M)
kstokely 11:4367b8eefa6c 30 PinName const SDA = PTB1;
kstokely 11:4367b8eefa6c 31 PinName const SCL = PTB0;
kstokely 7:e649bb2b6187 32 #elif defined (TARGET_MBED)
kstokely 11:4367b8eefa6c 33 PinName const SDA = p28;
kstokely 11:4367b8eefa6c 34 PinName const SCL = p27;
wbeaumont 0:5bc0f4bd5aa0 35 #else
kstokely 11:4367b8eefa6c 36 #error TARGET NOT DEFINED
wbeaumont 0:5bc0f4bd5aa0 37 #endif
wbeaumont 0:5bc0f4bd5aa0 38
wbeaumont 0:5bc0f4bd5aa0 39
wbeaumont 0:5bc0f4bd5aa0 40 #include "I2C.h"
kstokely 11:4367b8eefa6c 41 #include "I2CInterface.h"
kstokely 11:4367b8eefa6c 42 #include "MBEDI2CInterface.h"
kstokely 11:4367b8eefa6c 43 #include "DACInterface.h"
wbeaumont 0:5bc0f4bd5aa0 44 #include "dev_interface_def.h"
wbeaumont 3:e12e21dcd16a 45 #include "MCP4728setaddr.h"
wbeaumont 0:5bc0f4bd5aa0 46 #include "mcp4728.h"
kstokely 7:e649bb2b6187 47 #include "shutter.h"
kstokely 7:e649bb2b6187 48
kstokely 11:4367b8eefa6c 49 MBEDI2CInterface mbedi2c( SDA, SCL);
wbeaumont 0:5bc0f4bd5aa0 50 MBEDI2CInterface* mbedi2cp= &mbedi2c ;
wbeaumont 0:5bc0f4bd5aa0 51 I2CInterface* i2cdev= mbedi2cp;
kstokely 7:e649bb2b6187 52 const float Vdd = 4.97;
wbeaumont 3:e12e21dcd16a 53
wbeaumont 0:5bc0f4bd5aa0 54
wbeaumont 0:5bc0f4bd5aa0 55 Serial pc(USBTX, USBRX);
wbeaumont 0:5bc0f4bd5aa0 56
kstokely 11:4367b8eefa6c 57
kstokely 10:bf195171d850 58 DigitalOut CameraTrig(p29);
kstokely 11:4367b8eefa6c 59 InterruptIn TrigInt(p30);
kstokely 11:4367b8eefa6c 60 InterruptIn TrigHW(p30);
kstokely 11:4367b8eefa6c 61 int TrigMode = 0;
kstokely 11:4367b8eefa6c 62
kstokely 7:e649bb2b6187 63
kstokely 7:e649bb2b6187 64 //Pins for 4x4 Module
kstokely 7:e649bb2b6187 65 DigitalOut m4x4TTL1(p21);
kstokely 7:e649bb2b6187 66 DigitalOut m4x4TTL2(p22);
kstokely 7:e649bb2b6187 67 DigitalOut m4x4TTL3(p23);
kstokely 7:e649bb2b6187 68 DigitalOut m4x4TTL4(p24);
kstokely 7:e649bb2b6187 69 DigitalOut m4x4TTL5(p25);
kstokely 7:e649bb2b6187 70
kstokely 7:e649bb2b6187 71 DigitalOut m4x4CLK(p26); //CLk for triggering after new input
kstokely 7:e649bb2b6187 72
kstokely 7:e649bb2b6187 73
kstokely 11:4367b8eefa6c 74
kstokely 7:e649bb2b6187 75 //Pins for 4x5 Module
kstokely 7:e649bb2b6187 76
kstokely 7:e649bb2b6187 77 DigitalOut m4x5TTL1(p7);
kstokely 7:e649bb2b6187 78 DigitalOut m4x5TTL2(p8);
kstokely 7:e649bb2b6187 79 DigitalOut m4x5TTL3(p9);
kstokely 7:e649bb2b6187 80 DigitalOut m4x5TTL4(p10);
kstokely 7:e649bb2b6187 81 DigitalOut m4x5TTL5(p11);
kstokely 7:e649bb2b6187 82
kstokely 7:e649bb2b6187 83 //Shutter Pins
kstokely 7:e649bb2b6187 84 DigitalOut SH1_1(p12);
kstokely 7:e649bb2b6187 85 DigitalOut SH1_2(p13);
kstokely 7:e649bb2b6187 86 DigitalOut SH2_1(p14);
kstokely 7:e649bb2b6187 87 DigitalOut SH2_2(p15);
kstokely 7:e649bb2b6187 88 DigitalOut SH3_1(p16);
kstokely 7:e649bb2b6187 89 DigitalOut SH3_2(p17);
kstokely 7:e649bb2b6187 90 DigitalOut SH4_1(p18);
kstokely 7:e649bb2b6187 91 DigitalOut SH4_2(p19);
kstokely 7:e649bb2b6187 92
kstokely 7:e649bb2b6187 93 DigitalOut m4x5CLK(p20);
kstokely 7:e649bb2b6187 94
kstokely 9:2d70aa45f16e 95 DigitalOut mRefShutters(p5);
kstokely 8:abdd660056fb 96
kstokely 8:abdd660056fb 97 bool Shut1 = 0;
kstokely 8:abdd660056fb 98 bool Shut2 = 0;
kstokely 8:abdd660056fb 99 bool Shut3 = 0;
kstokely 8:abdd660056fb 100 bool Shut4 = 0;
kstokely 8:abdd660056fb 101
kstokely 11:4367b8eefa6c 102
kstokely 11:4367b8eefa6c 103 int DVOA1 = 0;
kstokely 11:4367b8eefa6c 104 int DVOA2 = 0;
kstokely 11:4367b8eefa6c 105 int DVOA3 = 0;
kstokely 11:4367b8eefa6c 106 int DVOA4 = 0;
kstokely 11:4367b8eefa6c 107
kstokely 11:4367b8eefa6c 108 bool trigSet = 0;
kstokely 11:4367b8eefa6c 109
kstokely 10:bf195171d850 110 string pcstr;
kstokely 10:bf195171d850 111 string seqstr;
kstokely 10:bf195171d850 112 Timer t;
kstokely 8:abdd660056fb 113
kstokely 11:4367b8eefa6c 114 MCP4728* gbldac;
kstokely 11:4367b8eefa6c 115 Shutter* gblSH;
kstokely 11:4367b8eefa6c 116
kstokely 11:4367b8eefa6c 117
kstokely 8:abdd660056fb 118
kstokely 10:bf195171d850 119 void trigSH( Shutter SH, int nimg )
kstokely 10:bf195171d850 120 {
kstokely 11:4367b8eefa6c 121 for(int i = 0; i<nimg; i++) {
kstokely 10:bf195171d850 122 SH.writeShutters(1,1,1,1);//Turn on Shutters
kstokely 11:4367b8eefa6c 123
kstokely 10:bf195171d850 124 wait_us(92);//Wait for shutter to go high
kstokely 10:bf195171d850 125 wait_us(120);//Wait to trigger until middle of Shutter Opening
kstokely 11:4367b8eefa6c 126
kstokely 10:bf195171d850 127 CameraTrig = 1;//Trigger Camera to turn on
kstokely 10:bf195171d850 128 wait_us(38);//Wait for rest of 250 us
kstokely 11:4367b8eefa6c 129
kstokely 10:bf195171d850 130 //wait_us(16417); //DEBUG: Added extra delay to slow down trigger
kstokely 11:4367b8eefa6c 131
kstokely 10:bf195171d850 132 //Turn off shutters and Camera Trigger
kstokely 10:bf195171d850 133 SH.writeShutters(0,0,0,0);
kstokely 11:4367b8eefa6c 134
kstokely 10:bf195171d850 135 CameraTrig = 0;
kstokely 11:4367b8eefa6c 136
kstokely 11:4367b8eefa6c 137 wait_us(8183); //Wait to run at 120 Hz
kstokely 11:4367b8eefa6c 138
kstokely 10:bf195171d850 139 //wait_us(16417); //DEBUG: Added extra delay to slow down trigger
kstokely 10:bf195171d850 140 }
kstokely 11:4367b8eefa6c 141 //pc.printf("Triggered Shutters (trigSH) \n\r");
kstokely 10:bf195171d850 142 }
kstokely 11:4367b8eefa6c 143
kstokely 10:bf195171d850 144
kstokely 10:bf195171d850 145 void trigNotEyeSafe( Shutter SH, int nimg )
kstokely 10:bf195171d850 146 {
kstokely 11:4367b8eefa6c 147 for(int i = 0; i<nimg; i++) {
kstokely 10:bf195171d850 148 //SH.writeShutters(1,1,1,1);//Turn on Shutters
kstokely 11:4367b8eefa6c 149
kstokely 10:bf195171d850 150 wait_us(92);//Wait for shutter to go high
kstokely 10:bf195171d850 151 wait_us(120);//Wait to trigger until middle of Shutter Opening
kstokely 11:4367b8eefa6c 152
kstokely 10:bf195171d850 153 CameraTrig = 1;//Trigger Camera to turn on
kstokely 10:bf195171d850 154 wait_us(38);//Wait for rest of 250 us
kstokely 11:4367b8eefa6c 155
kstokely 10:bf195171d850 156 //wait_us(16417);//DEBUG: Added extra delay to slow down trigger
kstokely 11:4367b8eefa6c 157
kstokely 10:bf195171d850 158 //Turn off shutters and Camera Trigger
kstokely 10:bf195171d850 159 //SH.writeShutters(0,0,0,0);
kstokely 10:bf195171d850 160 CameraTrig = 0;
kstokely 11:4367b8eefa6c 161
kstokely 11:4367b8eefa6c 162 wait_us(8183); //Wait to run at 120 Hz
kstokely 11:4367b8eefa6c 163
kstokely 11:4367b8eefa6c 164 // wait_us(16417);//DEBUG: Added extra delay to slow down trigger
kstokely 10:bf195171d850 165 }
kstokely 11:4367b8eefa6c 166 //pc.printf("Triggered Shutters (trigNotEyeSafe) \n\r");
kstokely 10:bf195171d850 167 }
kstokely 11:4367b8eefa6c 168
kstokely 11:4367b8eefa6c 169
kstokely 10:bf195171d850 170
kstokely 10:bf195171d850 171 int DACSetChannel( int chan, MCP4728* dac, int counts)
kstokely 8:abdd660056fb 172 {
kstokely 8:abdd660056fb 173 int ret = 0;
kstokely 10:bf195171d850 174 int z = 0;
kstokely 10:bf195171d850 175 int CHcnt;
kstokely 10:bf195171d850 176 int voltCount = counts;
kstokely 8:abdd660056fb 177 string instr;
kstokely 8:abdd660056fb 178
kstokely 11:4367b8eefa6c 179 if( voltCount > 4095 || voltCount < 0) {
kstokely 10:bf195171d850 180 voltCount = 4095;
kstokely 10:bf195171d850 181 }
kstokely 11:4367b8eefa6c 182
kstokely 11:4367b8eefa6c 183 while(ret == 0 && z < 10) {
kstokely 10:bf195171d850 184 //t.start();
kstokely 10:bf195171d850 185 dac->update();
kstokely 10:bf195171d850 186 //t.stop();
kstokely 10:bf195171d850 187 //t.reset();
kstokely 10:bf195171d850 188 //pc.printf("DAC update took %f seconds \n\r",t.read());
kstokely 10:bf195171d850 189 (void)dac->getDACvalue(CHcnt,chan);
kstokely 11:4367b8eefa6c 190
kstokely 11:4367b8eefa6c 191 if(CHcnt == counts) {
kstokely 10:bf195171d850 192 ret = 1;
kstokely 11:4367b8eefa6c 193 } else {
kstokely 10:bf195171d850 194 //t.start();
kstokely 10:bf195171d850 195 dac->setDACvalue(voltCount,chan);
kstokely 10:bf195171d850 196 //t.stop();
kstokely 10:bf195171d850 197 //pc.printf("DAC setting took %f seconds \n\r",t.read());
kstokely 10:bf195171d850 198 z++;
kstokely 11:4367b8eefa6c 199 }
kstokely 11:4367b8eefa6c 200
kstokely 11:4367b8eefa6c 201
kstokely 11:4367b8eefa6c 202 }
kstokely 11:4367b8eefa6c 203
kstokely 11:4367b8eefa6c 204
kstokely 8:abdd660056fb 205 return 1;
kstokely 8:abdd660056fb 206 }
kstokely 11:4367b8eefa6c 207
kstokely 10:bf195171d850 208 void set4x4Piping(DigitalOut** Arr_4x4, char z1, char z2, char z3, char z4, char z5)
kstokely 10:bf195171d850 209 {
kstokely 11:4367b8eefa6c 210
kstokely 11:4367b8eefa6c 211
kstokely 11:4367b8eefa6c 212 *Arr_4x4[0] = atoi(&z1);
kstokely 11:4367b8eefa6c 213 *Arr_4x4[1] = atoi(&z2);
kstokely 11:4367b8eefa6c 214 *Arr_4x4[2] = atoi(&z3);
kstokely 11:4367b8eefa6c 215 *Arr_4x4[3] = atoi(&z4);
kstokely 11:4367b8eefa6c 216 *Arr_4x4[4] = atoi(&z5);
kstokely 11:4367b8eefa6c 217
kstokely 11:4367b8eefa6c 218 for( int k = 0; k<2; k++) { //Trigger clocking to change values
kstokely 11:4367b8eefa6c 219 m4x4CLK = 1;
kstokely 11:4367b8eefa6c 220 wait_us(200);
kstokely 11:4367b8eefa6c 221 m4x4CLK = 0;
kstokely 11:4367b8eefa6c 222 }
kstokely 11:4367b8eefa6c 223
kstokely 11:4367b8eefa6c 224 //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() ); //Confirm the correct output is set
kstokely 10:bf195171d850 225 }
kstokely 7:e649bb2b6187 226
kstokely 10:bf195171d850 227 void set4x5Piping(DigitalOut** Arr_4x5, char z1, char z2, char z3, char z4, char z5)
kstokely 10:bf195171d850 228 {
kstokely 11:4367b8eefa6c 229
kstokely 11:4367b8eefa6c 230
kstokely 11:4367b8eefa6c 231 *Arr_4x5[0] = atoi(&z1);
kstokely 11:4367b8eefa6c 232 *Arr_4x5[1] = atoi(&z2);
kstokely 11:4367b8eefa6c 233 *Arr_4x5[2] = atoi(&z3);
kstokely 11:4367b8eefa6c 234 *Arr_4x5[3] = atoi(&z4);
kstokely 11:4367b8eefa6c 235 *Arr_4x5[4] = atoi(&z5);
kstokely 11:4367b8eefa6c 236
kstokely 11:4367b8eefa6c 237 for( int k = 0; k<2; k++) { //Trigger clocking to change values
kstokely 11:4367b8eefa6c 238 m4x5CLK = 1;
kstokely 11:4367b8eefa6c 239 wait_us(200);
kstokely 11:4367b8eefa6c 240 m4x5CLK = 0;
kstokely 11:4367b8eefa6c 241 }
kstokely 11:4367b8eefa6c 242
kstokely 11:4367b8eefa6c 243 //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); //Confirm the correct output is set
kstokely 10:bf195171d850 244 }
kstokely 7:e649bb2b6187 245
kstokely 7:e649bb2b6187 246
kstokely 7:e649bb2b6187 247
kstokely 10:bf195171d850 248 void toggleShut1(Shutter SH)
kstokely 10:bf195171d850 249 {
kstokely 10:bf195171d850 250 Shut1 = !Shut1;
kstokely 10:bf195171d850 251 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 252 }
kstokely 10:bf195171d850 253
kstokely 10:bf195171d850 254
kstokely 10:bf195171d850 255 void toggleShut2(Shutter SH)
kstokely 10:bf195171d850 256 {
kstokely 10:bf195171d850 257 Shut2 = !Shut2;
kstokely 10:bf195171d850 258 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 259 }
kstokely 10:bf195171d850 260
kstokely 10:bf195171d850 261
kstokely 10:bf195171d850 262 void toggleShut3(Shutter SH)
kstokely 10:bf195171d850 263 {
kstokely 10:bf195171d850 264 Shut3 = !Shut3;
kstokely 10:bf195171d850 265 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 266 }
kstokely 10:bf195171d850 267
kstokely 10:bf195171d850 268
kstokely 10:bf195171d850 269 void toggleShut4(Shutter SH)
kstokely 10:bf195171d850 270 {
kstokely 10:bf195171d850 271 Shut4 = !Shut4;
kstokely 10:bf195171d850 272 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 273 }
kstokely 10:bf195171d850 274
kstokely 10:bf195171d850 275 void closeRef()
kstokely 10:bf195171d850 276 {
kstokely 10:bf195171d850 277 mRefShutters = 0;
kstokely 10:bf195171d850 278 }
kstokely 10:bf195171d850 279
kstokely 10:bf195171d850 280 void openRef()
kstokely 10:bf195171d850 281 {
kstokely 10:bf195171d850 282 mRefShutters = 1;
kstokely 10:bf195171d850 283 }
kstokely 10:bf195171d850 284
kstokely 10:bf195171d850 285 void openAllHP(Shutter SH)
kstokely 10:bf195171d850 286 {
kstokely 10:bf195171d850 287 Shut1 = 1;
kstokely 10:bf195171d850 288 Shut2 = 1;
kstokely 10:bf195171d850 289 Shut3 = 1;
kstokely 10:bf195171d850 290 Shut4 = 1;
kstokely 10:bf195171d850 291 SH.writeShutters(1,1,1,1);
kstokely 10:bf195171d850 292 }
kstokely 10:bf195171d850 293
kstokely 10:bf195171d850 294 void closeAllHP(Shutter SH)
kstokely 10:bf195171d850 295 {
kstokely 10:bf195171d850 296 Shut1 = 0;
kstokely 10:bf195171d850 297 Shut2 = 0;
kstokely 10:bf195171d850 298 Shut3 = 0;
kstokely 10:bf195171d850 299 Shut4 = 0;
kstokely 10:bf195171d850 300 SH.writeShutters(0,0,0,0);
kstokely 10:bf195171d850 301 }
kstokely 10:bf195171d850 302
kstokely 10:bf195171d850 303 void setAllShutters(Shutter SH,char z1, char z2, char z3, char z4)
kstokely 10:bf195171d850 304 {
kstokely 11:4367b8eefa6c 305
kstokely 11:4367b8eefa6c 306 Shut1 = atoi(&z1);
kstokely 11:4367b8eefa6c 307 Shut2 = atoi(&z2);
kstokely 11:4367b8eefa6c 308 Shut3 = atoi(&z3);
kstokely 11:4367b8eefa6c 309 Shut4 = atoi(&z4);
kstokely 11:4367b8eefa6c 310 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 311 }
kstokely 10:bf195171d850 312
kstokely 10:bf195171d850 313 void queryDAC(MCP4728* dac)
kstokely 10:bf195171d850 314 {
kstokely 10:bf195171d850 315 int CH1cnt;
kstokely 10:bf195171d850 316 int CH2cnt;
kstokely 10:bf195171d850 317 int CH3cnt;
kstokely 10:bf195171d850 318 int CH4cnt;
kstokely 10:bf195171d850 319 //Print State of DAC
kstokely 11:4367b8eefa6c 320 if( dac->update() == 0) {
kstokely 10:bf195171d850 321 (void)dac->getDACvalue(CH1cnt,0);
kstokely 10:bf195171d850 322 (void)dac->getDACvalue(CH2cnt,1);
kstokely 10:bf195171d850 323 (void)dac->getDACvalue(CH3cnt,2);
kstokely 10:bf195171d850 324 (void)dac->getDACvalue(CH4cnt,3);
kstokely 10:bf195171d850 325 pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d\n\r",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
kstokely 10:bf195171d850 326 }
kstokely 11:4367b8eefa6c 327
kstokely 11:4367b8eefa6c 328 else {
kstokely 10:bf195171d850 329 pc.printf("Error: No readback from DAC\n\r");
kstokely 10:bf195171d850 330 }
kstokely 10:bf195171d850 331 }
kstokely 10:bf195171d850 332
kstokely 10:bf195171d850 333 void queryShutters()
kstokely 10:bf195171d850 334 {
kstokely 10:bf195171d850 335 //Print State of Shutters
kstokely 10:bf195171d850 336 pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d\n\r",Shut1,Shut2,Shut3,Shut4,mRefShutters.read());
kstokely 10:bf195171d850 337 }
kstokely 10:bf195171d850 338
kstokely 11:4367b8eefa6c 339 void HWTrigHandler()
kstokely 11:4367b8eefa6c 340 {
kstokely 11:4367b8eefa6c 341 //pc.printf("Hardware Interrupt Triggered \n\r");
kstokely 11:4367b8eefa6c 342
kstokely 11:4367b8eefa6c 343 if (TrigMode == 0)
kstokely 11:4367b8eefa6c 344 {
kstokely 11:4367b8eefa6c 345 trigSet = 1;
kstokely 11:4367b8eefa6c 346 }
kstokely 11:4367b8eefa6c 347
kstokely 11:4367b8eefa6c 348 else
kstokely 11:4367b8eefa6c 349 {
kstokely 11:4367b8eefa6c 350 int i;
kstokely 11:4367b8eefa6c 351 int nimgs = 0;
kstokely 11:4367b8eefa6c 352 //pc.printf("Interrupt Triggered \n\r");
kstokely 11:4367b8eefa6c 353 for(i = 0; i<seqstr.size(); i++) {
kstokely 11:4367b8eefa6c 354 //Find characters and then grab next three digits as the number of times to trigger
kstokely 11:4367b8eefa6c 355
kstokely 11:4367b8eefa6c 356 if( seqstr[i] == 'i') {
kstokely 11:4367b8eefa6c 357 nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
kstokely 11:4367b8eefa6c 358 DACSetChannel( 0, gbldac, 4095);
kstokely 11:4367b8eefa6c 359 DACSetChannel( 1, gbldac, 4095);
kstokely 11:4367b8eefa6c 360 DACSetChannel( 2, gbldac, 4095);
kstokely 11:4367b8eefa6c 361 DACSetChannel( 3, gbldac, 4095);
kstokely 11:4367b8eefa6c 362 trigSH( *gblSH, nimgs );
kstokely 11:4367b8eefa6c 363 //pc.printf("Num Illums: %d\n",nimgs);
kstokely 11:4367b8eefa6c 364 } else if( seqstr[i] == 'd') {
kstokely 11:4367b8eefa6c 365 nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
kstokely 11:4367b8eefa6c 366 gblSH->writeShutters(0,0,0,0);
kstokely 11:4367b8eefa6c 367 DACSetChannel( 0, gbldac, 4095);
kstokely 11:4367b8eefa6c 368 DACSetChannel( 1, gbldac, 4095);
kstokely 11:4367b8eefa6c 369 DACSetChannel( 2, gbldac, 4095);
kstokely 11:4367b8eefa6c 370 DACSetChannel( 3, gbldac, 4095);
kstokely 11:4367b8eefa6c 371 trigNotEyeSafe( *gblSH, nimgs );
kstokely 11:4367b8eefa6c 372 //pc.printf("Num Darks: %d\n",nimgs);
kstokely 11:4367b8eefa6c 373 } else if( seqstr[i] == 'c') {
kstokely 11:4367b8eefa6c 374 nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
kstokely 11:4367b8eefa6c 375 DACSetChannel( 0, gbldac, DVOA1);
kstokely 11:4367b8eefa6c 376 DACSetChannel( 1, gbldac, DVOA2);
kstokely 11:4367b8eefa6c 377 DACSetChannel( 2, gbldac, DVOA3);
kstokely 11:4367b8eefa6c 378 DACSetChannel( 3, gbldac, DVOA4);
kstokely 11:4367b8eefa6c 379 trigSH( *gblSH, nimgs );
kstokely 11:4367b8eefa6c 380
kstokely 11:4367b8eefa6c 381 //pc.printf("Num Contours: %d\n",nimgs);
kstokely 11:4367b8eefa6c 382 }
kstokely 11:4367b8eefa6c 383
kstokely 11:4367b8eefa6c 384
kstokely 11:4367b8eefa6c 385
kstokely 11:4367b8eefa6c 386 else if( seqstr[i] == 'r') {
kstokely 11:4367b8eefa6c 387 nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
kstokely 11:4367b8eefa6c 388 DACSetChannel( 0, gbldac, DVOA1);
kstokely 11:4367b8eefa6c 389 DACSetChannel( 1, gbldac, DVOA2);
kstokely 11:4367b8eefa6c 390 DACSetChannel( 2, gbldac, DVOA3);
kstokely 11:4367b8eefa6c 391 DACSetChannel( 3, gbldac, DVOA4);
kstokely 11:4367b8eefa6c 392 gblSH->writeShutters(0,0,0,0);
kstokely 11:4367b8eefa6c 393 trigNotEyeSafe( *gblSH, nimgs );
kstokely 11:4367b8eefa6c 394 //pc.printf("Num Refs: %d\n",nimgs);
kstokely 11:4367b8eefa6c 395 }
kstokely 11:4367b8eefa6c 396
kstokely 11:4367b8eefa6c 397 }
kstokely 11:4367b8eefa6c 398 }
kstokely 11:4367b8eefa6c 399 }
kstokely 11:4367b8eefa6c 400
kstokely 11:4367b8eefa6c 401 void extTrigHandler()
kstokely 11:4367b8eefa6c 402 {
kstokely 11:4367b8eefa6c 403 //In this mode trigger button sets the query Trig to high
kstokely 11:4367b8eefa6c 404 //Matlab query the trigger to see if it needs to stop
kstokely 11:4367b8eefa6c 405
kstokely 11:4367b8eefa6c 406 //trigSet = 1;
kstokely 11:4367b8eefa6c 407
kstokely 11:4367b8eefa6c 408
kstokely 11:4367b8eefa6c 409 /*
kstokely 11:4367b8eefa6c 410
kstokely 11:4367b8eefa6c 411 */
kstokely 11:4367b8eefa6c 412 }
kstokely 11:4367b8eefa6c 413
kstokely 11:4367b8eefa6c 414
kstokely 11:4367b8eefa6c 415 int main(void)
kstokely 11:4367b8eefa6c 416 {
kstokely 11:4367b8eefa6c 417
kstokely 11:4367b8eefa6c 418 //get the version of getVersion
kstokely 10:bf195171d850 419 getVersion gv;
kstokely 10:bf195171d850 420 int addr;
kstokely 10:bf195171d850 421 //Timer m;
kstokely 10:bf195171d850 422 addr = 0;
kstokely 11:4367b8eefa6c 423 MCP4728 dac( i2cdev ,addr, Vdd); // assuming the address of the MCP4728 is set to 0 factory default
kstokely 11:4367b8eefa6c 424 gbldac = &dac;
kstokely 10:bf195171d850 425 wait(1);
kstokely 7:e649bb2b6187 426
kstokely 10:bf195171d850 427 pc.baud(921600);
kstokely 10:bf195171d850 428 mRefShutters = 1;
kstokely 7:e649bb2b6187 429
kstokely 11:4367b8eefa6c 430 //Set up dac for external voltage
kstokely 10:bf195171d850 431 dac.setRefExtern();
kstokely 10:bf195171d850 432 dac.update();
kstokely 7:e649bb2b6187 433
kstokely 11:4367b8eefa6c 434 //Intialize shutters
kstokely 7:e649bb2b6187 435 Shutter SH;
kstokely 7:e649bb2b6187 436 SH.init( &SH1_1, &SH1_2, &SH2_1, &SH2_2, &SH3_1, &SH3_2, &SH4_1, &SH4_2 );
kstokely 8:abdd660056fb 437
kstokely 7:e649bb2b6187 438 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 11:4367b8eefa6c 439 gblSH = &SH;
kstokely 11:4367b8eefa6c 440
kstokely 11:4367b8eefa6c 441 //Set up ext trig interrupt
kstokely 11:4367b8eefa6c 442 TrigInt.rise(&extTrigHandler);
kstokely 11:4367b8eefa6c 443 TrigInt.mode(PullUp);
kstokely 7:e649bb2b6187 444
kstokely 11:4367b8eefa6c 445 TrigHW.rise(&HWTrigHandler);
kstokely 11:4367b8eefa6c 446 TrigHW.mode(PullUp);
kstokely 11:4367b8eefa6c 447 TrigHW.enable_irq();
kstokely 11:4367b8eefa6c 448
kstokely 11:4367b8eefa6c 449
kstokely 7:e649bb2b6187 450 //TTL pin arrays
kstokely 7:e649bb2b6187 451 DigitalOut* Arr_4x4[5] = {&m4x4TTL1, &m4x4TTL2, &m4x4TTL3, &m4x4TTL4, &m4x4TTL5 };
kstokely 7:e649bb2b6187 452 DigitalOut* Arr_4x5[5] = {&m4x5TTL1, &m4x5TTL2, &m4x5TTL3, &m4x5TTL4, &m4x5TTL5 };
kstokely 11:4367b8eefa6c 453
kstokely 11:4367b8eefa6c 454
kstokely 8:abdd660056fb 455 //Set straight pipes initial state
kstokely 7:e649bb2b6187 456 m4x5TTL1 = 1;
kstokely 10:bf195171d850 457 m4x4TTL1 = 1;
kstokely 11:4367b8eefa6c 458
kstokely 7:e649bb2b6187 459 string instr;
kstokely 11:4367b8eefa6c 460
kstokely 11:4367b8eefa6c 461 seqstr = "d010r010i010c010";
kstokely 11:4367b8eefa6c 462
kstokely 10:bf195171d850 463 pcstr.resize(200);
kstokely 11:4367b8eefa6c 464
kstokely 11:4367b8eefa6c 465 while(1)
kstokely 11:4367b8eefa6c 466 {
kstokely 11:4367b8eefa6c 467 //pc.printf("looping");
kstokely 10:bf195171d850 468 pc.scanf("%s", pcstr.c_str() );
kstokely 11:4367b8eefa6c 469
kstokely 11:4367b8eefa6c 470
kstokely 10:bf195171d850 471 int indexArr[100];
kstokely 10:bf195171d850 472 int indexSize = 0;
kstokely 11:4367b8eefa6c 473
kstokely 11:4367b8eefa6c 474
kstokely 10:bf195171d850 475 //had to change as string does not resize
kstokely 10:bf195171d850 476 int i =0;
kstokely 10:bf195171d850 477 while( pcstr.c_str()[i] != 0 && pcstr.c_str()[i] != ' ' && pcstr.c_str()[i] != '\0')
kstokely 10:bf195171d850 478 {
kstokely 10:bf195171d850 479 if( pcstr[i] == ',')
kstokely 10:bf195171d850 480 {
kstokely 10:bf195171d850 481 indexArr[indexSize] = i;
kstokely 10:bf195171d850 482 indexSize++;
kstokely 10:bf195171d850 483 }
kstokely 10:bf195171d850 484 i++;
kstokely 10:bf195171d850 485 }
kstokely 11:4367b8eefa6c 486
kstokely 10:bf195171d850 487 //DEBUG
kstokely 10:bf195171d850 488 //pc.printf( "Commas Found %d\n\r",indexSize );
kstokely 11:4367b8eefa6c 489
kstokely 11:4367b8eefa6c 490
kstokely 11:4367b8eefa6c 491
kstokely 10:bf195171d850 492 //Interpret commands
kstokely 10:bf195171d850 493 for(int i =0; i<indexSize; i++)
kstokely 10:bf195171d850 494 {
kstokely 10:bf195171d850 495 //DEBUG
kstokely 10:bf195171d850 496 //pc.printf( "Loop #%d of %d\n\r",i,indexSize-1 );
kstokely 11:4367b8eefa6c 497
kstokely 10:bf195171d850 498 char c;
kstokely 10:bf195171d850 499 //command must begin with a comma
kstokely 10:bf195171d850 500 c = pcstr.c_str()[ indexArr[i] +1 ];
kstokely 11:4367b8eefa6c 501
kstokely 10:bf195171d850 502 //DEBUG
kstokely 10:bf195171d850 503 //pc.printf( "Cmd is %c\n\r",c );
kstokely 11:4367b8eefa6c 504
kstokely 11:4367b8eefa6c 505
kstokely 7:e649bb2b6187 506 if( c == '1') //Toggle Shutter 1
kstokely 7:e649bb2b6187 507 {
kstokely 10:bf195171d850 508 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 509 Shut1 = atoi(&z1);
kstokely 7:e649bb2b6187 510 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 7:e649bb2b6187 511 }
kstokely 11:4367b8eefa6c 512
kstokely 7:e649bb2b6187 513 else if( c == '2') //Toggle Shutter 2
kstokely 7:e649bb2b6187 514 {
kstokely 10:bf195171d850 515 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 516 Shut2 = atoi(&z1);
kstokely 7:e649bb2b6187 517 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 7:e649bb2b6187 518 }
kstokely 11:4367b8eefa6c 519
kstokely 7:e649bb2b6187 520 else if( c == '3') //Toggle Shutter 3
kstokely 7:e649bb2b6187 521 {
kstokely 10:bf195171d850 522 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 523 Shut3 = atoi(&z1);
kstokely 7:e649bb2b6187 524 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 7:e649bb2b6187 525 }
kstokely 11:4367b8eefa6c 526
kstokely 7:e649bb2b6187 527 else if( c == '4') //Toggle Shutter 4
kstokely 7:e649bb2b6187 528 {
kstokely 10:bf195171d850 529 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 530 Shut4 = atoi(&z1);
kstokely 7:e649bb2b6187 531 SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
kstokely 7:e649bb2b6187 532 }
kstokely 7:e649bb2b6187 533
kstokely 11:4367b8eefa6c 534 else if (c == '5')
kstokely 11:4367b8eefa6c 535 {
kstokely 11:4367b8eefa6c 536 TrigMode = 0;
kstokely 11:4367b8eefa6c 537 }
kstokely 11:4367b8eefa6c 538
kstokely 11:4367b8eefa6c 539 else if (c == '6')
kstokely 11:4367b8eefa6c 540 {
kstokely 11:4367b8eefa6c 541 TrigMode = 1;
kstokely 11:4367b8eefa6c 542 }
kstokely 11:4367b8eefa6c 543
kstokely 8:abdd660056fb 544 else if( c == 'u')
kstokely 8:abdd660056fb 545 {
kstokely 10:bf195171d850 546 closeRef();
kstokely 8:abdd660056fb 547 }
kstokely 11:4367b8eefa6c 548
kstokely 8:abdd660056fb 549 else if( c == 'y')
kstokely 8:abdd660056fb 550 {
kstokely 10:bf195171d850 551 openRef();
kstokely 8:abdd660056fb 552 }
kstokely 11:4367b8eefa6c 553
kstokely 8:abdd660056fb 554 else if(c == 'o') //Open All Shutters
kstokely 8:abdd660056fb 555 {
kstokely 10:bf195171d850 556 openAllHP(SH);
kstokely 8:abdd660056fb 557 }
kstokely 11:4367b8eefa6c 558
kstokely 8:abdd660056fb 559 else if(c == 'r') //Close All Shutters
kstokely 8:abdd660056fb 560 {
kstokely 10:bf195171d850 561 closeAllHP(SH);
kstokely 10:bf195171d850 562 }
kstokely 11:4367b8eefa6c 563
kstokely 10:bf195171d850 564 else if( c == 'm')
kstokely 10:bf195171d850 565 {
kstokely 10:bf195171d850 566 //string sub = pcstr.substr( indexArr[i]+2 , 4 );//Used for DAC
kstokely 10:bf195171d850 567 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 568 char z2 = pcstr[ indexArr[i] +3 ];
kstokely 10:bf195171d850 569 char z3 = pcstr[ indexArr[i] +4 ];
kstokely 11:4367b8eefa6c 570 char z4 = pcstr[ indexArr[i] +5 ];
kstokely 10:bf195171d850 571 setAllShutters(SH,z1,z2,z3,z4);
kstokely 8:abdd660056fb 572 }
kstokely 11:4367b8eefa6c 573
kstokely 8:abdd660056fb 574 else if( c == 91 ) //Left square bracket [ 4x4 Control
kstokely 7:e649bb2b6187 575 {
kstokely 10:bf195171d850 576 //get inputs for 4x4
kstokely 10:bf195171d850 577 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 578 char z2 = pcstr[ indexArr[i] +3 ];
kstokely 10:bf195171d850 579 char z3 = pcstr[ indexArr[i] +4 ];
kstokely 10:bf195171d850 580 char z4 = pcstr[ indexArr[i] +5 ];
kstokely 10:bf195171d850 581 char z5 = pcstr[ indexArr[i] +6 ];
kstokely 10:bf195171d850 582 set4x4Piping(Arr_4x4,z1,z2,z3,z4,z5);
kstokely 7:e649bb2b6187 583 }
kstokely 11:4367b8eefa6c 584
kstokely 11:4367b8eefa6c 585
kstokely 8:abdd660056fb 586 else if( c == 93 ) //Right square bracket ] 4x5 Control
kstokely 7:e649bb2b6187 587 {
kstokely 10:bf195171d850 588 char z1 = pcstr[ indexArr[i] +2 ];
kstokely 10:bf195171d850 589 char z2 = pcstr[ indexArr[i] +3 ];
kstokely 10:bf195171d850 590 char z3 = pcstr[ indexArr[i] +4 ];
kstokely 10:bf195171d850 591 char z4 = pcstr[ indexArr[i] +5 ];
kstokely 10:bf195171d850 592 char z5 = pcstr[ indexArr[i] +6 ];
kstokely 10:bf195171d850 593 set4x5Piping(Arr_4x5,z1,z2,z3,z4,z5);
kstokely 7:e649bb2b6187 594 }
kstokely 11:4367b8eefa6c 595
kstokely 11:4367b8eefa6c 596
kstokely 9:2d70aa45f16e 597 else if( c == 'd')
kstokely 9:2d70aa45f16e 598 {
kstokely 10:bf195171d850 599 queryDAC(&dac);
kstokely 9:2d70aa45f16e 600 }
kstokely 11:4367b8eefa6c 601
kstokely 9:2d70aa45f16e 602 else if( c == 'a')
kstokely 9:2d70aa45f16e 603 {
kstokely 10:bf195171d850 604 queryShutters();
kstokely 11:4367b8eefa6c 605 }
kstokely 11:4367b8eefa6c 606
kstokely 11:4367b8eefa6c 607
kstokely 9:2d70aa45f16e 608
kstokely 8:abdd660056fb 609 else if( c == '.' ) //Single Channel DAC Control
kstokely 8:abdd660056fb 610 {
kstokely 9:2d70aa45f16e 611 ////pc.printf("Single Channel DAC Control Press Channel Number\n\r");
kstokely 11:4367b8eefa6c 612
kstokely 11:4367b8eefa6c 613
kstokely 10:bf195171d850 614 char achan = pcstr[ indexArr[i] + 2 ];
kstokely 10:bf195171d850 615 int ichan = atoi(&achan);
kstokely 11:4367b8eefa6c 616
kstokely 10:bf195171d850 617 char acount[5];
kstokely 10:bf195171d850 618 acount[0] = pcstr[ indexArr[i] + 3 ];
kstokely 10:bf195171d850 619 acount[1] = pcstr[ indexArr[i] + 4 ];
kstokely 10:bf195171d850 620 acount[2] = pcstr[ indexArr[i] + 5 ];
kstokely 10:bf195171d850 621 acount[3] = pcstr[ indexArr[i] + 6 ];
kstokely 10:bf195171d850 622 acount[4] = '\0';
kstokely 10:bf195171d850 623 int icount = atoi(acount);//Get 4 digit Count
kstokely 10:bf195171d850 624 //icount = icount / 10;
kstokely 10:bf195171d850 625 //DEBUG
kstokely 11:4367b8eefa6c 626 //pc.printf("DAC Channel: %d DAC Counts: %d Acount:\n\r",ichan,icount);
kstokely 11:4367b8eefa6c 627
kstokely 11:4367b8eefa6c 628
kstokely 10:bf195171d850 629 if( achan == '1' || achan== '2' || achan == '3' || achan == '0' )
kstokely 8:abdd660056fb 630 {
kstokely 9:2d70aa45f16e 631 //////////pc.printf("Channel %c Selected",z);
kstokely 10:bf195171d850 632 DACSetChannel( ichan , &dac, icount);
kstokely 11:4367b8eefa6c 633 }
kstokely 7:e649bb2b6187 634 else
kstokely 7:e649bb2b6187 635 {
kstokely 9:2d70aa45f16e 636 ////pc.printf("ERROR");
wbeaumont 1:d175631a5803 637 }
kstokely 7:e649bb2b6187 638 }
kstokely 11:4367b8eefa6c 639
kstokely 11:4367b8eefa6c 640 else if( c == '<' )
kstokely 11:4367b8eefa6c 641 {
kstokely 11:4367b8eefa6c 642 //pc.printf("Interrupts Disabled \n\r");
kstokely 11:4367b8eefa6c 643 TrigInt.disable_irq();
kstokely 11:4367b8eefa6c 644 }
kstokely 11:4367b8eefa6c 645
kstokely 11:4367b8eefa6c 646 else if( c == '>' )
kstokely 11:4367b8eefa6c 647 {
kstokely 11:4367b8eefa6c 648 //pc.printf("Interrupts Enabled \n\r");
kstokely 11:4367b8eefa6c 649 TrigInt.enable_irq();
kstokely 11:4367b8eefa6c 650
kstokely 11:4367b8eefa6c 651 }
kstokely 10:bf195171d850 652
kstokely 11:4367b8eefa6c 653 else if( c == 'q')
kstokely 11:4367b8eefa6c 654 {
kstokely 11:4367b8eefa6c 655 //Query trigger
kstokely 11:4367b8eefa6c 656 if( trigSet == 1)
kstokely 11:4367b8eefa6c 657 {
kstokely 11:4367b8eefa6c 658 trigSet = 0;
kstokely 11:4367b8eefa6c 659 pc.printf("Yy\n\r");
kstokely 11:4367b8eefa6c 660 }
kstokely 11:4367b8eefa6c 661 else
kstokely 11:4367b8eefa6c 662 {
kstokely 11:4367b8eefa6c 663 trigSet = 0;
kstokely 11:4367b8eefa6c 664 pc.printf("Nn\n\r");
kstokely 11:4367b8eefa6c 665 }
kstokely 11:4367b8eefa6c 666 }
kstokely 11:4367b8eefa6c 667
kstokely 11:4367b8eefa6c 668
kstokely 10:bf195171d850 669 else if( c == 't')
kstokely 10:bf195171d850 670 {
kstokely 11:4367b8eefa6c 671
kstokely 11:4367b8eefa6c 672 extTrigHandler();
kstokely 11:4367b8eefa6c 673
kstokely 11:4367b8eefa6c 674 }
kstokely 11:4367b8eefa6c 675
wbeaumont 1:d175631a5803 676
kstokely 11:4367b8eefa6c 677 else if( c == 'S')
kstokely 11:4367b8eefa6c 678 {
kstokely 11:4367b8eefa6c 679 DVOA1 = atoi( pcstr.substr( indexArr[i] +2, indexArr[i] + 5).c_str() );
kstokely 11:4367b8eefa6c 680 DVOA2 = atoi( pcstr.substr( indexArr[i] +6, indexArr[i] + 9).c_str() );
kstokely 11:4367b8eefa6c 681 DVOA3 = atoi( pcstr.substr( indexArr[i] +10, indexArr[i] + 13).c_str() );
kstokely 11:4367b8eefa6c 682 DVOA4 = atoi( pcstr.substr( indexArr[i] +14, indexArr[i] + 17).c_str() );
kstokely 11:4367b8eefa6c 683
kstokely 10:bf195171d850 684 }
kstokely 11:4367b8eefa6c 685
kstokely 11:4367b8eefa6c 686
kstokely 11:4367b8eefa6c 687
kstokely 10:bf195171d850 688 else if( c == 's' )
kstokely 10:bf195171d850 689 {
kstokely 10:bf195171d850 690 seqstr = pcstr.substr( indexArr[i] +2, indexArr[i+1] -1 );
kstokely 11:4367b8eefa6c 691 //pc.printf("String is %s \n",seqstr.c_str());
kstokely 10:bf195171d850 692 }
kstokely 11:4367b8eefa6c 693
kstokely 11:4367b8eefa6c 694
kstokely 10:bf195171d850 695 else if( c == ';')
kstokely 10:bf195171d850 696 {
kstokely 10:bf195171d850 697 //Dumb states of everything out
kstokely 10:bf195171d850 698 //All on one line
kstokely 11:4367b8eefa6c 699
kstokely 10:bf195171d850 700 //Shutters
kstokely 10:bf195171d850 701 pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d",Shut1,Shut2,Shut3,Shut4,mRefShutters.read());
kstokely 11:4367b8eefa6c 702
kstokely 10:bf195171d850 703 //DAC
kstokely 10:bf195171d850 704 int CH1cnt;
kstokely 10:bf195171d850 705 int CH2cnt;
kstokely 10:bf195171d850 706 int CH3cnt;
kstokely 10:bf195171d850 707 int CH4cnt;
kstokely 11:4367b8eefa6c 708
kstokely 10:bf195171d850 709 //Print State of DAC
kstokely 10:bf195171d850 710 int sts = dac.update();
kstokely 10:bf195171d850 711 int updatecnt = 0;
kstokely 11:4367b8eefa6c 712
kstokely 11:4367b8eefa6c 713
kstokely 10:bf195171d850 714 while( sts != 0 && updatecnt < 5)
kstokely 11:4367b8eefa6c 715 {
kstokely 10:bf195171d850 716 if(sts != 0)
kstokely 10:bf195171d850 717 {
kstokely 10:bf195171d850 718 sts = dac.update();
kstokely 10:bf195171d850 719 updatecnt++;
kstokely 11:4367b8eefa6c 720
kstokely 10:bf195171d850 721 }
kstokely 10:bf195171d850 722 }
kstokely 11:4367b8eefa6c 723
kstokely 10:bf195171d850 724 if( updatecnt >= 5)
kstokely 10:bf195171d850 725 {
kstokely 10:bf195171d850 726 pc.printf("CH1:xxxx CH2:xxxx CH3:xxxx CH4:xxxx");
kstokely 10:bf195171d850 727 }
kstokely 10:bf195171d850 728 else
kstokely 10:bf195171d850 729 {
kstokely 10:bf195171d850 730 (void)dac.getDACvalue(CH1cnt,0);
kstokely 10:bf195171d850 731 (void)dac.getDACvalue(CH2cnt,1);
kstokely 10:bf195171d850 732 (void)dac.getDACvalue(CH3cnt,2);
kstokely 10:bf195171d850 733 (void)dac.getDACvalue(CH4cnt,3);
kstokely 10:bf195171d850 734 pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
kstokely 10:bf195171d850 735 }
kstokely 11:4367b8eefa6c 736
kstokely 10:bf195171d850 737 //Piping
kstokely 10:bf195171d850 738 pc.printf("4x4:%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() );
kstokely 10:bf195171d850 739 pc.printf("4x5:%d%d%d%d%d\n", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() );
kstokely 10:bf195171d850 740 }
kstokely 11:4367b8eefa6c 741
kstokely 10:bf195171d850 742 else if( c == '+' )
kstokely 10:bf195171d850 743 {
kstokely 10:bf195171d850 744 pc.printf(",[%d%d%d%d%d,]%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read(), m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() );
kstokely 10:bf195171d850 745 pc.printf(",m%d%d%d%d",Shut1,Shut2,Shut3,Shut4);
kstokely 10:bf195171d850 746 int CH1cnt;
kstokely 10:bf195171d850 747 int CH2cnt;
kstokely 10:bf195171d850 748 int CH3cnt;
kstokely 10:bf195171d850 749 int CH4cnt;
kstokely 11:4367b8eefa6c 750
kstokely 10:bf195171d850 751 int sts = dac.update();
kstokely 10:bf195171d850 752 int updatecnt = 0;
kstokely 11:4367b8eefa6c 753
kstokely 11:4367b8eefa6c 754
kstokely 10:bf195171d850 755 while( sts != 0 && updatecnt < 5)
kstokely 10:bf195171d850 756 {
kstokely 11:4367b8eefa6c 757
kstokely 10:bf195171d850 758 if(sts != 0)
kstokely 10:bf195171d850 759 {
kstokely 10:bf195171d850 760 sts = dac.update();
kstokely 10:bf195171d850 761 updatecnt++;
kstokely 11:4367b8eefa6c 762
kstokely 10:bf195171d850 763 }
kstokely 11:4367b8eefa6c 764
kstokely 10:bf195171d850 765 }
kstokely 10:bf195171d850 766 if( updatecnt >= 5 && sts != 0)
kstokely 10:bf195171d850 767 {
kstokely 10:bf195171d850 768 pc.printf(",.0xxxx,.1xxxx,.2xxxx,.3xxxx\n");
kstokely 10:bf195171d850 769 }
kstokely 10:bf195171d850 770 else
kstokely 10:bf195171d850 771 {
kstokely 10:bf195171d850 772 (void)dac.getDACvalue(CH1cnt,0);
kstokely 10:bf195171d850 773 (void)dac.getDACvalue(CH2cnt,1);
kstokely 10:bf195171d850 774 (void)dac.getDACvalue(CH3cnt,2);
kstokely 10:bf195171d850 775 (void)dac.getDACvalue(CH4cnt,3);
kstokely 10:bf195171d850 776 pc.printf(",.0%04d,.1%04d,.2%04d,.3%04d\n",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
kstokely 10:bf195171d850 777 }
kstokely 11:4367b8eefa6c 778
kstokely 10:bf195171d850 779 }
kstokely 11:4367b8eefa6c 780
kstokely 10:bf195171d850 781 }
kstokely 11:4367b8eefa6c 782
kstokely 11:4367b8eefa6c 783 }
kstokely 8:abdd660056fb 784 //Never Reach This
kstokely 8:abdd660056fb 785 return 1;
kstokely 11:4367b8eefa6c 786 }