tweaked, ready for testing with real scintillators
This commit is contained in:
parent
ae47874639
commit
4efa743882
3 changed files with 255 additions and 69 deletions
|
|
@ -1 +0,0 @@
|
||||||
,jimmy,jimmy-Edgar,14.03.2017 01:17,file:///home/jimmy/.config/libreoffice/4;
|
|
||||||
|
|
@ -10,15 +10,25 @@ long PPSLength = 0; //The number of internal clock cycles in a GPS PPS
|
||||||
long PPSUptime = 0; //The number of PPS pulses counted since the last reboot.
|
long PPSUptime = 0; //The number of PPS pulses counted since the last reboot.
|
||||||
long PreviousPPS = 0; //The value of the previous PPS (to define which second we're in)
|
long PreviousPPS = 0; //The value of the previous PPS (to define which second we're in)
|
||||||
int EventsThisSecond = 0; //The number of events since the last PPS
|
int EventsThisSecond = 0; //The number of events since the last PPS
|
||||||
bool dump = false; //if there's an event, dump the data.
|
int EventsLastSecond = 0; //events in the last second
|
||||||
|
bool dump = false; //if there's an event, dump the data
|
||||||
|
bool OutputFlag = false;
|
||||||
int Ch1Offset = 240; //Channel 1 trigger offset
|
int Ch1Offset = 240; //Channel 1 trigger offset
|
||||||
int Ch2Offset = 240; //Channel 2 trigger offset
|
int Ch2Offset = 240; //Channel 2 trigger offset
|
||||||
bool tempflipvar = true; //flash the light when GPS is locked
|
bool tempflipvar = true; //flash the light when GPS is locked
|
||||||
bool tempevtvar = false; //temp event value
|
bool tempevtvar = false; //temp event value
|
||||||
|
bool changingvoltage = false; //when changing the voltage ignore inputs for a few seconds
|
||||||
int readthresholdCh1 = 0; //read in values for the thresholds; for software triggering
|
int readthresholdCh1 = 0; //read in values for the thresholds; for software triggering
|
||||||
int readthresholdCh2 = 0;
|
int readthresholdCh2 = 0;
|
||||||
int calcthreshCh1 = 0; //calcualte the thresholds
|
int calcthreshCh1 = 0; //calcualte the thresholds
|
||||||
int calcthreshCh2 = 0;
|
int calcthreshCh2 = 0;
|
||||||
|
int Ch1SetPoint = 0;
|
||||||
|
int Ch2SetPoint = 0;
|
||||||
|
int VoltageSetPoint = 0;
|
||||||
|
int CMFEvents = 0;
|
||||||
|
float EventRate = 0;
|
||||||
|
float PressureTempVal = 0;
|
||||||
|
float PressureTempValOld = 0;
|
||||||
|
|
||||||
//SoftSPI pin assignments
|
//SoftSPI pin assignments
|
||||||
#define SS_pin 42
|
#define SS_pin 42
|
||||||
|
|
@ -70,6 +80,26 @@ unsigned long oldtime = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
||||||
|
// Issue 20 I2C clocks to make sure no slaves are hung in a read
|
||||||
|
pinMode(20, OUTPUT);
|
||||||
|
pinMode(21, OUTPUT);
|
||||||
|
pinMode(70, OUTPUT);
|
||||||
|
pinMode(71, OUTPUT);
|
||||||
|
digitalWrite(20, LOW);
|
||||||
|
digitalWrite(70, LOW);
|
||||||
|
for (int i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(21, LOW);
|
||||||
|
digitalWrite(71, LOW);
|
||||||
|
delayMicroseconds(10);
|
||||||
|
digitalWrite(21, HIGH);
|
||||||
|
digitalWrite(71, HIGH);
|
||||||
|
delayMicroseconds(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Start Wire (I2C comms)
|
//Start Wire (I2C comms)
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
Wire1.begin();
|
Wire1.begin();
|
||||||
|
|
@ -113,7 +143,51 @@ void setup() {
|
||||||
|
|
||||||
PressureSetup();
|
PressureSetup();
|
||||||
Serial.println("Temp:");
|
Serial.println("Temp:");
|
||||||
Serial.println(PressureTemp());
|
PressureTempVal = PressureTemp();
|
||||||
|
Serial.println(PressureTempVal);
|
||||||
|
PressureTempValOld = PressureTempVal;
|
||||||
|
|
||||||
|
//We're going to do the single chan. calibration now
|
||||||
|
//stage 1 - set the channels; Ch A is being calibrated. Set this value to 255
|
||||||
|
//Channel B isn't, so set it to 0 (i.e. always triggering).
|
||||||
|
/*
|
||||||
|
//These are the values to scan Ch1
|
||||||
|
Ch1SetPoint = 0;
|
||||||
|
Ch2SetPoint = 134; //note this doesn't seem to work under 30..
|
||||||
|
ThresholdSet(Ch1SetPoint,Ch2SetPoint);
|
||||||
|
*/
|
||||||
|
//These are the values to scan Ch1
|
||||||
|
Ch1SetPoint = 255;
|
||||||
|
Ch2SetPoint = 255; //note this doesn't seem to work under 30..
|
||||||
|
ThresholdSet(Ch1SetPoint, Ch2SetPoint);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//now we set the HV bias
|
||||||
|
VoltageSetPoint = (HVSetpoints[int(PressureTemp() + 0.5)] - 7);
|
||||||
|
VbiasSet(VoltageSetPoint);//VoltageSetPoint);
|
||||||
|
OutputFlag = false;
|
||||||
|
delay(1000); //wait for the GPS to start up
|
||||||
|
TimerInit();
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println("Threshold start values");
|
||||||
|
int Ch1 = analogRead(A1);
|
||||||
|
int Ch2 = analogRead(A2);
|
||||||
|
Serial.print(Ch1);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(Ch2);
|
||||||
|
Serial.println("Analogue Values");
|
||||||
|
Ch1 = analogRead(A6);
|
||||||
|
Ch2 = analogRead(A7);
|
||||||
|
Serial.print(Ch1);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(Ch2);
|
||||||
|
|
||||||
|
Serial.println("loop starting");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]+5);
|
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]+5);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
//set the thresholds; rewrite this to not echo in future
|
//set the thresholds; rewrite this to not echo in future
|
||||||
|
|
@ -150,6 +224,7 @@ void setup() {
|
||||||
|
|
||||||
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]);
|
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//ADCSetup();
|
//ADCSetup();
|
||||||
|
|
@ -163,9 +238,105 @@ void setup() {
|
||||||
//TimerInit();
|
//TimerInit();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Serial.print("VoltageSetPoint");
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print("Ch1SetPoint");
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print("Ch2SetPoint");
|
||||||
|
Serial.print("; ");
|
||||||
|
|
||||||
|
Serial.print("EventsLastSecond");
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print("EventRate");
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print("CMFEvents");
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print("PPSUptime");
|
||||||
|
Serial.println("; ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
ThresholdSet(Ch1SetPoint, Ch2SetPoint);
|
||||||
|
//Serial.println(Ch1SetPoint);
|
||||||
|
//Serial.println(Ch2SetPoint);
|
||||||
|
//Serial.println(Ch2SetPoint);
|
||||||
|
/* int Ch1 = analogRead(A1);
|
||||||
|
int Ch2 = analogRead(A2);
|
||||||
|
int ChA = analogRead(A6);
|
||||||
|
int ChB = analogRead(A7);
|
||||||
|
Serial.print(Ch1);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print(Ch2);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print(ChA);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(ChB);
|
||||||
|
*/
|
||||||
|
PressureTempVal = PressureTemp();
|
||||||
|
//Serial.println(PressureTempVal);
|
||||||
|
//Serial.println(PressureTempValOld);
|
||||||
|
if (int(PressureTempValOld+0.5) != int(PressureTempVal+0.5))
|
||||||
|
{
|
||||||
|
VoltageSetPoint = (HVSetpoints[int(PressureTempVal + 0.5)] - 7);
|
||||||
|
VbiasSet(VoltageSetPoint);//VoltageSetPoint);
|
||||||
|
delay(1000);
|
||||||
|
Serial.println("changed voltage");
|
||||||
|
Serial.println(PressureTempVal);
|
||||||
|
Serial.println(PressureTempValOld);
|
||||||
|
PressureTempValOld = PressureTempVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (OutputFlag)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|
||||||
|
Serial.println("Got some events");
|
||||||
|
Serial.println(Ch1SetPoint);
|
||||||
|
Serial.println(EventsLastSecond);
|
||||||
|
Serial.println("End of Readout");
|
||||||
|
Serial.println("Threshold values");
|
||||||
|
int Ch1 = analogRead(A1);
|
||||||
|
int Ch2 = analogRead(A2);
|
||||||
|
Serial.print(Ch1);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(Ch2);
|
||||||
|
Serial.println("Analogue Values");
|
||||||
|
Ch1 = analogRead(A6);
|
||||||
|
Ch2 = analogRead(A7);
|
||||||
|
Serial.print(Ch1);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(Ch2);
|
||||||
|
*/
|
||||||
|
Serial.print(VoltageSetPoint);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(Ch1SetPoint);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(Ch2SetPoint);
|
||||||
|
Serial.print("; ");
|
||||||
|
|
||||||
|
Serial.print(EventsLastSecond);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(EventRate);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(CMFEvents);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(PPSUptime);
|
||||||
|
Serial.print("; ");
|
||||||
|
Serial.print(float(CMFEvents)/float(PPSUptime));
|
||||||
|
Serial.println("; ");
|
||||||
|
|
||||||
|
|
||||||
|
OutputFlag = false;
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// Serial.println("Nothing");
|
||||||
|
// }
|
||||||
|
|
||||||
|
/*
|
||||||
// for (int i = 0; i < 220; i++)
|
// for (int i = 0; i < 220; i++)
|
||||||
// {
|
// {
|
||||||
// VbiasSet(i);
|
// VbiasSet(i);
|
||||||
|
|
@ -185,6 +356,7 @@ void loop() {
|
||||||
|
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -244,25 +416,40 @@ void TC0_Handler() {
|
||||||
//This is called the one second event interrupt in documentation
|
//This is called the one second event interrupt in documentation
|
||||||
//when the PPS event occurs
|
//when the PPS event occurs
|
||||||
PPSLength = TC0->TC_CHANNEL[0].TC_RA; // Read the RA reg (PPS period)
|
PPSLength = TC0->TC_CHANNEL[0].TC_RA; // Read the RA reg (PPS period)
|
||||||
TC_GetStatus(TC0, 0); // Read status and clear load bits
|
//Ch2SetPoint--;
|
||||||
tempflipvar = !tempflipvar;
|
if (EventsThisSecond > 2)
|
||||||
digitalWrite(Power_LED, tempflipvar);
|
{
|
||||||
|
EventsThisSecond = 1; //we consider that >1 events is bounce, not events, this is <3% probable
|
||||||
|
}
|
||||||
|
EventsLastSecond = EventsThisSecond;
|
||||||
|
CMFEvents = CMFEvents + EventsLastSecond;
|
||||||
|
EventRate = (EventRate + EventsLastSecond) / 2;
|
||||||
|
OutputFlag = true;
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// OutputFlag= false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
EventsThisSecond = 0;
|
||||||
digitalWrite(Event_LED, 0);
|
digitalWrite(Event_LED, 0);
|
||||||
|
|
||||||
|
TC_GetStatus(TC0, 0); // Read status and clear load bits
|
||||||
|
|
||||||
|
tempflipvar = !tempflipvar;
|
||||||
|
digitalWrite(Power_LED, tempflipvar);
|
||||||
|
//digitalWrite(Event_LED, 0);
|
||||||
|
|
||||||
PPSUptime++; // PPS count
|
PPSUptime++; // PPS count
|
||||||
EventsThisSecond = 0; //reset the event counter for this second
|
//EventsThisSecond = 0; //reset the event counter for this second
|
||||||
}
|
}
|
||||||
|
|
||||||
void TC6_Handler() {
|
void TC6_Handler() {
|
||||||
Serial.println("Cosmic");
|
//This is called when the trigger is activated
|
||||||
//rega1 = TC2->TC_CHANNEL[0].TC_RA; // Read the RA on channel 1 (PPS period)
|
//EventTimestamp[EventsThisSecond] = TC0->TC_CHANNEL[0].TC_RA; //read the main clock and copy it to the event register
|
||||||
//stsr1 =
|
EventsThisSecond++; //increment the event counter for this second
|
||||||
// tempevtvar=!tempevtvar;
|
|
||||||
digitalWrite(Event_LED, 1);
|
digitalWrite(Event_LED, 1);
|
||||||
|
|
||||||
|
|
||||||
EventTimestamp[EventsThisSecond] = TC0->TC_CHANNEL[0].TC_RA; //read the main clock and copy it to the event register
|
|
||||||
EventsThisSecond++; //increment the event counter for this second
|
|
||||||
TC_GetStatus(TC2, 0); // Read status clear load bits, unlocking this interrupt.
|
TC_GetStatus(TC2, 0); // Read status clear load bits, unlocking this interrupt.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue