K Andres / Mbed 2 deprecated SCIboard

Dependencies:   mbed

Committer:
AstrodyneSystems
Date:
Wed Dec 18 17:43:09 2013 +0000
Revision:
4:09ffcb9bc1d3
Parent:
3:a0863e392562
Child:
5:dc778a682d29
Added MOSFET switches and ADC reading

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AstrodyneSystems 0:ab51d784ef36 1 /* SCIboard(TM) main.cpp
AstrodyneSystems 0:ab51d784ef36 2 Copyright (c) 2013 K. Andres
AstrodyneSystems 0:ab51d784ef36 3
AstrodyneSystems 0:ab51d784ef36 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AstrodyneSystems 0:ab51d784ef36 5 of this software and associated documentation files (the "Software"), to deal
AstrodyneSystems 0:ab51d784ef36 6 in the Software without restriction, including without limitation the rights
AstrodyneSystems 0:ab51d784ef36 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AstrodyneSystems 0:ab51d784ef36 8 copies of the Software, and to permit persons to whom the Software is
AstrodyneSystems 0:ab51d784ef36 9 furnished to do so, subject to the following conditions:
AstrodyneSystems 0:ab51d784ef36 10
AstrodyneSystems 0:ab51d784ef36 11 The above copyright notice and this permission notice shall be included in
AstrodyneSystems 0:ab51d784ef36 12 all copies or substantial portions of the Software.
AstrodyneSystems 0:ab51d784ef36 13
AstrodyneSystems 0:ab51d784ef36 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AstrodyneSystems 0:ab51d784ef36 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AstrodyneSystems 0:ab51d784ef36 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AstrodyneSystems 0:ab51d784ef36 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AstrodyneSystems 0:ab51d784ef36 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AstrodyneSystems 0:ab51d784ef36 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AstrodyneSystems 0:ab51d784ef36 20 THE SOFTWARE.
AstrodyneSystems 0:ab51d784ef36 21 */
AstrodyneSystems 0:ab51d784ef36 22
AstrodyneSystems 0:ab51d784ef36 23 /* OVERVIEW
AstrodyneSystems 1:a54c4a4f3b30 24 Displays on USB serial (9600 bps)
AstrodyneSystems 1:a54c4a4f3b30 25 MPL3115A2 ident 0xC4
AstrodyneSystems 1:a54c4a4f3b30 26 LSM303 ident 0x48 0x34 0x33
AstrodyneSystems 3:a0863e392562 27 L3G4200DTR ident 0xD3
AstrodyneSystems 0:ab51d784ef36 28 then collects 10 seconds of data from accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 29
AstrodyneSystems 0:ab51d784ef36 30 Filename on Local: OUTxx.csv (csv format allows easy import into spreadsheets)
AstrodyneSystems 0:ab51d784ef36 31 Format: microseconds,record type, variable length data\r\n
AstrodyneSystems 1:a54c4a4f3b30 32 Rec type 1= altimeter data altitude (meters) and semiconductor temperature (deg C)
AstrodyneSystems 0:ab51d784ef36 33 Rec type 2= accelerometer data x, y, and z in g's
AstrodyneSystems 3:a0863e392562 34 Rec type 3= magnetometer data x, y, and z
AstrodyneSystems 3:a0863e392562 35 Rec type 4= gyro data x, y, z in degrees per second (dps)
AstrodyneSystems 0:ab51d784ef36 36
AstrodyneSystems 3:a0863e392562 37 MOSFET switch software coming soon (under development)...
AstrodyneSystems 0:ab51d784ef36 38 */
AstrodyneSystems 0:ab51d784ef36 39
AstrodyneSystems 0:ab51d784ef36 40 #include "mbed.h"
AstrodyneSystems 0:ab51d784ef36 41 #include "math.h"
AstrodyneSystems 0:ab51d784ef36 42
AstrodyneSystems 0:ab51d784ef36 43 #include "SCIboard_I2C.h"
AstrodyneSystems 1:a54c4a4f3b30 44 #include "SCIboard_MPL3115A2.h"
AstrodyneSystems 0:ab51d784ef36 45 #include "SCIboard_LSM303DLHC.h"
AstrodyneSystems 3:a0863e392562 46 #include "SCIboard_L3G4200DTR.h"
AstrodyneSystems 4:09ffcb9bc1d3 47
AstrodyneSystems 0:ab51d784ef36 48 #include "SCIboard_DataLogger.h"
AstrodyneSystems 2:6698a2433bfd 49 #include "SCIboard_ConfigFile.h"
AstrodyneSystems 4:09ffcb9bc1d3 50 #include "SCIboard_MOSFET.h"
AstrodyneSystems 0:ab51d784ef36 51
AstrodyneSystems 0:ab51d784ef36 52 // LEDs
AstrodyneSystems 0:ab51d784ef36 53 DigitalOut led1(LED1);
AstrodyneSystems 0:ab51d784ef36 54 DigitalOut led2(LED2);
AstrodyneSystems 0:ab51d784ef36 55 DigitalOut led3(LED3);
AstrodyneSystems 0:ab51d784ef36 56 DigitalOut led4(LED4);
AstrodyneSystems 0:ab51d784ef36 57
AstrodyneSystems 0:ab51d784ef36 58 // PWM out
AstrodyneSystems 0:ab51d784ef36 59 PwmOut pwm1(p26);
AstrodyneSystems 0:ab51d784ef36 60 PwmOut pwm2(p25);
AstrodyneSystems 0:ab51d784ef36 61 PwmOut pwm3(p24);
AstrodyneSystems 0:ab51d784ef36 62 PwmOut pwm4(p23);
AstrodyneSystems 0:ab51d784ef36 63 PwmOut pwm5(p22);
AstrodyneSystems 0:ab51d784ef36 64 PwmOut pwm6(p21);
AstrodyneSystems 0:ab51d784ef36 65
AstrodyneSystems 0:ab51d784ef36 66 // Serial gps(p13, p14);
AstrodyneSystems 0:ab51d784ef36 67 // Serial Xbee(p9, p10);
AstrodyneSystems 0:ab51d784ef36 68
AstrodyneSystems 0:ab51d784ef36 69 // Buzzer
AstrodyneSystems 0:ab51d784ef36 70 DigitalOut alert(p29); // CAN_RD
AstrodyneSystems 0:ab51d784ef36 71
AstrodyneSystems 0:ab51d784ef36 72 // MOSFET controls
AstrodyneSystems 0:ab51d784ef36 73 DigitalOut fet_out1(p15); // ADC1
AstrodyneSystems 0:ab51d784ef36 74 DigitalOut fet_out2(p12); // SPI2_MISO
AstrodyneSystems 0:ab51d784ef36 75 DigitalOut fet_out3(p11); // SPI2_MOSI
AstrodyneSystems 0:ab51d784ef36 76 DigitalOut fet_out4(p8); // GPIO8
AstrodyneSystems 0:ab51d784ef36 77
AstrodyneSystems 0:ab51d784ef36 78 // ADC inputs
AstrodyneSystems 0:ab51d784ef36 79 AnalogIn batt_mon(p16); // ADC2
AstrodyneSystems 0:ab51d784ef36 80 AnalogIn fet_mon1(p17); // ADC3
AstrodyneSystems 0:ab51d784ef36 81 AnalogIn fet_mon2(p18); // ADC4
AstrodyneSystems 0:ab51d784ef36 82 AnalogIn fet_mon3(p19); // ADC5
AstrodyneSystems 0:ab51d784ef36 83 AnalogIn fet_mon4(p20); // ADC6
AstrodyneSystems 0:ab51d784ef36 84
AstrodyneSystems 0:ab51d784ef36 85 //
AstrodyneSystems 0:ab51d784ef36 86 Serial pc(USBTX, USBRX); // Default 9600 bps
AstrodyneSystems 0:ab51d784ef36 87
AstrodyneSystems 0:ab51d784ef36 88 // Timers
AstrodyneSystems 0:ab51d784ef36 89 Timer t;
AstrodyneSystems 0:ab51d784ef36 90 int time_ms;
AstrodyneSystems 0:ab51d784ef36 91
AstrodyneSystems 0:ab51d784ef36 92
AstrodyneSystems 0:ab51d784ef36 93 // I2C interface
AstrodyneSystems 0:ab51d784ef36 94 //#define sdaPin p9
AstrodyneSystems 0:ab51d784ef36 95 //#define sdcPin p10
AstrodyneSystems 0:ab51d784ef36 96 #define sdaPin p28
AstrodyneSystems 0:ab51d784ef36 97 #define sdcPin p27
AstrodyneSystems 0:ab51d784ef36 98
AstrodyneSystems 0:ab51d784ef36 99 SCIboard_I2C i2cBus(sdaPin, sdcPin);
AstrodyneSystems 0:ab51d784ef36 100
AstrodyneSystems 1:a54c4a4f3b30 101 // Altimeter
AstrodyneSystems 1:a54c4a4f3b30 102 SCIboard_MPL3115A2 alt(&i2cBus);
AstrodyneSystems 1:a54c4a4f3b30 103 InterruptIn MPL3115A2_INT1(p5);
AstrodyneSystems 1:a54c4a4f3b30 104 void MPL3115A2_INT1_INTERRUPT(void);
AstrodyneSystems 1:a54c4a4f3b30 105 //InterruptIn MPL3115A2_INT2();
AstrodyneSystems 1:a54c4a4f3b30 106
AstrodyneSystems 1:a54c4a4f3b30 107 const int accAltDecimate=5;
AstrodyneSystems 1:a54c4a4f3b30 108 int accCnt=0;
AstrodyneSystems 0:ab51d784ef36 109
AstrodyneSystems 3:a0863e392562 110
AstrodyneSystems 0:ab51d784ef36 111 // Accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 112 SCIboard_LSM303DLHC lsm303(&i2cBus);
AstrodyneSystems 0:ab51d784ef36 113 InterruptIn LSM303DLHC_DRDY(p7);
AstrodyneSystems 0:ab51d784ef36 114 void LSM303DLHC_DRDY_INTERRUPT(void);
AstrodyneSystems 0:ab51d784ef36 115 //InterruptIn LSM303DLHC_INT1(p6);
AstrodyneSystems 0:ab51d784ef36 116 //void LSM303DLHC_INT1_INTERRUPT(void);
AstrodyneSystems 0:ab51d784ef36 117 // INT2 n/c
AstrodyneSystems 0:ab51d784ef36 118
AstrodyneSystems 0:ab51d784ef36 119
AstrodyneSystems 3:a0863e392562 120 // Gyro
AstrodyneSystems 3:a0863e392562 121 SCIboard_L3G4200DTR l3g4200dtr(&i2cBus, GYR_DR_100HZ, GYR_BW_0, GYR_FS_250DPS);
AstrodyneSystems 3:a0863e392562 122 //InterruptIn L3G4200DTR_INT();
AstrodyneSystems 3:a0863e392562 123 //InterruptIn L3G4200DTR_DRDY(p24);
AstrodyneSystems 3:a0863e392562 124 //void L3G4200DTR_INTERRUPT(void);
AstrodyneSystems 3:a0863e392562 125
AstrodyneSystems 3:a0863e392562 126
AstrodyneSystems 2:6698a2433bfd 127 // Configuration data
AstrodyneSystems 2:6698a2433bfd 128 void ReadConfigfile(void);
AstrodyneSystems 2:6698a2433bfd 129 float fMachDelay, fApogeeDelay, fMainDeploymentAlt, fLowVoltageAlarm, fAltLog, fAccelLog, fMagLog, fGyroLog;
AstrodyneSystems 2:6698a2433bfd 130
AstrodyneSystems 2:6698a2433bfd 131 char *cfgKeyStr[]={
AstrodyneSystems 2:6698a2433bfd 132 "MACH DELAY (s)",
AstrodyneSystems 2:6698a2433bfd 133 "APOGEE DELAY (s)",
AstrodyneSystems 2:6698a2433bfd 134 "MAIN DEPLOYMENT (ft)",
AstrodyneSystems 2:6698a2433bfd 135 "LOW VOLTAGE ALARM (v)",
AstrodyneSystems 2:6698a2433bfd 136 "ALT LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 137 "ACCEL LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 138 "MAG LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 139 "GYRO LOG (1|0)"
AstrodyneSystems 2:6698a2433bfd 140 // NMEA Log(1|0)",
AstrodyneSystems 2:6698a2433bfd 141 //"SSID",
AstrodyneSystems 2:6698a2433bfd 142 //"PASSWD",
AstrodyneSystems 2:6698a2433bfd 143 };
AstrodyneSystems 2:6698a2433bfd 144
AstrodyneSystems 2:6698a2433bfd 145 float *cfgFloatPtr[] = {
AstrodyneSystems 2:6698a2433bfd 146 &fMachDelay, &fApogeeDelay, &fMainDeploymentAlt, &fLowVoltageAlarm, &fAltLog, &fAccelLog, &fMagLog, &fGyroLog};
AstrodyneSystems 2:6698a2433bfd 147
AstrodyneSystems 4:09ffcb9bc1d3 148 // MOSFET switchs and ADC
AstrodyneSystems 4:09ffcb9bc1d3 149 SCIboard_Mosfet mosfet;
AstrodyneSystems 4:09ffcb9bc1d3 150
AstrodyneSystems 0:ab51d784ef36 151 //---------------------------------------------------------------------
AstrodyneSystems 0:ab51d784ef36 152 int main() {
AstrodyneSystems 0:ab51d784ef36 153 unsigned char data[10];
AstrodyneSystems 0:ab51d784ef36 154 float f[3];
AstrodyneSystems 0:ab51d784ef36 155 char str[132];
AstrodyneSystems 0:ab51d784ef36 156 int currentTime;
AstrodyneSystems 0:ab51d784ef36 157 int lastTime=0;
AstrodyneSystems 3:a0863e392562 158 float gyro_store[3];
AstrodyneSystems 3:a0863e392562 159 bool bGyroDataStored=false;
AstrodyneSystems 0:ab51d784ef36 160
AstrodyneSystems 3:a0863e392562 161 // Ensure interrupts are off
AstrodyneSystems 1:a54c4a4f3b30 162 MPL3115A2_INT1.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 163 LSM303DLHC_DRDY.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 164 // LSM303DLHC_INT1.rise(NULL);
AstrodyneSystems 3:a0863e392562 165 // L3G4200DTR_DRDY.fall(NULL);
AstrodyneSystems 3:a0863e392562 166
AstrodyneSystems 2:6698a2433bfd 167 ReadConfigfile();
AstrodyneSystems 2:6698a2433bfd 168
AstrodyneSystems 0:ab51d784ef36 169 // DataLogger
AstrodyneSystems 0:ab51d784ef36 170 nextFilename();
AstrodyneSystems 0:ab51d784ef36 171
AstrodyneSystems 1:a54c4a4f3b30 172 // Get I2C device IDs
AstrodyneSystems 1:a54c4a4f3b30 173 sprintf(str, "MPL3115A2 Ident 0x%X\r\n", alt.getDeviceID());
AstrodyneSystems 1:a54c4a4f3b30 174 pc.printf(str);
AstrodyneSystems 1:a54c4a4f3b30 175 log_write(str);
AstrodyneSystems 1:a54c4a4f3b30 176
AstrodyneSystems 0:ab51d784ef36 177 lsm303.getDeviceID(data);
AstrodyneSystems 0:ab51d784ef36 178 sprintf(str, "LSM303DLHC Ident 0x%X 0x%X 0x%X\r\n", data[0], data[1], data[2]);
AstrodyneSystems 0:ab51d784ef36 179 pc.printf(str);
AstrodyneSystems 0:ab51d784ef36 180 log_write(str);
AstrodyneSystems 0:ab51d784ef36 181
AstrodyneSystems 3:a0863e392562 182 sprintf(str, "L3G4200DTR Ident 0x%X\r\n", l3g4200dtr.getDeviceID());
AstrodyneSystems 3:a0863e392562 183 pc.printf(str);
AstrodyneSystems 3:a0863e392562 184 log_write(str);
AstrodyneSystems 0:ab51d784ef36 185
AstrodyneSystems 0:ab51d784ef36 186 // Setup accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 187 lsm303.setAccMode(ACC_4G, ACC_50HZ);
AstrodyneSystems 0:ab51d784ef36 188 lsm303.setMagMode(MAG_1p3G, MAG_75HZ);
AstrodyneSystems 0:ab51d784ef36 189
AstrodyneSystems 1:a54c4a4f3b30 190 // Setup altimeter
AstrodyneSystems 1:a54c4a4f3b30 191 alt.setMode(ALT_MODE, OS4);
AstrodyneSystems 1:a54c4a4f3b30 192 alt.OST(); // initiate first conversion
AstrodyneSystems 1:a54c4a4f3b30 193 MPL3115A2_INT1.fall(MPL3115A2_INT1_INTERRUPT);
AstrodyneSystems 1:a54c4a4f3b30 194
AstrodyneSystems 0:ab51d784ef36 195 t.start(); // start timer
AstrodyneSystems 0:ab51d784ef36 196
AstrodyneSystems 0:ab51d784ef36 197 LSM303DLHC_DRDY.fall(LSM303DLHC_DRDY_INTERRUPT); // Magnetometer
AstrodyneSystems 0:ab51d784ef36 198 // LSM303DLHC_INT1.rise(LSM303DLHC_INT1_INTERRUPT); // Accelerometer
AstrodyneSystems 0:ab51d784ef36 199
AstrodyneSystems 0:ab51d784ef36 200
AstrodyneSystems 0:ab51d784ef36 201 // Collect 10 seconds of data then close file system to allow mbed to be visible on USB connected PC for demo app only
AstrodyneSystems 0:ab51d784ef36 202 while(t.read()<10) {
AstrodyneSystems 0:ab51d784ef36 203 time_ms = t.read_ms();
AstrodyneSystems 0:ab51d784ef36 204 currentTime = t.read();
AstrodyneSystems 0:ab51d784ef36 205 if(currentTime!=lastTime) {
AstrodyneSystems 0:ab51d784ef36 206 lastTime = currentTime;
AstrodyneSystems 0:ab51d784ef36 207 led2 = !led2; // slow blink led
AstrodyneSystems 0:ab51d784ef36 208 }
AstrodyneSystems 0:ab51d784ef36 209
AstrodyneSystems 0:ab51d784ef36 210 __disable_irq();
AstrodyneSystems 0:ab51d784ef36 211
AstrodyneSystems 0:ab51d784ef36 212 // Accelerometer
AstrodyneSystems 0:ab51d784ef36 213 if(lsm303.bAccDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 214 lsm303.getAccData(f);
AstrodyneSystems 0:ab51d784ef36 215 sprintf(str,"%u,2,%.3f,%.3f,%.3f\r\n", time_ms, f[0], f[1], f[2]);
AstrodyneSystems 0:ab51d784ef36 216 log_write(str);
AstrodyneSystems 1:a54c4a4f3b30 217 if(++accCnt >= accAltDecimate) {
AstrodyneSystems 1:a54c4a4f3b30 218 accCnt = 0;
AstrodyneSystems 1:a54c4a4f3b30 219 alt.OST();
AstrodyneSystems 1:a54c4a4f3b30 220 }
AstrodyneSystems 0:ab51d784ef36 221 }
AstrodyneSystems 0:ab51d784ef36 222
AstrodyneSystems 0:ab51d784ef36 223
AstrodyneSystems 0:ab51d784ef36 224 #ifdef NON_DRDY_MAG
AstrodyneSystems 0:ab51d784ef36 225 // Magnetometer
AstrodyneSystems 0:ab51d784ef36 226 data[0] = lsm303.getMagStatus();
AstrodyneSystems 0:ab51d784ef36 227 pc.printf("MagStatus=%X\r\n", data[0]);
AstrodyneSystems 0:ab51d784ef36 228
AstrodyneSystems 0:ab51d784ef36 229 if(lsm303.bMagDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 230 lsm303.getMagData(f);
AstrodyneSystems 0:ab51d784ef36 231 pc.printf("MAG: %.3f %.3f %.3f %.0f\r\n", f[0], f[1], f[2], atan2(f[1],f[0])*180.0/PI);
AstrodyneSystems 0:ab51d784ef36 232 }
AstrodyneSystems 0:ab51d784ef36 233 #endif
AstrodyneSystems 3:a0863e392562 234
AstrodyneSystems 3:a0863e392562 235 // Gyro
AstrodyneSystems 3:a0863e392562 236 if(l3g4200dtr.getStatus() & STATUS_REG_ZYXDA)
AstrodyneSystems 3:a0863e392562 237 {
AstrodyneSystems 3:a0863e392562 238 if(bGyroDataStored) {
AstrodyneSystems 3:a0863e392562 239 l3g4200dtr.getData(f);
AstrodyneSystems 3:a0863e392562 240 sprintf(str, "%u,4,%.3f,%.3f,%.3f\r\n", time_ms, f[0]+gyro_store[0], f[1]+gyro_store[1], f[2]+gyro_store[2]);
AstrodyneSystems 3:a0863e392562 241 log_write(str);
AstrodyneSystems 3:a0863e392562 242 bGyroDataStored = false;
AstrodyneSystems 3:a0863e392562 243 }
AstrodyneSystems 3:a0863e392562 244 else {
AstrodyneSystems 3:a0863e392562 245 l3g4200dtr.getData(gyro_store);
AstrodyneSystems 3:a0863e392562 246 bGyroDataStored = true;
AstrodyneSystems 3:a0863e392562 247 }
AstrodyneSystems 3:a0863e392562 248 }
AstrodyneSystems 3:a0863e392562 249
AstrodyneSystems 0:ab51d784ef36 250 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 251
AstrodyneSystems 0:ab51d784ef36 252 }
AstrodyneSystems 3:a0863e392562 253
AstrodyneSystems 3:a0863e392562 254 // Ensure interrupts are off
AstrodyneSystems 1:a54c4a4f3b30 255 MPL3115A2_INT1.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 256 LSM303DLHC_DRDY.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 257 // LSM303DLHC_INT1.rise(NULL);
AstrodyneSystems 3:a0863e392562 258 // L3G4200DTR_DRDY.fall(NULL);
AstrodyneSystems 3:a0863e392562 259
AstrodyneSystems 0:ab51d784ef36 260 wait(.1);
AstrodyneSystems 0:ab51d784ef36 261 log_close();
AstrodyneSystems 4:09ffcb9bc1d3 262
AstrodyneSystems 4:09ffcb9bc1d3 263 // Demo MOSFET
AstrodyneSystems 4:09ffcb9bc1d3 264 pc.printf("Battery voltage=%f\r\n", mosfet.getBattVoltage());
AstrodyneSystems 4:09ffcb9bc1d3 265 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 266 mosfet.setFet(4, 2.0);
AstrodyneSystems 4:09ffcb9bc1d3 267 pc.printf("MOSFET 4 on for 2 seconds.\r\n");
AstrodyneSystems 4:09ffcb9bc1d3 268 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 269 wait(3);
AstrodyneSystems 4:09ffcb9bc1d3 270 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 271
AstrodyneSystems 0:ab51d784ef36 272 pc.printf("Done.\r\n");
AstrodyneSystems 0:ab51d784ef36 273 led2=0;
AstrodyneSystems 0:ab51d784ef36 274
AstrodyneSystems 0:ab51d784ef36 275 // Signal program done
AstrodyneSystems 0:ab51d784ef36 276 while(1) {
AstrodyneSystems 0:ab51d784ef36 277 led1 = 1;
AstrodyneSystems 0:ab51d784ef36 278 wait(0.2);
AstrodyneSystems 0:ab51d784ef36 279 led1 = 0;
AstrodyneSystems 0:ab51d784ef36 280 wait(0.2);
AstrodyneSystems 0:ab51d784ef36 281 }
AstrodyneSystems 0:ab51d784ef36 282 }
AstrodyneSystems 0:ab51d784ef36 283
AstrodyneSystems 0:ab51d784ef36 284
AstrodyneSystems 1:a54c4a4f3b30 285 // Altimeter interrupt service ----------------------------------------
AstrodyneSystems 1:a54c4a4f3b30 286 void MPL3115A2_INT1_INTERRUPT(void)
AstrodyneSystems 1:a54c4a4f3b30 287 {
AstrodyneSystems 1:a54c4a4f3b30 288 float f[3];
AstrodyneSystems 1:a54c4a4f3b30 289 char str[80];
AstrodyneSystems 1:a54c4a4f3b30 290
AstrodyneSystems 1:a54c4a4f3b30 291 __disable_irq();
AstrodyneSystems 1:a54c4a4f3b30 292
AstrodyneSystems 1:a54c4a4f3b30 293 alt.getData(f);
AstrodyneSystems 1:a54c4a4f3b30 294 sprintf(str, "%u,1,%.1f,%.1f\r\n", time_ms, f[0], f[1]);
AstrodyneSystems 1:a54c4a4f3b30 295 log_write(str);
AstrodyneSystems 1:a54c4a4f3b30 296
AstrodyneSystems 1:a54c4a4f3b30 297 __enable_irq();
AstrodyneSystems 1:a54c4a4f3b30 298 }
AstrodyneSystems 1:a54c4a4f3b30 299
AstrodyneSystems 0:ab51d784ef36 300
AstrodyneSystems 0:ab51d784ef36 301 // Magnetometer interrupt service -------------------------------------
AstrodyneSystems 0:ab51d784ef36 302 void LSM303DLHC_DRDY_INTERRUPT(void)
AstrodyneSystems 0:ab51d784ef36 303 {
AstrodyneSystems 0:ab51d784ef36 304 float f[3];
AstrodyneSystems 0:ab51d784ef36 305 char str[80];
AstrodyneSystems 0:ab51d784ef36 306
AstrodyneSystems 0:ab51d784ef36 307 __disable_irq();
AstrodyneSystems 0:ab51d784ef36 308 lsm303.getMagData(f);
AstrodyneSystems 0:ab51d784ef36 309 sprintf(str, "%u,3,%.3f,%.3f,%.3f\r\n", time_ms, f[0], f[1], f[2]);
AstrodyneSystems 0:ab51d784ef36 310 log_write(str);
AstrodyneSystems 0:ab51d784ef36 311 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 312 }
AstrodyneSystems 0:ab51d784ef36 313
AstrodyneSystems 0:ab51d784ef36 314
AstrodyneSystems 0:ab51d784ef36 315 // Accelerometer interrupt service ------------------------------------
AstrodyneSystems 0:ab51d784ef36 316 /*void LSM303DLHC_INT1_INTERRUPT(void)
AstrodyneSystems 0:ab51d784ef36 317 {
AstrodyneSystems 0:ab51d784ef36 318 float f[3];
AstrodyneSystems 0:ab51d784ef36 319 unsigned char src;
AstrodyneSystems 0:ab51d784ef36 320 char str[80];
AstrodyneSystems 0:ab51d784ef36 321
AstrodyneSystems 0:ab51d784ef36 322 __disable_irq();
AstrodyneSystems 0:ab51d784ef36 323
AstrodyneSystems 0:ab51d784ef36 324 src = lsm303.getInt1Src();
AstrodyneSystems 0:ab51d784ef36 325 if(lsm303.bAccDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 326 lsm303.getAccData(f);
AstrodyneSystems 0:ab51d784ef36 327 sprintf(str,"%u,2,%.3f,%.3f,%.3f,%x\r\n", time_ms, f[0], f[1], f[2], src);
AstrodyneSystems 0:ab51d784ef36 328 log_write(str);
AstrodyneSystems 0:ab51d784ef36 329 if(++accCnt >= accAltDecimate) {
AstrodyneSystems 0:ab51d784ef36 330 accCnt = 0;
AstrodyneSystems 0:ab51d784ef36 331 alt.OST();
AstrodyneSystems 0:ab51d784ef36 332 }
AstrodyneSystems 0:ab51d784ef36 333 }
AstrodyneSystems 0:ab51d784ef36 334
AstrodyneSystems 0:ab51d784ef36 335 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 336 }
AstrodyneSystems 0:ab51d784ef36 337 */
AstrodyneSystems 2:6698a2433bfd 338
AstrodyneSystems 2:6698a2433bfd 339
AstrodyneSystems 2:6698a2433bfd 340 // Read configuration file --------------------------------------------
AstrodyneSystems 2:6698a2433bfd 341 void ReadConfigfile(void) {
AstrodyneSystems 2:6698a2433bfd 342 ConfigFile cfgFile("/local/SCIbdCfg.txt");
AstrodyneSystems 2:6698a2433bfd 343 int n;
AstrodyneSystems 2:6698a2433bfd 344 float f;
AstrodyneSystems 2:6698a2433bfd 345
AstrodyneSystems 2:6698a2433bfd 346 for(n=0; n<sizeof(cfgKeyStr)/sizeof(char*); n++) {
AstrodyneSystems 2:6698a2433bfd 347 if(cfgFile.getValue(cfgKeyStr[n], &f))
AstrodyneSystems 2:6698a2433bfd 348 {
AstrodyneSystems 2:6698a2433bfd 349 if(f < 0) f = 0;
AstrodyneSystems 2:6698a2433bfd 350 *(cfgFloatPtr[n]) = f;
AstrodyneSystems 2:6698a2433bfd 351 pc.printf("Found: %s: %f\r\n", cfgKeyStr[n], f);
AstrodyneSystems 2:6698a2433bfd 352 }
AstrodyneSystems 2:6698a2433bfd 353 }
AstrodyneSystems 2:6698a2433bfd 354 cfgFile.closeFile();
AstrodyneSystems 2:6698a2433bfd 355
AstrodyneSystems 2:6698a2433bfd 356 if(fMachDelay > 15.0)
AstrodyneSystems 2:6698a2433bfd 357 fMachDelay = 15;
AstrodyneSystems 2:6698a2433bfd 358
AstrodyneSystems 2:6698a2433bfd 359 if(fApogeeDelay > 1)
AstrodyneSystems 2:6698a2433bfd 360 fApogeeDelay = 1;
AstrodyneSystems 2:6698a2433bfd 361
AstrodyneSystems 2:6698a2433bfd 362 if(fMainDeploymentAlt < 300)
AstrodyneSystems 2:6698a2433bfd 363 fMainDeploymentAlt = 300;
AstrodyneSystems 2:6698a2433bfd 364 else if(fMainDeploymentAlt > 2000)
AstrodyneSystems 2:6698a2433bfd 365 fMainDeploymentAlt = 2000;
AstrodyneSystems 2:6698a2433bfd 366
AstrodyneSystems 2:6698a2433bfd 367 // save config file if not found?
AstrodyneSystems 2:6698a2433bfd 368
AstrodyneSystems 2:6698a2433bfd 369 }