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...

Rebmon_main.cpp

Committer:
pegcjs
Date:
2012-08-01
Revision:
0:52d05d950581
Child:
1:9cff4feccbce

File content as of revision 0:52d05d950581:

//lpc1124lcddemo
#include "ds1307.h"
#include "mbed.h"
#include "TextLCD.h"

//pin assignments and declarations
// LCD display
TextLCD g_lcd(p26, p25, p24, p23, p22, p21);  // RS, E, DB4, DB5, DB6, DB7

//onboard leds
DigitalOut led1(LED1);
DigitalOut led2(LED2);

// warning leds
DigitalOut red(p34);
DigitalOut green(p33);
DigitalOut blue(p30);

// switches and buttons
DigitalIn CAL(p36);
DigitalIn SW1(p35);

// log data storage
LocalFileSystem local("local");

// adc inputs for sensors
AnalogIn depin(p20);
AnalogIn EG1(p19);
AnalogIn EG2(p18);
AnalogIn Vbatt(p17);

// realtime clock
DS1307 my1307(p28,p27); // start DS1307 class and give it pins for connections of the DS1307 device

// variables for realtime clock
int sec = 0;
int min = 0;
int hours = 0;
int day = 0;
int date = 0;
int month = 0;
int year = 0;


int main() {
    // get time to log a startup time
    my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
    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.
    

    int seconds;
    float depth;

// setup local file to store data in
    FILE *fp = fopen("/local/out.txt", "a");  // Open "out.txt" on the local file system for writing




g_lcd.cls();

g_lcd.locate(0, 0);
g_lcd.printf( "Hello world!");

while (1) {
    g_lcd.locate(0, 1);
    my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year);
    seconds=day*24*60*60+hours*60*60+min*60+sec; // seconds since the start of this month....

    if (led1==0) led1=1;
    else led1=0;
    g_lcd.printf( "%.2d:%.2d:%.2d", hours,min,sec);

    iCounter++;
    depth=depin/0.020;
    if (iCounter <=60) {
        fprintf(fp, "%d\t%e\n",seconds,depth);
        g_lcd.locate(0,0);
        g_lcd.printf("Writing data  ");
    } else {
        g_lcd.locate(0,0);
        g_lcd.printf("Closed file  ");
    }
    if (iCounter==61) {
        fclose(fp);
    }
    g_lcd.locate(9,1);
    g_lcd.printf("%3.1f",depth);
    wait(1.0);
}
}