Software to drive a monitor unit for a closed circuit rebreather using 3 electrogalvanic oxygen sensor cells run through an amplifier (lm324) . Uses a separate ds1307 clock IC to get timestamp values for logged data.

Dependencies:   DS1307 TextOLED_custom mbed

The main electornics is housed in another pod mounted on the back of the unit. I'm using an mbed lpc11u24 to drive everything which comes with a flash drive for data logging built in. It has an external ds1307 clock chip added and a very cheapo lm324 quad op-amp to amplify the o2 sensor signals from the 10s of mV range by 30x so that ppo2=0.21 corresponds to about 0.3V. I still have to do some ADC averaging with this amplifier and do have to calibrate out the individual offsets of the chip but this works ok now that I've worked out which amp is on which adc...

Committer:
pegcjs
Date:
Wed Aug 01 15:04:18 2012 +0000
Revision:
0:52d05d950581
Child:
1:9cff4feccbce
just started writing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pegcjs 0:52d05d950581 1 //lpc1124lcddemo
pegcjs 0:52d05d950581 2 #include "ds1307.h"
pegcjs 0:52d05d950581 3 #include "mbed.h"
pegcjs 0:52d05d950581 4 #include "TextLCD.h"
pegcjs 0:52d05d950581 5
pegcjs 0:52d05d950581 6 //pin assignments and declarations
pegcjs 0:52d05d950581 7 // LCD display
pegcjs 0:52d05d950581 8 TextLCD g_lcd(p26, p25, p24, p23, p22, p21); // RS, E, DB4, DB5, DB6, DB7
pegcjs 0:52d05d950581 9
pegcjs 0:52d05d950581 10 //onboard leds
pegcjs 0:52d05d950581 11 DigitalOut led1(LED1);
pegcjs 0:52d05d950581 12 DigitalOut led2(LED2);
pegcjs 0:52d05d950581 13
pegcjs 0:52d05d950581 14 // warning leds
pegcjs 0:52d05d950581 15 DigitalOut red(p34);
pegcjs 0:52d05d950581 16 DigitalOut green(p33);
pegcjs 0:52d05d950581 17 DigitalOut blue(p30);
pegcjs 0:52d05d950581 18
pegcjs 0:52d05d950581 19 // switches and buttons
pegcjs 0:52d05d950581 20 DigitalIn CAL(p36);
pegcjs 0:52d05d950581 21 DigitalIn SW1(p35);
pegcjs 0:52d05d950581 22
pegcjs 0:52d05d950581 23 // log data storage
pegcjs 0:52d05d950581 24 LocalFileSystem local("local");
pegcjs 0:52d05d950581 25
pegcjs 0:52d05d950581 26 // adc inputs for sensors
pegcjs 0:52d05d950581 27 AnalogIn depin(p20);
pegcjs 0:52d05d950581 28 AnalogIn EG1(p19);
pegcjs 0:52d05d950581 29 AnalogIn EG2(p18);
pegcjs 0:52d05d950581 30 AnalogIn Vbatt(p17);
pegcjs 0:52d05d950581 31
pegcjs 0:52d05d950581 32 // realtime clock
pegcjs 0:52d05d950581 33 DS1307 my1307(p28,p27); // start DS1307 class and give it pins for connections of the DS1307 device
pegcjs 0:52d05d950581 34
pegcjs 0:52d05d950581 35 // variables for realtime clock
pegcjs 0:52d05d950581 36 int sec = 0;
pegcjs 0:52d05d950581 37 int min = 0;
pegcjs 0:52d05d950581 38 int hours = 0;
pegcjs 0:52d05d950581 39 int day = 0;
pegcjs 0:52d05d950581 40 int date = 0;
pegcjs 0:52d05d950581 41 int month = 0;
pegcjs 0:52d05d950581 42 int year = 0;
pegcjs 0:52d05d950581 43
pegcjs 0:52d05d950581 44
pegcjs 0:52d05d950581 45 int main() {
pegcjs 0:52d05d950581 46 // get time to log a startup time
pegcjs 0:52d05d950581 47 my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
pegcjs 0:52d05d950581 48 int starttime=year*365*24*60*60+month*30*24*60*60+day*24*60*60+hours*60*60+min*60+sec; //simple timestamp = # seconds since midnight jan 1st 2000 if all months were 30 days.
pegcjs 0:52d05d950581 49
pegcjs 0:52d05d950581 50
pegcjs 0:52d05d950581 51 int seconds;
pegcjs 0:52d05d950581 52 float depth;
pegcjs 0:52d05d950581 53
pegcjs 0:52d05d950581 54 // setup local file to store data in
pegcjs 0:52d05d950581 55 FILE *fp = fopen("/local/out.txt", "a"); // Open "out.txt" on the local file system for writing
pegcjs 0:52d05d950581 56
pegcjs 0:52d05d950581 57
pegcjs 0:52d05d950581 58
pegcjs 0:52d05d950581 59
pegcjs 0:52d05d950581 60 g_lcd.cls();
pegcjs 0:52d05d950581 61
pegcjs 0:52d05d950581 62 g_lcd.locate(0, 0);
pegcjs 0:52d05d950581 63 g_lcd.printf( "Hello world!");
pegcjs 0:52d05d950581 64
pegcjs 0:52d05d950581 65 while (1) {
pegcjs 0:52d05d950581 66 g_lcd.locate(0, 1);
pegcjs 0:52d05d950581 67 my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
pegcjs 0:52d05d950581 68 seconds=day*24*60*60+hours*60*60+min*60+sec; // seconds since the start of this month....
pegcjs 0:52d05d950581 69
pegcjs 0:52d05d950581 70 if (led1==0) led1=1;
pegcjs 0:52d05d950581 71 else led1=0;
pegcjs 0:52d05d950581 72 g_lcd.printf( "%.2d:%.2d:%.2d", hours,min,sec);
pegcjs 0:52d05d950581 73
pegcjs 0:52d05d950581 74 iCounter++;
pegcjs 0:52d05d950581 75 depth=depin/0.020;
pegcjs 0:52d05d950581 76 if (iCounter <=60) {
pegcjs 0:52d05d950581 77 fprintf(fp, "%d\t%e\n",seconds,depth);
pegcjs 0:52d05d950581 78 g_lcd.locate(0,0);
pegcjs 0:52d05d950581 79 g_lcd.printf("Writing data ");
pegcjs 0:52d05d950581 80 } else {
pegcjs 0:52d05d950581 81 g_lcd.locate(0,0);
pegcjs 0:52d05d950581 82 g_lcd.printf("Closed file ");
pegcjs 0:52d05d950581 83 }
pegcjs 0:52d05d950581 84 if (iCounter==61) {
pegcjs 0:52d05d950581 85 fclose(fp);
pegcjs 0:52d05d950581 86 }
pegcjs 0:52d05d950581 87 g_lcd.locate(9,1);
pegcjs 0:52d05d950581 88 g_lcd.printf("%3.1f",depth);
pegcjs 0:52d05d950581 89 wait(1.0);
pegcjs 0:52d05d950581 90 }
pegcjs 0:52d05d950581 91 }