SiPM basded cosmic ray detector data acquisition system.

Dependencies:   DNSResolver EthernetNetIf FatFileSystem SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
NickRyder
Date:
Mon Jan 21 13:51:58 2013 +0000
Commit message:
Initial commit.

Changed in this revision

DNSResolver.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
FatFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SiPM.cpp Show annotated file Show diff for this revision Revisions of this file
SiPM.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a8cee0e1d6d9 DNSResolver.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DNSResolver.lib	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/DNSResolver/#097d4993dd1e
diff -r 000000000000 -r a8cee0e1d6d9 EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r a8cee0e1d6d9 FatFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FatFileSystem.lib	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_unsupported/code/FatFileSystem/#333d6e93e58f
diff -r 000000000000 -r a8cee0e1d6d9 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SDFileSystem/#603a8d2f4de5
diff -r 000000000000 -r a8cee0e1d6d9 SiPM.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SiPM.cpp	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,60 @@
+#include "SiPM.h"
+
+SiPM::SiPM(PinName pin, PinName led) : 
+        n(0), ncoincidence(0), ntrig(0),
+        time(),
+        checkcoincidence(false), running(false),
+        interval(20), deadtime(50),
+        other(NULL),
+        iin(pin), ledpin(led)
+        {
+    iin.rise(this, &SiPM::trigger);
+    ledpin = 1;
+}
+
+void SiPM::addother(SiPM * sipm) {
+   other = sipm;
+   checkcoincidence = true;
+}
+
+void SiPM::setinterval_us(int t)  {
+    interval = t;
+}
+
+void SiPM::setdeadtime_us(int t)  {
+    deadtime = t;
+}
+
+void SiPM::trigger()    {
+    ntrig++;
+    if (running) {
+        ledpin = !ledpin;
+        if (time.read_us() > deadtime)  {
+            n++;
+            time.reset();
+            if (checkcoincidence)   {
+                if (other->time.read_us() < interval)   {
+                    ncoincidence++;
+                }
+            }        
+        }
+    }
+}
+
+void SiPM::reset()  {
+    n = 0;
+    ncoincidence = 0;
+    ntrig = 0;
+    start();
+}
+
+void SiPM::start()  {
+    running = true;
+    time.start();
+    printf("# Starting SiPM.\n");
+}
+
+void SiPM::stop()   {
+    running = false;
+    printf("#Stopping SiPM.\n");
+}
\ No newline at end of file
diff -r 000000000000 -r a8cee0e1d6d9 SiPM.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SiPM.h	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,26 @@
+#ifndef MBED_SIPM_H
+#define MBED_SIPM_H
+
+#include "mbed.h"
+
+class SiPM{
+    public:
+        SiPM(PinName, PinName);
+        void addother(SiPM *);
+        void setinterval_us(int);
+        void setdeadtime_us(int);
+        void trigger();
+        void start();
+        void stop();
+        void reset();
+        int n, ncoincidence, ntrig;
+        Timer time;
+    private:
+        bool checkcoincidence, running;
+        int interval, deadtime;
+        SiPM * other;
+        InterruptIn iin;
+        DigitalOut ledpin;
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r a8cee0e1d6d9 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,133 @@
+#include "mbed.h"
+//#include "Websocket.h"
+#include "SDFileSystem.h"
+#include "SiPM.h"
+#include <vector>
+
+//Websocket ws("ws://sockets.mbed.org/ws/NickRyder/wo");
+char url[100] = "ws://pplxgo1.physics.ox.ac.uk:8008/log";
+//char url[100] = "ws://163.1.136.220:8008/log";
+//char url[100] = "ws://sockets.mbed.org:80/ws/NickRyder/wo";
+//Websocket ws(url);
+
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+DigitalOut myled(LED1);
+DigitalOut webconnected(LED4);
+AnalogOut comparison(p18);
+AnalogIn temperature(p15);
+AnalogIn bias(p20);
+Serial pc(USBTX, USBRX);
+float scantime;
+unsigned long n;
+
+SiPM sipm1(p21, LED2);
+//SiPM sipm2(p22, LED3);
+
+void scan(float voltage, float waittime) {
+    float scale = voltage / 3.3;
+    comparison.write(scale);
+    sipm1.reset();
+//    sipm2.reset();
+    wait(waittime);
+    sipm1.stop();
+//    sipm2.stop();
+}
+
+int main() {
+    pc.printf("# Connecting together sipms.\n");
+//    sipm1.addother(&sipm2);
+//    sipm2.addother(&sipm1);
+    pc.printf("# Done.\n");
+    webconnected = 0;
+    pc.printf("# Started.\n");
+    time_t now = time(NULL);
+    pc.printf("# Time is now %d\n", now);
+    /*
+      pc.printf("# Trying to set time...\n");
+        int n = 0;
+        char timeword[20];
+        int j = 0;
+        for (int i = 0; i < 20; i++) {
+            if (pc.readable()) {
+                while (pc.readable()) {
+                    timeword[j] = pc.getc();
+                    j += 1;
+                    wait(0.1);
+                }
+            }
+            wait(0.5);
+        }
+        timeword[j] = 0;
+        n = atoi(timeword);
+        pc.printf("# n = %d\n", n);
+        if (n > 10000)  {
+            set_time(n);
+            now = time(NULL);         
+            pc.printf("# Set time to %s", ctime(&now));
+        } else  {
+            pc.printf("# Failed to set time.\n");
+        }
+    }
+    */
+    myled = 1;
+    scantime = 20.0;
+    pc.printf("# Each scan is %f seconds.\n", scantime);
+    vector<float> vscan;
+//    vscan.push_back(0.05);
+//    vscan.push_back(0.10);
+//    vscan.push_back(0.15);
+//    vscan.push_back(0.20);
+//    vscan.push_back(0.25);
+//    vscan.push_back(0.30);
+//    vscan.push_back(0.35);
+//    vscan.push_back(0.40);
+//    vscan.push_back(0.45);
+    vscan.push_back(0.50);
+//    vscan.push_back(0.55);
+    vscan.push_back(0.60);
+//    vscan.push_back(0.65);
+    vscan.push_back(0.70);
+//    vscan.push_back(0.75);
+    vscan.push_back(0.80);
+//    vscan.push_back(0.85);
+    vscan.push_back(0.90);
+//    vscan.push_back(0.95);
+    vscan.push_back(1.00);
+    vscan.push_back(1.10);
+    vscan.push_back(1.20);
+    vscan.push_back(1.30);
+    vscan.push_back(1.40);
+    vscan.push_back(1.50);
+    vscan.push_back(1.60);
+//   vscan.push_back(1.70);
+//    vscan.push_back(1.80);
+//    vscan.push_back(1.90);
+//    vscan.push_back(2.00);
+//    vscan.push_back(2.20);
+//    vscan.push_back(2.50);
+//    vscan.push_back(2.75);
+    //vscan.push_back(3.00);
+    vector<float>::iterator vit;
+    int loop = 0;
+    char msg[200];
+    while (true) {
+        pc.printf("# Starting loop %d.\n", loop);
+        loop++;
+        FILE * outp = NULL;
+        for (vit = vscan.begin() ; vit != vscan.end(); vit++)   {
+            float v = *vit;
+            time_t start = time(NULL);
+            pc.printf("# %f V started at %s", v, ctime(&start));
+            scan(v, scantime);
+            sprintf(msg, "%f, %f, %i, %i, %i, %s", 
+                    scantime, v,
+                    sipm1.n, sipm1.ncoincidence, sipm1.ntrig,
+                    ctime(&start));
+            outp = fopen("/sd/sipm.dat", "a");
+            fprintf(outp, "%s", msg);
+            fclose(outp);
+            pc.printf(msg);
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r a8cee0e1d6d9 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jan 21 13:51:58 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
\ No newline at end of file