This is the DW1000 driver and our self developed distance measurement application based on it. We do this as a semester thesis at ETH Zürich under the Automatic Control Laboratory in the Department of electrical engineering.

Dependencies:   mbed

Committer:
manumaet
Date:
Fri Nov 28 07:44:36 2014 +0000
Revision:
27:71178fdb78e1
Parent:
26:a65c6f26c458
Child:
28:a830131560e8
MMRanging intriduced, before any switchover

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 24:6f25ba679490 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 0:f50e671ffff7 2 #include "mbed.h"
manumaet 26:a65c6f26c458 3 #include "PC.h" // Serial Port via USB for debugging with Terminal
manumaet 27:71178fdb78e1 4 #include "DW1000.h" // our DW1000 device driver
manumaet 27:71178fdb78e1 5 #include "MMRanging.h" // our self developed raning application
manumaet 0:f50e671ffff7 6
manumaet 26:a65c6f26c458 7 //#define RECEIVER
manumaet 26:a65c6f26c458 8
manumaet 26:a65c6f26c458 9 PC pc(USBTX, USBRX, 921600); // USB UART Terminal
manumaet 26:a65c6f26c458 10 DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
manumaet 27:71178fdb78e1 11 MMRanging ranging(&dw); // Ranging class for getting distances and later positions
manumaet 22:576ee999b004 12
manumaet 27:71178fdb78e1 13 const float timeunit = 1/(128*499.2); // conversion between LSB of TX and RX timestamps and microseconds
manumaet 14:8041c9b68406 14 int i=0;
manumaet 24:6f25ba679490 15 char message[1021] = "";
manumaet 24:6f25ba679490 16 char messageRX[1021] = "";
manumaet 24:6f25ba679490 17 uint64_t TX_timestamp;
manumaet 24:6f25ba679490 18 uint64_t RX_timestamp;
manumaet 24:6f25ba679490 19 int event_i = 0;
manumaet 24:6f25ba679490 20 char event[10][20];
manumaet 24:6f25ba679490 21 uint64_t eventtimes[10];
manumaet 14:8041c9b68406 22
manumaet 18:bbc7ca7d3a95 23 void callbackRX(int framelength) {
manumaet 26:a65c6f26c458 24 RX_timestamp = dw.getRXTimestamp();
manumaet 26:a65c6f26c458 25 dw.receiveString(messageRX);
manumaet 26:a65c6f26c458 26 #ifdef RECEIVER
manumaet 26:a65c6f26c458 27 message[0] = 'A'; // acknowledge messages
manumaet 24:6f25ba679490 28 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 29 message[i+1] = messageRX[i];
manumaet 24:6f25ba679490 30 dw.sendString(message);
manumaet 21:23bf4399020d 31 #endif
manumaet 26:a65c6f26c458 32 eventtimes[event_i] = RX_timestamp - TX_timestamp; // TODO: can give some wrong values because of timer reset after 17 seconds
manumaet 24:6f25ba679490 33 event[event_i][0] = '!';
manumaet 24:6f25ba679490 34 event[event_i][1] = 'R';
manumaet 24:6f25ba679490 35 event[event_i][2] = ' ';
manumaet 24:6f25ba679490 36 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 37 event[event_i][i+3] = messageRX[i];
manumaet 24:6f25ba679490 38 if (event_i == 8)
manumaet 24:6f25ba679490 39 event_i = 0;
manumaet 24:6f25ba679490 40 else
manumaet 24:6f25ba679490 41 event_i++;
manumaet 17:8afa5f9122da 42 dw.startRX();
manumaet 6:d5864a1b9e17 43 }
manumaet 6:d5864a1b9e17 44
manumaet 18:bbc7ca7d3a95 45 void callbackTX() {
manumaet 26:a65c6f26c458 46 TX_timestamp = dw.getTXTimestamp();
manumaet 24:6f25ba679490 47 eventtimes[event_i] = 0;
manumaet 24:6f25ba679490 48 event[event_i][0] = '!';
manumaet 24:6f25ba679490 49 event[event_i][1] = 'S';
manumaet 24:6f25ba679490 50 event[event_i][2] = ' ';
manumaet 24:6f25ba679490 51 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 52 event[event_i][i+3] = message[i];
manumaet 24:6f25ba679490 53 if (event_i == 8)
manumaet 24:6f25ba679490 54 event_i = 0;
manumaet 18:bbc7ca7d3a95 55 else
manumaet 24:6f25ba679490 56 event_i++;
manumaet 18:bbc7ca7d3a95 57 }
manumaet 18:bbc7ca7d3a95 58
manumaet 0:f50e671ffff7 59 int main() {
manumaet 27:71178fdb78e1 60 pc.printf("DecaWave 0.2\r\nup and running!\r\n");
manumaet 20:257d56530ae1 61 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
manumaet 4:6240b9c7a033 62 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 63 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 64 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 65
manumaet 26:a65c6f26c458 66 dw.setCallbacks(&callbackRX, &callbackTX);
manumaet 26:a65c6f26c458 67 dw.setInterrupt(true, true);
manumaet 17:8afa5f9122da 68 dw.startRX();
manumaet 5:111f11c95d27 69
manumaet 0:f50e671ffff7 70 while(1) {
manumaet 26:a65c6f26c458 71 for(int j = 0; j < 10; j++)
manumaet 26:a65c6f26c458 72 if(event[j][0] == '!') {
manumaet 26:a65c6f26c458 73 pc.printf("%s Time: %fus\r\n", event[j], eventtimes[j]*timeunit);
manumaet 26:a65c6f26c458 74 event[j][0] = 'X';
manumaet 24:6f25ba679490 75 }
manumaet 26:a65c6f26c458 76 #ifndef RECEIVER
manumaet 26:a65c6f26c458 77 sprintf(message, "%d", i); // send numbers to acknowledge
manumaet 26:a65c6f26c458 78 dw.sendString(message);
manumaet 26:a65c6f26c458 79 wait(1);
manumaet 17:8afa5f9122da 80 #endif
manumaet 15:e1fea7e2aff1 81 i++;
manumaet 0:f50e671ffff7 82 }
manumaet 0:f50e671ffff7 83 }