From e3abcb64f324f85fa7c10d139dc0fe20b03d80fa Mon Sep 17 00:00:00 2001 From: James Devine Date: Sun, 18 Dec 2016 18:10:28 +0100 Subject: [PATCH] --- CPiThreshold.ino | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CPiThreshold.ino diff --git a/CPiThreshold.ino b/CPiThreshold.ino new file mode 100644 index 0000000..ceaa82c --- /dev/null +++ b/CPiThreshold.ino @@ -0,0 +1,52 @@ +#include + +//this test works when testing with boards 1 and 2 +//set the threshold as a 1 time value, max is 3.3V (voltage reference removed from protos) +//crashes due to 50Hz noise +//input thresholds not checked 100% +//minimum input signal duration 40ns for coincidence. +//at 40ns incident coincidence the output lasts for 150ns - plenty for the DUE to capture. +//Hardware is more reliable than DUE's noise immunity. +//Note the MAX5387LAUD+ doesn't support I2C readback. + +//detailed threshold calibration could be done, but our signal generator doesn't plug in very well. +//using DAC would be a nice option for checking the thresholds. +byte ADCval; + +void setup() { + // put your setup code here, to run once: + pinMode(35, OUTPUT); //setup for the MAX5387 - later set to 0. signal PA0 + pinMode(36, OUTPUT);//setup for the MAX5387 - later set to 0. signal PA1 + pinMode(37, OUTPUT);//setup for the MAX5387 - later set to 0. signal PA2 + pinMode(A1, INPUT); //make sure the input pins are in high impedance mode + pinMode(A2, INPUT);//make sure the input pins are in high impedance mode + digitalWrite(35, LOW);//configure the address of the MAX5387 pot + digitalWrite(36, LOW);//configure the address of the MAX5387 pot + digitalWrite(37, LOW);//configure the address of the MAX5387 pot + pinMode(5, INPUT); //set the interrupt pin for trigger as high impedance, probably not required + + //setup the serial for debug + Serial.begin(9600); + //setup the MAX5387 pot + ADCval = byte(0x00); +} + + +void loop() { + Wire.begin(); + //Serial.print("MAX5387 Address "); + //Serial.print(0x28, HEX); + Wire.beginTransmission(byte(0x28)); // transmit to device #112 + Wire.write(byte(B00010011)); + Wire.write(ADCval);// sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + Serial.print("Setpoint:"); //note that this is manually updated by the human! + Serial.print(ADCval); //note that this is manually updated by the human! + Serial.print("; A1:"); //note that this is manually updated by the human! + Serial.print(analogRead(A1)); + Serial.print("; A2:"); //note that this is manually updated by the human! + Serial.print(analogRead(A2)); + Serial.println(";"); //note that this is manually updated by the human! + delay(1000); + ADCval++; +} \ No newline at end of file