![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2
Dependencies: mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces
main.cpp@8:abdd660056fb, 2019-02-20 (annotated)
- Committer:
- kstokely
- Date:
- Wed Feb 20 14:53:58 2019 +0000
- Revision:
- 8:abdd660056fb
- Parent:
- 7:e649bb2b6187
- Child:
- 9:2d70aa45f16e
Clone from MCP4728 Test 2-20-19;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 1:d175631a5803 | 1 | /** example program for the use of the MCP4728 class and DACInterface.h classes |
wbeaumont | 1:d175631a5803 | 2 | * |
wbeaumont | 1:d175631a5803 | 3 | * V 1.0 : tested on the KL05z but without the MCP4728 connected \ |
wbeaumont | 1:d175631a5803 | 4 | * (C) Wim Beaumont Universiteit Antwerpen 2016 |
wbeaumont | 1:d175631a5803 | 5 | */ |
wbeaumont | 1:d175631a5803 | 6 | |
wbeaumont | 3:e12e21dcd16a | 7 | #define MCP4728EXAMPLEVER "2.04" |
kstokely | 7:e649bb2b6187 | 8 | #define TARGET_MBED 1 |
wbeaumont | 1:d175631a5803 | 9 | |
wbeaumont | 0:5bc0f4bd5aa0 | 10 | #include "mbed.h" |
kstokely | 7:e649bb2b6187 | 11 | #include <string> |
wbeaumont | 0:5bc0f4bd5aa0 | 12 | |
wbeaumont | 0:5bc0f4bd5aa0 | 13 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 14 | PinName const SDA = PTE25; |
wbeaumont | 0:5bc0f4bd5aa0 | 15 | PinName const SCL = PTE24; |
wbeaumont | 0:5bc0f4bd5aa0 | 16 | #elif defined (TARGET_KL05Z) |
wbeaumont | 0:5bc0f4bd5aa0 | 17 | PinName const SDA = PTB4; |
wbeaumont | 0:5bc0f4bd5aa0 | 18 | PinName const SCL = PTB3; |
wbeaumont | 0:5bc0f4bd5aa0 | 19 | #elif defined (TARGET_K20D50M) |
wbeaumont | 0:5bc0f4bd5aa0 | 20 | PinName const SDA = PTB1; |
wbeaumont | 0:5bc0f4bd5aa0 | 21 | PinName const SCL = PTB0; |
kstokely | 7:e649bb2b6187 | 22 | #elif defined (TARGET_MBED) |
kstokely | 7:e649bb2b6187 | 23 | PinName const SDA = p28; |
kstokely | 7:e649bb2b6187 | 24 | PinName const SCL = p27; |
wbeaumont | 0:5bc0f4bd5aa0 | 25 | #else |
wbeaumont | 0:5bc0f4bd5aa0 | 26 | #error TARGET NOT DEFINED |
wbeaumont | 0:5bc0f4bd5aa0 | 27 | #endif |
wbeaumont | 0:5bc0f4bd5aa0 | 28 | |
wbeaumont | 0:5bc0f4bd5aa0 | 29 | |
wbeaumont | 0:5bc0f4bd5aa0 | 30 | #include "I2C.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 31 | #include "I2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 32 | #include "MBEDI2CInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 33 | #include "DACInterface.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 34 | #include "dev_interface_def.h" |
wbeaumont | 3:e12e21dcd16a | 35 | #include "MCP4728setaddr.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 36 | #include "mcp4728.h" |
wbeaumont | 0:5bc0f4bd5aa0 | 37 | |
kstokely | 7:e649bb2b6187 | 38 | #include "shutter.h" |
kstokely | 7:e649bb2b6187 | 39 | |
wbeaumont | 0:5bc0f4bd5aa0 | 40 | MBEDI2CInterface mbedi2c( SDA, SCL); |
wbeaumont | 0:5bc0f4bd5aa0 | 41 | MBEDI2CInterface* mbedi2cp= &mbedi2c ; |
wbeaumont | 0:5bc0f4bd5aa0 | 42 | I2CInterface* i2cdev= mbedi2cp; |
kstokely | 7:e649bb2b6187 | 43 | const float Vdd = 4.97; |
wbeaumont | 3:e12e21dcd16a | 44 | |
kstokely | 7:e649bb2b6187 | 45 | DigitalOut LDAC(p5); |
kstokely | 7:e649bb2b6187 | 46 | DigitalOut CntPin(p6); |
kstokely | 7:e649bb2b6187 | 47 | |
wbeaumont | 3:e12e21dcd16a | 48 | |
wbeaumont | 0:5bc0f4bd5aa0 | 49 | |
wbeaumont | 0:5bc0f4bd5aa0 | 50 | Serial pc(USBTX, USBRX); |
wbeaumont | 0:5bc0f4bd5aa0 | 51 | |
kstokely | 7:e649bb2b6187 | 52 | |
kstokely | 7:e649bb2b6187 | 53 | //Pins for 4x4 Module |
kstokely | 7:e649bb2b6187 | 54 | |
kstokely | 7:e649bb2b6187 | 55 | DigitalOut m4x4TTL1(p21); |
kstokely | 7:e649bb2b6187 | 56 | DigitalOut m4x4TTL2(p22); |
kstokely | 7:e649bb2b6187 | 57 | DigitalOut m4x4TTL3(p23); |
kstokely | 7:e649bb2b6187 | 58 | DigitalOut m4x4TTL4(p24); |
kstokely | 7:e649bb2b6187 | 59 | DigitalOut m4x4TTL5(p25); |
kstokely | 7:e649bb2b6187 | 60 | |
kstokely | 7:e649bb2b6187 | 61 | DigitalOut m4x4CLK(p26); //CLk for triggering after new input |
kstokely | 7:e649bb2b6187 | 62 | |
kstokely | 7:e649bb2b6187 | 63 | |
kstokely | 7:e649bb2b6187 | 64 | //Pins for 4x5 Module |
kstokely | 7:e649bb2b6187 | 65 | |
kstokely | 7:e649bb2b6187 | 66 | DigitalOut m4x5TTL1(p7); |
kstokely | 7:e649bb2b6187 | 67 | DigitalOut m4x5TTL2(p8); |
kstokely | 7:e649bb2b6187 | 68 | DigitalOut m4x5TTL3(p9); |
kstokely | 7:e649bb2b6187 | 69 | DigitalOut m4x5TTL4(p10); |
kstokely | 7:e649bb2b6187 | 70 | DigitalOut m4x5TTL5(p11); |
kstokely | 7:e649bb2b6187 | 71 | |
kstokely | 7:e649bb2b6187 | 72 | //Shutter Pins |
kstokely | 7:e649bb2b6187 | 73 | DigitalOut SH1_1(p12); |
kstokely | 7:e649bb2b6187 | 74 | DigitalOut SH1_2(p13); |
kstokely | 7:e649bb2b6187 | 75 | DigitalOut SH2_1(p14); |
kstokely | 7:e649bb2b6187 | 76 | DigitalOut SH2_2(p15); |
kstokely | 7:e649bb2b6187 | 77 | DigitalOut SH3_1(p16); |
kstokely | 7:e649bb2b6187 | 78 | DigitalOut SH3_2(p17); |
kstokely | 7:e649bb2b6187 | 79 | DigitalOut SH4_1(p18); |
kstokely | 7:e649bb2b6187 | 80 | DigitalOut SH4_2(p19); |
kstokely | 7:e649bb2b6187 | 81 | |
kstokely | 7:e649bb2b6187 | 82 | DigitalOut m4x5CLK(p20); |
kstokely | 7:e649bb2b6187 | 83 | |
kstokely | 8:abdd660056fb | 84 | DigitalOut mRefShutters(p30); |
kstokely | 8:abdd660056fb | 85 | |
kstokely | 8:abdd660056fb | 86 | bool Shut1 = 0; |
kstokely | 8:abdd660056fb | 87 | bool Shut2 = 0; |
kstokely | 8:abdd660056fb | 88 | bool Shut3 = 0; |
kstokely | 8:abdd660056fb | 89 | bool Shut4 = 0; |
kstokely | 8:abdd660056fb | 90 | |
kstokely | 8:abdd660056fb | 91 | |
kstokely | 8:abdd660056fb | 92 | |
kstokely | 8:abdd660056fb | 93 | |
kstokely | 8:abdd660056fb | 94 | int DACSetChannel( int chan, MCP4728* dac) |
kstokely | 8:abdd660056fb | 95 | { |
kstokely | 8:abdd660056fb | 96 | int ret = 0; |
kstokely | 8:abdd660056fb | 97 | char z; |
kstokely | 8:abdd660056fb | 98 | float voltage = 0; |
kstokely | 8:abdd660056fb | 99 | string instr; |
kstokely | 8:abdd660056fb | 100 | |
kstokely | 8:abdd660056fb | 101 | printf("\n\rEnter Voltage \n\r"); |
kstokely | 8:abdd660056fb | 102 | while (ret == 0) |
kstokely | 8:abdd660056fb | 103 | { |
kstokely | 8:abdd660056fb | 104 | |
kstokely | 8:abdd660056fb | 105 | z = pc.getc(); |
kstokely | 8:abdd660056fb | 106 | |
kstokely | 8:abdd660056fb | 107 | |
kstokely | 8:abdd660056fb | 108 | if( z == 13 ) |
kstokely | 8:abdd660056fb | 109 | { |
kstokely | 8:abdd660056fb | 110 | voltage = atof( instr.c_str() ); |
kstokely | 8:abdd660056fb | 111 | |
kstokely | 8:abdd660056fb | 112 | if( voltage > Vdd || voltage < 0) |
kstokely | 8:abdd660056fb | 113 | { |
kstokely | 8:abdd660056fb | 114 | pc.printf("\n\r Voltage Entered Higher than Vdd Setting Voltage to Maximum\n\r"); |
kstokely | 8:abdd660056fb | 115 | } |
kstokely | 8:abdd660056fb | 116 | else |
kstokely | 8:abdd660056fb | 117 | { |
kstokely | 8:abdd660056fb | 118 | if ( dac->setVoltage(voltage,chan) ) |
kstokely | 8:abdd660056fb | 119 | { |
kstokely | 8:abdd660056fb | 120 | printf("failed to set dac value %f for channel %d\n\r",voltage,chan); |
kstokely | 8:abdd660056fb | 121 | } |
kstokely | 8:abdd660056fb | 122 | //pc.printf("Voltage set to %3fV\n\r", voltage); |
kstokely | 8:abdd660056fb | 123 | if( dac->update() ) |
kstokely | 8:abdd660056fb | 124 | { |
kstokely | 8:abdd660056fb | 125 | printf("\n\rfailed to readback channel info \n\r"); |
kstokely | 8:abdd660056fb | 126 | } |
kstokely | 8:abdd660056fb | 127 | else |
kstokely | 8:abdd660056fb | 128 | { |
kstokely | 8:abdd660056fb | 129 | (void)dac->getVoltage(voltage,chan);//no need to test done with updat |
kstokely | 8:abdd660056fb | 130 | printf(" CH%d %f[V]",chan,voltage); |
kstokely | 8:abdd660056fb | 131 | printf("\n\r"); |
kstokely | 8:abdd660056fb | 132 | |
kstokely | 8:abdd660056fb | 133 | } |
kstokely | 8:abdd660056fb | 134 | |
kstokely | 8:abdd660056fb | 135 | } |
kstokely | 8:abdd660056fb | 136 | |
kstokely | 8:abdd660056fb | 137 | instr.clear(); |
kstokely | 8:abdd660056fb | 138 | ret = 1; |
kstokely | 8:abdd660056fb | 139 | } |
kstokely | 8:abdd660056fb | 140 | else |
kstokely | 8:abdd660056fb | 141 | { |
kstokely | 8:abdd660056fb | 142 | pc.printf("%c",z); |
kstokely | 8:abdd660056fb | 143 | instr.push_back(z); |
kstokely | 8:abdd660056fb | 144 | } |
kstokely | 8:abdd660056fb | 145 | } |
kstokely | 8:abdd660056fb | 146 | return 1; |
kstokely | 8:abdd660056fb | 147 | } |
kstokely | 8:abdd660056fb | 148 | |
kstokely | 7:e649bb2b6187 | 149 | |
kstokely | 7:e649bb2b6187 | 150 | |
kstokely | 7:e649bb2b6187 | 151 | |
kstokely | 7:e649bb2b6187 | 152 | |
kstokely | 7:e649bb2b6187 | 153 | |
wbeaumont | 0:5bc0f4bd5aa0 | 154 | int main(void) { |
wbeaumont | 0:5bc0f4bd5aa0 | 155 | |
wbeaumont | 0:5bc0f4bd5aa0 | 156 | // get the version of getVersion |
wbeaumont | 0:5bc0f4bd5aa0 | 157 | getVersion gv; |
wbeaumont | 3:e12e21dcd16a | 158 | int addr; |
wbeaumont | 6:d1e569f370ac | 159 | |
kstokely | 7:e649bb2b6187 | 160 | addr = 0; |
wbeaumont | 3:e12e21dcd16a | 161 | MCP4728 dac( i2cdev ,addr, Vdd); // assuming the address of the MCP4728 is set to 0 factory default |
wbeaumont | 3:e12e21dcd16a | 162 | printf("\n\raddr %d MCP4728 :%s\n\r",addr,dac.getversioninfo()); |
wbeaumont | 3:e12e21dcd16a | 163 | wait(1); |
kstokely | 7:e649bb2b6187 | 164 | |
wbeaumont | 0:5bc0f4bd5aa0 | 165 | int cnt=0; |
kstokely | 7:e649bb2b6187 | 166 | |
kstokely | 8:abdd660056fb | 167 | mRefShutters = 1; |
kstokely | 7:e649bb2b6187 | 168 | |
kstokely | 7:e649bb2b6187 | 169 | |
kstokely | 7:e649bb2b6187 | 170 | |
kstokely | 7:e649bb2b6187 | 171 | pc.printf("Agiltron Serial Control Program\n\r"); |
kstokely | 8:abdd660056fb | 172 | pc.printf("'[' 4x4 Swtiching \n\r"); |
kstokely | 8:abdd660056fb | 173 | pc.printf("']' 4x5 Swtiching\n\r"); |
kstokely | 8:abdd660056fb | 174 | pc.printf("1, 2, 3, 4 Toggle Single Shutters\n\r"); |
kstokely | 8:abdd660056fb | 175 | pc.printf("'o' Opens all Shutters\n\r"); |
kstokely | 8:abdd660056fb | 176 | pc.printf("'r' Closes all Shutters \n\r"); |
kstokely | 8:abdd660056fb | 177 | pc.printf("',' 4 Channel DAC Control \n\r"); |
kstokely | 8:abdd660056fb | 178 | pc.printf("'.' Single Channel DAC Control \n\r"); |
kstokely | 7:e649bb2b6187 | 179 | |
kstokely | 7:e649bb2b6187 | 180 | //Set up dac for external voltage |
kstokely | 7:e649bb2b6187 | 181 | dac.setRefExtern(); |
kstokely | 7:e649bb2b6187 | 182 | dac.update(); |
kstokely | 7:e649bb2b6187 | 183 | |
kstokely | 7:e649bb2b6187 | 184 | //Intialize shutters |
kstokely | 7:e649bb2b6187 | 185 | Shutter SH; |
kstokely | 7:e649bb2b6187 | 186 | SH.init( &SH1_1, &SH1_2, &SH2_1, &SH2_2, &SH3_1, &SH3_2, &SH4_1, &SH4_2 ); |
kstokely | 8:abdd660056fb | 187 | |
kstokely | 7:e649bb2b6187 | 188 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 189 | |
kstokely | 7:e649bb2b6187 | 190 | |
kstokely | 7:e649bb2b6187 | 191 | //TTL pin arrays |
kstokely | 7:e649bb2b6187 | 192 | DigitalOut* Arr_4x4[5] = {&m4x4TTL1, &m4x4TTL2, &m4x4TTL3, &m4x4TTL4, &m4x4TTL5 }; |
kstokely | 7:e649bb2b6187 | 193 | DigitalOut* Arr_4x5[5] = {&m4x5TTL1, &m4x5TTL2, &m4x5TTL3, &m4x5TTL4, &m4x5TTL5 }; |
kstokely | 7:e649bb2b6187 | 194 | |
kstokely | 7:e649bb2b6187 | 195 | |
kstokely | 8:abdd660056fb | 196 | //Set straight pipes initial state |
kstokely | 7:e649bb2b6187 | 197 | m4x5TTL1 = 1; |
kstokely | 7:e649bb2b6187 | 198 | |
kstokely | 7:e649bb2b6187 | 199 | m4x4TTL1 = 1; |
kstokely | 7:e649bb2b6187 | 200 | float voltage = 0; |
kstokely | 7:e649bb2b6187 | 201 | string instr; |
kstokely | 7:e649bb2b6187 | 202 | |
kstokely | 7:e649bb2b6187 | 203 | while(1) |
kstokely | 7:e649bb2b6187 | 204 | { |
kstokely | 7:e649bb2b6187 | 205 | char c = pc.getc(); |
kstokely | 7:e649bb2b6187 | 206 | |
kstokely | 7:e649bb2b6187 | 207 | if( c == '1') //Toggle Shutter 1 |
kstokely | 7:e649bb2b6187 | 208 | { |
kstokely | 7:e649bb2b6187 | 209 | Shut1 = !Shut1; |
kstokely | 7:e649bb2b6187 | 210 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 211 | } |
kstokely | 7:e649bb2b6187 | 212 | |
kstokely | 7:e649bb2b6187 | 213 | else if( c == '2') //Toggle Shutter 2 |
kstokely | 7:e649bb2b6187 | 214 | { |
kstokely | 7:e649bb2b6187 | 215 | Shut2 = !Shut2; |
kstokely | 7:e649bb2b6187 | 216 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 217 | } |
kstokely | 7:e649bb2b6187 | 218 | |
kstokely | 7:e649bb2b6187 | 219 | else if( c == '3') //Toggle Shutter 3 |
kstokely | 7:e649bb2b6187 | 220 | { |
kstokely | 7:e649bb2b6187 | 221 | Shut3 = !Shut3; |
kstokely | 7:e649bb2b6187 | 222 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 223 | } |
kstokely | 7:e649bb2b6187 | 224 | |
kstokely | 7:e649bb2b6187 | 225 | else if( c == '4') //Toggle Shutter 4 |
kstokely | 7:e649bb2b6187 | 226 | { |
kstokely | 7:e649bb2b6187 | 227 | Shut4 = !Shut4; |
kstokely | 7:e649bb2b6187 | 228 | SH.writeShutters(Shut1,Shut2,Shut3,Shut4); |
kstokely | 7:e649bb2b6187 | 229 | } |
kstokely | 7:e649bb2b6187 | 230 | |
kstokely | 8:abdd660056fb | 231 | else if( c == 'u') |
kstokely | 8:abdd660056fb | 232 | { |
kstokely | 8:abdd660056fb | 233 | mRefShutters = 0; |
kstokely | 8:abdd660056fb | 234 | } |
kstokely | 7:e649bb2b6187 | 235 | |
kstokely | 8:abdd660056fb | 236 | else if( c == 'y') |
kstokely | 8:abdd660056fb | 237 | { |
kstokely | 8:abdd660056fb | 238 | mRefShutters = 1; |
kstokely | 8:abdd660056fb | 239 | } |
kstokely | 8:abdd660056fb | 240 | |
kstokely | 8:abdd660056fb | 241 | else if(c == 'o') //Open All Shutters |
kstokely | 8:abdd660056fb | 242 | { |
kstokely | 8:abdd660056fb | 243 | Shut1 = 1; |
kstokely | 8:abdd660056fb | 244 | Shut2 = 1; |
kstokely | 8:abdd660056fb | 245 | Shut3 = 1; |
kstokely | 8:abdd660056fb | 246 | Shut4 = 1; |
kstokely | 8:abdd660056fb | 247 | SH.writeShutters(1,1,1,1); |
kstokely | 8:abdd660056fb | 248 | } |
kstokely | 8:abdd660056fb | 249 | |
kstokely | 8:abdd660056fb | 250 | else if(c == 'r') //Close All Shutters |
kstokely | 8:abdd660056fb | 251 | { |
kstokely | 8:abdd660056fb | 252 | Shut1 = 0; |
kstokely | 8:abdd660056fb | 253 | Shut2 = 0; |
kstokely | 8:abdd660056fb | 254 | Shut3 = 0; |
kstokely | 8:abdd660056fb | 255 | Shut4 = 0; |
kstokely | 8:abdd660056fb | 256 | SH.writeShutters(0,0,0,0); |
kstokely | 8:abdd660056fb | 257 | } |
kstokely | 8:abdd660056fb | 258 | |
kstokely | 8:abdd660056fb | 259 | else if( c == 91 ) //Left square bracket [ 4x4 Control |
kstokely | 7:e649bb2b6187 | 260 | { |
kstokely | 7:e649bb2b6187 | 261 | //Get 5 1's or 0's for binary number |
kstokely | 7:e649bb2b6187 | 262 | int count = 0; |
kstokely | 7:e649bb2b6187 | 263 | pc.printf("4x4 Control: Enter 5 digit binary number\n\r"); |
kstokely | 7:e649bb2b6187 | 264 | while ( count < 5 ) |
kstokely | 7:e649bb2b6187 | 265 | { |
kstokely | 7:e649bb2b6187 | 266 | c = pc.getc(); |
kstokely | 7:e649bb2b6187 | 267 | |
kstokely | 7:e649bb2b6187 | 268 | if( c == '1' || c=='0' ) |
kstokely | 7:e649bb2b6187 | 269 | { |
kstokely | 7:e649bb2b6187 | 270 | *Arr_4x4[count] = atoi(&c); |
kstokely | 7:e649bb2b6187 | 271 | count++; |
kstokely | 7:e649bb2b6187 | 272 | } |
wbeaumont | 0:5bc0f4bd5aa0 | 273 | } |
kstokely | 7:e649bb2b6187 | 274 | |
kstokely | 7:e649bb2b6187 | 275 | for( int k = 0; k<5; k++) //Trigger clocking to change values |
kstokely | 7:e649bb2b6187 | 276 | { |
kstokely | 7:e649bb2b6187 | 277 | m4x4CLK = 1; |
kstokely | 7:e649bb2b6187 | 278 | wait(0.1); |
kstokely | 7:e649bb2b6187 | 279 | m4x4CLK = 0; |
kstokely | 7:e649bb2b6187 | 280 | } |
kstokely | 7:e649bb2b6187 | 281 | |
kstokely | 7:e649bb2b6187 | 282 | 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 | 7:e649bb2b6187 | 283 | } |
kstokely | 7:e649bb2b6187 | 284 | |
kstokely | 7:e649bb2b6187 | 285 | |
kstokely | 7:e649bb2b6187 | 286 | |
kstokely | 8:abdd660056fb | 287 | else if( c == 93 ) //Right square bracket ] 4x5 Control |
kstokely | 7:e649bb2b6187 | 288 | { |
kstokely | 7:e649bb2b6187 | 289 | //Get 5 1's or 0's for binary number |
kstokely | 7:e649bb2b6187 | 290 | int count = 0; |
kstokely | 7:e649bb2b6187 | 291 | pc.printf("4x5 Control: Enter 5 digit binary number\n\r"); |
kstokely | 7:e649bb2b6187 | 292 | while ( count < 5 ) |
kstokely | 7:e649bb2b6187 | 293 | { |
kstokely | 7:e649bb2b6187 | 294 | c = pc.getc(); |
kstokely | 7:e649bb2b6187 | 295 | |
kstokely | 7:e649bb2b6187 | 296 | if( c == '1' || c=='0' ) |
kstokely | 7:e649bb2b6187 | 297 | { |
kstokely | 7:e649bb2b6187 | 298 | *Arr_4x5[count] = atoi(&c); |
kstokely | 7:e649bb2b6187 | 299 | count++; |
kstokely | 7:e649bb2b6187 | 300 | } |
kstokely | 7:e649bb2b6187 | 301 | } |
kstokely | 7:e649bb2b6187 | 302 | |
kstokely | 7:e649bb2b6187 | 303 | for( int k = 0; k<5; k++) //Trigger clocking to change values |
kstokely | 7:e649bb2b6187 | 304 | { |
kstokely | 7:e649bb2b6187 | 305 | m4x5CLK = 1; |
kstokely | 7:e649bb2b6187 | 306 | wait(0.1); |
kstokely | 7:e649bb2b6187 | 307 | m4x5CLK = 0; |
kstokely | 7:e649bb2b6187 | 308 | } |
kstokely | 7:e649bb2b6187 | 309 | |
kstokely | 7:e649bb2b6187 | 310 | 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 | 7:e649bb2b6187 | 311 | } |
kstokely | 7:e649bb2b6187 | 312 | |
kstokely | 8:abdd660056fb | 313 | else if( c == ',' ) //4 Channel DAC Control |
kstokely | 7:e649bb2b6187 | 314 | { |
kstokely | 8:abdd660056fb | 315 | pc.printf("4 Channel DAC Control Enter voltage and Press Enter\n\r"); |
kstokely | 8:abdd660056fb | 316 | int ret = 0; |
kstokely | 8:abdd660056fb | 317 | int chan = 0; |
kstokely | 8:abdd660056fb | 318 | while( ret ==0 && chan < 4) |
kstokely | 7:e649bb2b6187 | 319 | { |
kstokely | 8:abdd660056fb | 320 | char z = pc.getc(); |
kstokely | 8:abdd660056fb | 321 | if( z == 13 ) |
kstokely | 8:abdd660056fb | 322 | { |
kstokely | 8:abdd660056fb | 323 | voltage = atof( instr.c_str() ); |
kstokely | 8:abdd660056fb | 324 | |
kstokely | 8:abdd660056fb | 325 | if( voltage == 0 || voltage > 5.0 ) |
kstokely | 8:abdd660056fb | 326 | { |
kstokely | 8:abdd660056fb | 327 | pc.printf("ERROR\n\r"); |
kstokely | 8:abdd660056fb | 328 | } |
kstokely | 8:abdd660056fb | 329 | else |
kstokely | 8:abdd660056fb | 330 | { |
kstokely | 8:abdd660056fb | 331 | if ( dac.setVoltage(voltage,chan) ) |
kstokely | 8:abdd660056fb | 332 | { |
kstokely | 8:abdd660056fb | 333 | printf("failed to set dac value %d for channel %d\n\r",cnt,chan); |
kstokely | 8:abdd660056fb | 334 | } |
kstokely | 8:abdd660056fb | 335 | //pc.printf("Voltage set to %3fV\n\r", voltage); |
kstokely | 8:abdd660056fb | 336 | if( dac.update() ) |
kstokely | 8:abdd660056fb | 337 | { |
kstokely | 8:abdd660056fb | 338 | printf("\n\rfailed to readback channel info \n\r"); |
kstokely | 8:abdd660056fb | 339 | } |
kstokely | 8:abdd660056fb | 340 | else |
kstokely | 8:abdd660056fb | 341 | { |
kstokely | 8:abdd660056fb | 342 | (void)dac.getVoltage(voltage,chan);//no need to test done with updat |
kstokely | 8:abdd660056fb | 343 | printf(" CH%d %f[V]",chan,voltage); |
kstokely | 8:abdd660056fb | 344 | printf("\n\r"); |
kstokely | 8:abdd660056fb | 345 | chan++; |
kstokely | 8:abdd660056fb | 346 | } |
kstokely | 8:abdd660056fb | 347 | |
kstokely | 8:abdd660056fb | 348 | } |
kstokely | 8:abdd660056fb | 349 | if( chan == 4) |
kstokely | 8:abdd660056fb | 350 | { |
kstokely | 8:abdd660056fb | 351 | ret = 1; |
kstokely | 8:abdd660056fb | 352 | wait_ms(100); |
kstokely | 8:abdd660056fb | 353 | } |
kstokely | 8:abdd660056fb | 354 | instr.clear(); |
kstokely | 8:abdd660056fb | 355 | |
kstokely | 8:abdd660056fb | 356 | } |
kstokely | 8:abdd660056fb | 357 | |
kstokely | 8:abdd660056fb | 358 | else if( z == ']') |
kstokely | 8:abdd660056fb | 359 | { |
kstokely | 8:abdd660056fb | 360 | for ( int cc =0 ; cc <4 ; cc++) |
kstokely | 8:abdd660056fb | 361 | { |
kstokely | 8:abdd660056fb | 362 | if ( dac.setDACvalue(4095,cc) ) |
kstokely | 8:abdd660056fb | 363 | { |
kstokely | 8:abdd660056fb | 364 | printf("failed to set dac value %d for channel %d\n\r",cnt,cc); |
kstokely | 8:abdd660056fb | 365 | } |
kstokely | 8:abdd660056fb | 366 | } |
kstokely | 8:abdd660056fb | 367 | printf("All Channels Set to 5V /n/r"); |
kstokely | 8:abdd660056fb | 368 | ret = 1; |
kstokely | 8:abdd660056fb | 369 | } |
kstokely | 8:abdd660056fb | 370 | |
kstokely | 8:abdd660056fb | 371 | else |
kstokely | 8:abdd660056fb | 372 | { |
kstokely | 8:abdd660056fb | 373 | pc.printf("%c",z); |
kstokely | 8:abdd660056fb | 374 | instr.push_back(z); |
kstokely | 8:abdd660056fb | 375 | } |
kstokely | 8:abdd660056fb | 376 | } |
kstokely | 8:abdd660056fb | 377 | } |
kstokely | 8:abdd660056fb | 378 | |
kstokely | 8:abdd660056fb | 379 | |
kstokely | 8:abdd660056fb | 380 | else if( c == '.' ) //Single Channel DAC Control |
kstokely | 8:abdd660056fb | 381 | { |
kstokely | 8:abdd660056fb | 382 | pc.printf("Single Channel DAC Control Press Channel Number\n\r"); |
kstokely | 8:abdd660056fb | 383 | char z = pc.getc(); |
kstokely | 8:abdd660056fb | 384 | |
kstokely | 8:abdd660056fb | 385 | if( z == '1' || z== '2' || z == '3' || z == '4' ) |
kstokely | 8:abdd660056fb | 386 | { |
kstokely | 8:abdd660056fb | 387 | pc.printf("Channel %c Selected",z); |
kstokely | 8:abdd660056fb | 388 | DACSetChannel( atoi(&z) , &dac); |
kstokely | 8:abdd660056fb | 389 | } |
kstokely | 7:e649bb2b6187 | 390 | else |
kstokely | 7:e649bb2b6187 | 391 | { |
kstokely | 8:abdd660056fb | 392 | pc.printf("ERROR"); |
wbeaumont | 1:d175631a5803 | 393 | } |
kstokely | 7:e649bb2b6187 | 394 | } |
wbeaumont | 1:d175631a5803 | 395 | |
kstokely | 7:e649bb2b6187 | 396 | } |
kstokely | 8:abdd660056fb | 397 | //Never Reach This |
kstokely | 8:abdd660056fb | 398 | return 1; |
kstokely | 8:abdd660056fb | 399 | } |
kstokely | 8:abdd660056fb | 400 |