This is a data logger program to be implemented with an instrument amplifier.

Dependencies:   mbed

Committer:
KISScientific
Date:
Tue Apr 04 18:01:11 2017 +0000
Revision:
0:d75ca4e39672
This is a data logger program.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KISScientific 0:d75ca4e39672 1
KISScientific 0:d75ca4e39672 2 //This program is for a 1 mV FS datalogger
KISScientific 0:d75ca4e39672 3
KISScientific 0:d75ca4e39672 4 #include "mbed.h"
KISScientific 0:d75ca4e39672 5 #include "USBSerial.h"
KISScientific 0:d75ca4e39672 6 Serial pc(USBTX, USBRX);
KISScientific 0:d75ca4e39672 7 DigitalOut d1(p15);
KISScientific 0:d75ca4e39672 8 AnalogIn input1(p16);
KISScientific 0:d75ca4e39672 9 DigitalOut d2(p17);
KISScientific 0:d75ca4e39672 10 DigitalOut d3(p18);
KISScientific 0:d75ca4e39672 11 DigitalOut d4(p19);
KISScientific 0:d75ca4e39672 12 DigitalOut d5(p20);
KISScientific 0:d75ca4e39672 13
KISScientific 0:d75ca4e39672 14 PwmOut OUToffset(p23);
KISScientific 0:d75ca4e39672 15 PwmOut INoffset(p21);
KISScientific 0:d75ca4e39672 16 PwmOut myled1(LED1); //P26
KISScientific 0:d75ca4e39672 17 PwmOut myled2(LED2); //P25
KISScientific 0:d75ca4e39672 18 PwmOut myled3(LED3); //P24
KISScientific 0:d75ca4e39672 19 //Don't use LED4, it is connected to PWMout P23!!
KISScientific 0:d75ca4e39672 20
KISScientific 0:d75ca4e39672 21 DigitalOut mux0(p27);
KISScientific 0:d75ca4e39672 22 DigitalOut mux1(p28);
KISScientific 0:d75ca4e39672 23 DigitalOut mux2(p29);
KISScientific 0:d75ca4e39672 24 DigitalOut mux3(p30);
KISScientific 0:d75ca4e39672 25
KISScientific 0:d75ca4e39672 26 char ch;
KISScientific 0:d75ca4e39672 27 unsigned short mvolts1;
KISScientific 0:d75ca4e39672 28 unsigned short mvolts2;
KISScientific 0:d75ca4e39672 29 unsigned short mvolts3;
KISScientific 0:d75ca4e39672 30
KISScientific 0:d75ca4e39672 31 //offset Control
KISScientific 0:d75ca4e39672 32 float Offset_A = 0.5; //in offset p21
KISScientific 0:d75ca4e39672 33 float Offset_B = 0.5; // out offset p23
KISScientific 0:d75ca4e39672 34 float Stime = .05;
KISScientific 0:d75ca4e39672 35 float Sgain = 1;
KISScientific 0:d75ca4e39672 36
KISScientific 0:d75ca4e39672 37 void rec_param(float *Offset_A, float *Offset_B, float *Stime, float *Sgain)
KISScientific 0:d75ca4e39672 38 {
KISScientific 0:d75ca4e39672 39 pc.putc(0x0C); // Write to computer serial port
KISScientific 0:d75ca4e39672 40 ch = pc.getc();
KISScientific 0:d75ca4e39672 41 while (ch != ' ') {
KISScientific 0:d75ca4e39672 42 ch = pc.getc();
KISScientific 0:d75ca4e39672 43 }
KISScientific 0:d75ca4e39672 44 pc.scanf("%f %f %f %f", Offset_A, Offset_B, Stime, Sgain);
KISScientific 0:d75ca4e39672 45 myled1 = 1;
KISScientific 0:d75ca4e39672 46 wait(0.2);
KISScientific 0:d75ca4e39672 47 return;
KISScientific 0:d75ca4e39672 48 }
KISScientific 0:d75ca4e39672 49
KISScientific 0:d75ca4e39672 50 main(void) {
KISScientific 0:d75ca4e39672 51
KISScientific 0:d75ca4e39672 52 mux0 = 0;
KISScientific 0:d75ca4e39672 53 mux1 = 1;
KISScientific 0:d75ca4e39672 54 mux2 = 0;
KISScientific 0:d75ca4e39672 55 mux3 = 0;
KISScientific 0:d75ca4e39672 56
KISScientific 0:d75ca4e39672 57 OUToffset.period_us(100);
KISScientific 0:d75ca4e39672 58 INoffset.period_us(100);
KISScientific 0:d75ca4e39672 59
KISScientific 0:d75ca4e39672 60 // Default offsets
KISScientific 0:d75ca4e39672 61 INoffset = 50.;
KISScientific 0:d75ca4e39672 62 OUToffset = 50.;
KISScientific 0:d75ca4e39672 63
KISScientific 0:d75ca4e39672 64 // Read initial offset and sample time
KISScientific 0:d75ca4e39672 65 rec_param(&Offset_A,&Offset_B, &Stime, &Sgain);
KISScientific 0:d75ca4e39672 66 wait(0.2);
KISScientific 0:d75ca4e39672 67 INoffset = Offset_A/100.;
KISScientific 0:d75ca4e39672 68 OUToffset = Offset_B/100.;
KISScientific 0:d75ca4e39672 69 myled1= 0;
KISScientific 0:d75ca4e39672 70
KISScientific 0:d75ca4e39672 71 //Read character
KISScientific 0:d75ca4e39672 72 while (1) {
KISScientific 0:d75ca4e39672 73 if(pc.readable()) {
KISScientific 0:d75ca4e39672 74 myled2 = myled3 = 0;
KISScientific 0:d75ca4e39672 75 ch = pc.getc();
KISScientific 0:d75ca4e39672 76 //Read setup parameters
KISScientific 0:d75ca4e39672 77 if (ch == 'X') {
KISScientific 0:d75ca4e39672 78 myled2 = 1;
KISScientific 0:d75ca4e39672 79 rec_param(&Offset_A,&Offset_B, &Stime, &Sgain);
KISScientific 0:d75ca4e39672 80 wait(0.2);
KISScientific 0:d75ca4e39672 81 INoffset = Offset_A/100.;
KISScientific 0:d75ca4e39672 82 OUToffset = Offset_B/100.;
KISScientific 0:d75ca4e39672 83
KISScientific 0:d75ca4e39672 84 if (Sgain == 1){
KISScientific 0:d75ca4e39672 85 mux0 = 0;
KISScientific 0:d75ca4e39672 86 mux1 = 0; }
KISScientific 0:d75ca4e39672 87 else if (Sgain == 10){
KISScientific 0:d75ca4e39672 88 mux0 = 0;
KISScientific 0:d75ca4e39672 89 mux1 = 1;}
KISScientific 0:d75ca4e39672 90 else if (Sgain == 100){
KISScientific 0:d75ca4e39672 91 mux0 = 1;
KISScientific 0:d75ca4e39672 92 mux1 = 0; }
KISScientific 0:d75ca4e39672 93 else {
KISScientific 0:d75ca4e39672 94 mux0 = 1;
KISScientific 0:d75ca4e39672 95 mux1 = 1;}
KISScientific 0:d75ca4e39672 96
KISScientific 0:d75ca4e39672 97 myled1 = myled2 = 0;
KISScientific 0:d75ca4e39672 98 ch = ' ';
KISScientific 0:d75ca4e39672 99 }
KISScientific 0:d75ca4e39672 100
KISScientific 0:d75ca4e39672 101 //Sample Data
KISScientific 0:d75ca4e39672 102 if (ch == 'S') {
KISScientific 0:d75ca4e39672 103 for(int i = 1; i < 4 ; i++) {
KISScientific 0:d75ca4e39672 104 wait(Stime/3000);
KISScientific 0:d75ca4e39672 105 mvolts1 = input1.read_u16();
KISScientific 0:d75ca4e39672 106 mvolts2 = input1.read_u16();
KISScientific 0:d75ca4e39672 107 mvolts3 = input1.read_u16();
KISScientific 0:d75ca4e39672 108 if ((mvolts1 >= mvolts2 && mvolts1 <= mvolts3) || (mvolts1 >= mvolts3 && mvolts1 <= mvolts2)) mvolts = mvolts1;
KISScientific 0:d75ca4e39672 109 else if ((mvolts2 >= mvolts1 && mvolts2 <= mvolts3) || (mvolts2 >= mvolts3 && mvolts2 <= mvolts1)) mvolts = mvolts2;
KISScientific 0:d75ca4e39672 110 else mvolts = mvolts3;
KISScientific 0:d75ca4e39672 111
KISScientific 0:d75ca4e39672 112 pc.putc((mvolts>>8)&0xFF);
KISScientific 0:d75ca4e39672 113 pc.putc((mvolts>>0)&0xFF);
KISScientific 0:d75ca4e39672 114 } //end for
KISScientific 0:d75ca4e39672 115 } // end if
KISScientific 0:d75ca4e39672 116 //Check for stop
KISScientific 0:d75ca4e39672 117 if (ch == 'Q') {
KISScientific 0:d75ca4e39672 118 wait(1);
KISScientific 0:d75ca4e39672 119 ch = ' ';
KISScientific 0:d75ca4e39672 120 }
KISScientific 0:d75ca4e39672 121
KISScientific 0:d75ca4e39672 122 } //pc readable
KISScientific 0:d75ca4e39672 123 } //while
KISScientific 0:d75ca4e39672 124 }