SiPM basded cosmic ray detector data acquisition system.

Dependencies:   DNSResolver EthernetNetIf FatFileSystem SDFileSystem mbed

Committer:
NickRyder
Date:
Mon Jan 21 13:51:58 2013 +0000
Revision:
0:a8cee0e1d6d9
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NickRyder 0:a8cee0e1d6d9 1 #include "mbed.h"
NickRyder 0:a8cee0e1d6d9 2 //#include "Websocket.h"
NickRyder 0:a8cee0e1d6d9 3 #include "SDFileSystem.h"
NickRyder 0:a8cee0e1d6d9 4 #include "SiPM.h"
NickRyder 0:a8cee0e1d6d9 5 #include <vector>
NickRyder 0:a8cee0e1d6d9 6
NickRyder 0:a8cee0e1d6d9 7 //Websocket ws("ws://sockets.mbed.org/ws/NickRyder/wo");
NickRyder 0:a8cee0e1d6d9 8 char url[100] = "ws://pplxgo1.physics.ox.ac.uk:8008/log";
NickRyder 0:a8cee0e1d6d9 9 //char url[100] = "ws://163.1.136.220:8008/log";
NickRyder 0:a8cee0e1d6d9 10 //char url[100] = "ws://sockets.mbed.org:80/ws/NickRyder/wo";
NickRyder 0:a8cee0e1d6d9 11 //Websocket ws(url);
NickRyder 0:a8cee0e1d6d9 12
NickRyder 0:a8cee0e1d6d9 13 SDFileSystem sd(p5, p6, p7, p8, "sd");
NickRyder 0:a8cee0e1d6d9 14
NickRyder 0:a8cee0e1d6d9 15 DigitalOut myled(LED1);
NickRyder 0:a8cee0e1d6d9 16 DigitalOut webconnected(LED4);
NickRyder 0:a8cee0e1d6d9 17 AnalogOut comparison(p18);
NickRyder 0:a8cee0e1d6d9 18 AnalogIn temperature(p15);
NickRyder 0:a8cee0e1d6d9 19 AnalogIn bias(p20);
NickRyder 0:a8cee0e1d6d9 20 Serial pc(USBTX, USBRX);
NickRyder 0:a8cee0e1d6d9 21 float scantime;
NickRyder 0:a8cee0e1d6d9 22 unsigned long n;
NickRyder 0:a8cee0e1d6d9 23
NickRyder 0:a8cee0e1d6d9 24 SiPM sipm1(p21, LED2);
NickRyder 0:a8cee0e1d6d9 25 //SiPM sipm2(p22, LED3);
NickRyder 0:a8cee0e1d6d9 26
NickRyder 0:a8cee0e1d6d9 27 void scan(float voltage, float waittime) {
NickRyder 0:a8cee0e1d6d9 28 float scale = voltage / 3.3;
NickRyder 0:a8cee0e1d6d9 29 comparison.write(scale);
NickRyder 0:a8cee0e1d6d9 30 sipm1.reset();
NickRyder 0:a8cee0e1d6d9 31 // sipm2.reset();
NickRyder 0:a8cee0e1d6d9 32 wait(waittime);
NickRyder 0:a8cee0e1d6d9 33 sipm1.stop();
NickRyder 0:a8cee0e1d6d9 34 // sipm2.stop();
NickRyder 0:a8cee0e1d6d9 35 }
NickRyder 0:a8cee0e1d6d9 36
NickRyder 0:a8cee0e1d6d9 37 int main() {
NickRyder 0:a8cee0e1d6d9 38 pc.printf("# Connecting together sipms.\n");
NickRyder 0:a8cee0e1d6d9 39 // sipm1.addother(&sipm2);
NickRyder 0:a8cee0e1d6d9 40 // sipm2.addother(&sipm1);
NickRyder 0:a8cee0e1d6d9 41 pc.printf("# Done.\n");
NickRyder 0:a8cee0e1d6d9 42 webconnected = 0;
NickRyder 0:a8cee0e1d6d9 43 pc.printf("# Started.\n");
NickRyder 0:a8cee0e1d6d9 44 time_t now = time(NULL);
NickRyder 0:a8cee0e1d6d9 45 pc.printf("# Time is now %d\n", now);
NickRyder 0:a8cee0e1d6d9 46 /*
NickRyder 0:a8cee0e1d6d9 47 pc.printf("# Trying to set time...\n");
NickRyder 0:a8cee0e1d6d9 48 int n = 0;
NickRyder 0:a8cee0e1d6d9 49 char timeword[20];
NickRyder 0:a8cee0e1d6d9 50 int j = 0;
NickRyder 0:a8cee0e1d6d9 51 for (int i = 0; i < 20; i++) {
NickRyder 0:a8cee0e1d6d9 52 if (pc.readable()) {
NickRyder 0:a8cee0e1d6d9 53 while (pc.readable()) {
NickRyder 0:a8cee0e1d6d9 54 timeword[j] = pc.getc();
NickRyder 0:a8cee0e1d6d9 55 j += 1;
NickRyder 0:a8cee0e1d6d9 56 wait(0.1);
NickRyder 0:a8cee0e1d6d9 57 }
NickRyder 0:a8cee0e1d6d9 58 }
NickRyder 0:a8cee0e1d6d9 59 wait(0.5);
NickRyder 0:a8cee0e1d6d9 60 }
NickRyder 0:a8cee0e1d6d9 61 timeword[j] = 0;
NickRyder 0:a8cee0e1d6d9 62 n = atoi(timeword);
NickRyder 0:a8cee0e1d6d9 63 pc.printf("# n = %d\n", n);
NickRyder 0:a8cee0e1d6d9 64 if (n > 10000) {
NickRyder 0:a8cee0e1d6d9 65 set_time(n);
NickRyder 0:a8cee0e1d6d9 66 now = time(NULL);
NickRyder 0:a8cee0e1d6d9 67 pc.printf("# Set time to %s", ctime(&now));
NickRyder 0:a8cee0e1d6d9 68 } else {
NickRyder 0:a8cee0e1d6d9 69 pc.printf("# Failed to set time.\n");
NickRyder 0:a8cee0e1d6d9 70 }
NickRyder 0:a8cee0e1d6d9 71 }
NickRyder 0:a8cee0e1d6d9 72 */
NickRyder 0:a8cee0e1d6d9 73 myled = 1;
NickRyder 0:a8cee0e1d6d9 74 scantime = 20.0;
NickRyder 0:a8cee0e1d6d9 75 pc.printf("# Each scan is %f seconds.\n", scantime);
NickRyder 0:a8cee0e1d6d9 76 vector<float> vscan;
NickRyder 0:a8cee0e1d6d9 77 // vscan.push_back(0.05);
NickRyder 0:a8cee0e1d6d9 78 // vscan.push_back(0.10);
NickRyder 0:a8cee0e1d6d9 79 // vscan.push_back(0.15);
NickRyder 0:a8cee0e1d6d9 80 // vscan.push_back(0.20);
NickRyder 0:a8cee0e1d6d9 81 // vscan.push_back(0.25);
NickRyder 0:a8cee0e1d6d9 82 // vscan.push_back(0.30);
NickRyder 0:a8cee0e1d6d9 83 // vscan.push_back(0.35);
NickRyder 0:a8cee0e1d6d9 84 // vscan.push_back(0.40);
NickRyder 0:a8cee0e1d6d9 85 // vscan.push_back(0.45);
NickRyder 0:a8cee0e1d6d9 86 vscan.push_back(0.50);
NickRyder 0:a8cee0e1d6d9 87 // vscan.push_back(0.55);
NickRyder 0:a8cee0e1d6d9 88 vscan.push_back(0.60);
NickRyder 0:a8cee0e1d6d9 89 // vscan.push_back(0.65);
NickRyder 0:a8cee0e1d6d9 90 vscan.push_back(0.70);
NickRyder 0:a8cee0e1d6d9 91 // vscan.push_back(0.75);
NickRyder 0:a8cee0e1d6d9 92 vscan.push_back(0.80);
NickRyder 0:a8cee0e1d6d9 93 // vscan.push_back(0.85);
NickRyder 0:a8cee0e1d6d9 94 vscan.push_back(0.90);
NickRyder 0:a8cee0e1d6d9 95 // vscan.push_back(0.95);
NickRyder 0:a8cee0e1d6d9 96 vscan.push_back(1.00);
NickRyder 0:a8cee0e1d6d9 97 vscan.push_back(1.10);
NickRyder 0:a8cee0e1d6d9 98 vscan.push_back(1.20);
NickRyder 0:a8cee0e1d6d9 99 vscan.push_back(1.30);
NickRyder 0:a8cee0e1d6d9 100 vscan.push_back(1.40);
NickRyder 0:a8cee0e1d6d9 101 vscan.push_back(1.50);
NickRyder 0:a8cee0e1d6d9 102 vscan.push_back(1.60);
NickRyder 0:a8cee0e1d6d9 103 // vscan.push_back(1.70);
NickRyder 0:a8cee0e1d6d9 104 // vscan.push_back(1.80);
NickRyder 0:a8cee0e1d6d9 105 // vscan.push_back(1.90);
NickRyder 0:a8cee0e1d6d9 106 // vscan.push_back(2.00);
NickRyder 0:a8cee0e1d6d9 107 // vscan.push_back(2.20);
NickRyder 0:a8cee0e1d6d9 108 // vscan.push_back(2.50);
NickRyder 0:a8cee0e1d6d9 109 // vscan.push_back(2.75);
NickRyder 0:a8cee0e1d6d9 110 //vscan.push_back(3.00);
NickRyder 0:a8cee0e1d6d9 111 vector<float>::iterator vit;
NickRyder 0:a8cee0e1d6d9 112 int loop = 0;
NickRyder 0:a8cee0e1d6d9 113 char msg[200];
NickRyder 0:a8cee0e1d6d9 114 while (true) {
NickRyder 0:a8cee0e1d6d9 115 pc.printf("# Starting loop %d.\n", loop);
NickRyder 0:a8cee0e1d6d9 116 loop++;
NickRyder 0:a8cee0e1d6d9 117 FILE * outp = NULL;
NickRyder 0:a8cee0e1d6d9 118 for (vit = vscan.begin() ; vit != vscan.end(); vit++) {
NickRyder 0:a8cee0e1d6d9 119 float v = *vit;
NickRyder 0:a8cee0e1d6d9 120 time_t start = time(NULL);
NickRyder 0:a8cee0e1d6d9 121 pc.printf("# %f V started at %s", v, ctime(&start));
NickRyder 0:a8cee0e1d6d9 122 scan(v, scantime);
NickRyder 0:a8cee0e1d6d9 123 sprintf(msg, "%f, %f, %i, %i, %i, %s",
NickRyder 0:a8cee0e1d6d9 124 scantime, v,
NickRyder 0:a8cee0e1d6d9 125 sipm1.n, sipm1.ncoincidence, sipm1.ntrig,
NickRyder 0:a8cee0e1d6d9 126 ctime(&start));
NickRyder 0:a8cee0e1d6d9 127 outp = fopen("/sd/sipm.dat", "a");
NickRyder 0:a8cee0e1d6d9 128 fprintf(outp, "%s", msg);
NickRyder 0:a8cee0e1d6d9 129 fclose(outp);
NickRyder 0:a8cee0e1d6d9 130 pc.printf(msg);
NickRyder 0:a8cee0e1d6d9 131 }
NickRyder 0:a8cee0e1d6d9 132 }
NickRyder 0:a8cee0e1d6d9 133 }