added spreadsheet

This commit is contained in:
James Devine 2017-03-14 01:19:44 +01:00
parent 9b053b3c87
commit ae47874639
4 changed files with 198 additions and 152 deletions

View file

@ -0,0 +1 @@
,jimmy,jimmy-Edgar,14.03.2017 01:17,file:///home/jimmy/.config/libreoffice/4;

View file

@ -11,6 +11,14 @@ 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. bool dump = false; //if there's an event, dump the data.
int Ch1Offset = 240; //Channel 1 trigger offset
int Ch2Offset = 240; //Channel 2 trigger offset
bool tempflipvar = true; //flash the light when GPS is locked
bool tempevtvar = false; //temp event value
int readthresholdCh1 = 0; //read in values for the thresholds; for software triggering
int readthresholdCh2 = 0;
int calcthreshCh1 = 0; //calcualte the thresholds
int calcthreshCh2 = 0;
//SoftSPI pin assignments //SoftSPI pin assignments
#define SS_pin 42 #define SS_pin 42
@ -43,15 +51,18 @@ bool dump = false; //if there's an event, dump the data.
#define AccelFullScale 2.0 // +-2g 16 bit 2's compliment #define AccelFullScale 2.0 // +-2g 16 bit 2's compliment
#define GravityEarth 9.80665 //The earth's gravity #define GravityEarth 9.80665 //The earth's gravity
const int HVSetpoints[50] = {0x8F,0x8F,0x8E,0x8D,0x8D,0x8C,0x8B,0x8B,0x8A,0x89,
0x89,0x88,0x87,0x87,0x86,0x86,0x85,0x84,0x84,0x83, //this table is WAY OFF
0x82,0x82,0x81,0x80,0x80,0x7F,0x7E,0x7E,0x7D,0x7D, const int HVSetpoints[50] = {98,98,97,97,96, 96,95,95,94,94,
0x7C,0x7B,0x7B,0x7A,0x79,0x79,0x78,0x77,0x77,0x76, 93,93,92,92,91, 91,90,90,89,88,
0x75,0x75,0x74,0x73,0x73,0x72,0x72,0x71,0x70,0x70}; 88,87,87,86,86, 85,85,84,84,83,
83,82,82,81,81, 80,80,79,79,78,
78,77,77,76,76, 75,75,74,74,73
};
//HV setpoints, starting from 0 to 50 degrees (i.e. 0th element is 0 degrees) - add 0.5 and cast as an int for the index. //HV setpoints, starting from 0 to 50 degrees (i.e. 0th element is 0 degrees) - add 0.5 and cast as an int for the index.
String StringEventBuf[3] = {"Output String Buffer Event 1", "Output String Buffer Event 2", "Output String Buffer Event 3"}; String StringEventBuf[3] = {"Output String Buffer Event 1", "Output String Buffer Event 2", "Output String Buffer Event 3"};
long EventTimestamp[3] = {0,0,0}; long EventTimestamp[3] = {0, 0, 0};
float Accel[3]; //Accelerometer array, 0 is X, 1 is Y and 2 is Z. float Accel[3]; //Accelerometer array, 0 is X, 1 is Y and 2 is Z.
unsigned long timeX = 0; unsigned long timeX = 0;
unsigned long oldtime = 0; unsigned long oldtime = 0;
@ -89,64 +100,91 @@ void setup() {
digitalWrite(AccelSA1, LOW); digitalWrite(AccelSA1, LOW);
Serial.begin(9600);//we run the serial at 9600 for debugging only.
//make sure the LED's are off //make sure the LED's are off
digitalWrite(Power_LED, 0); digitalWrite(Power_LED, 0);
digitalWrite(Event_LED, 0); digitalWrite(Event_LED, 0);
PressureSetup();
VbiasSet(HVSetpoints[int(PressureTemp()+0.5)]);
//VbiasSet(100);
ThresholdSet(130,130);
//ADCSetup(); //Turn on the ON led
//TimerInit();
PowerOn(); PowerOn();
ThresholdSet(255, 255);
//debug output
Serial.begin(9600);//we run the serial at 9600 for debugging only.
PressureSetup();
Serial.println("Temp:");
Serial.println(PressureTemp());
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]+5);
delay(1000);
//set the thresholds; rewrite this to not echo in future
//read the threshold setpoints
Serial.println("Initial Threshold values");
int Ch1 = analogRead(A1);
int Ch2 = analogRead(A2);
Serial.print(Ch1);
Serial.print(" ");
Serial.println(Ch2);
Serial.println("Backed-off Analogue values");
Ch1 = analogRead(A6);
Ch2 = analogRead(A7);
Serial.print(Ch1);
Serial.print(" ");
Serial.println(Ch2);
calcthreshCh1 =(Ch1+Ch1Offset) >> 2;
calcthreshCh2 =(Ch2+Ch2Offset) >> 2;
ThresholdSet(calcthreshCh1,calcthreshCh2);
Serial.println("Calculated threshold values");
Serial.print(calcthreshCh1);
Serial.print(" ");
Serial.println(calcthreshCh2);
Serial.println("New Threshold values");
readthresholdCh1 = analogRead(A1);
readthresholdCh2 = analogRead(A2);
Serial.print(readthresholdCh1);
Serial.print(" ");
Serial.println(readthresholdCh2);
VbiasSet(HVSetpoints[int(PressureTemp() + 0.5)]);
delay(1000);
/*
//ADCSetup();
//AccelSetup(); //AccelSetup();
SerialNumberValue = SerialNumberReadout(); SerialNumberValue = SerialNumberReadout();
Serial.println(SerialNumberValue); Serial.println(SerialNumberValue);
Serial.println("finished init"); Serial.println("finished init");
timeX = millis(); //timeX = millis();
Serial.print("analogue values "); Serial.println("analogue values ");
int Ch1 = analogRead(A6);
int Ch2 = analogRead(A7);
Serial.print(Ch1);
Serial.print(" ");
Serial.println(Ch2);
//) + " " + int(analogRead(A7))); //TimerInit();
*/
} }
void loop() { void loop() {
//Serial.println(String(analogRead(A6))+" "+String(analogRead(A7))+" " +int(digitalRead(Event_Input))); // for (int i = 0; i < 220; i++)
Serial.println(PressureTemp()); // {
// VbiasSet(i);
// delay(100);
// for (int i = 0; i < 5; i++)
// {
int Ch1 = analogRead(A6);
int Ch2 = analogRead(A7);
if (Ch1 > readthresholdCh1) {
if (Ch2 > readthresholdCh2) {
Serial.print(Ch1);
Serial.print(" ");
Serial.println(Ch2);
}
delay(1000); }
/*
if (digitalRead(Event_Input)) {
Serial.print("Event ");
oldtime = timeX;
timeX = millis();
//prints time since program started
Serial.println(timeX - oldtime);
EventFlashOn();
delay(50);
EventFlashOff();
}
// Serial.println("temp");
// Serial.println(HumReadTemp());
//delay(1000);
// Serial.println("Hum"); //}
// Serial.println(HumReadHum()); //}
//delay(1000);
//ThresholdSet(200,20);
//Serial.println("Accel");
//AccelRead();
// Serial.println(String(Accel[0])+" "+ String(Accel[1])+" "+ String(Accel[2]));
*/
} }
@ -193,29 +231,36 @@ void TimerInit() {
// Set up the PIO controller to route input pins for TC0 and TC2 // Set up the PIO controller to route input pins for TC0 and TC2
PIO_Configure(PIOC,PIO_INPUT, PIO_Configure(PIOC, PIO_INPUT,
PIO_PB25B_TIOA0, // D2 Input for PPS PIO_PB25B_TIOA0, // D2 Input for PPS
PIO_DEFAULT); PIO_DEFAULT);
PIO_Configure(PIOC,PIO_INPUT, PIO_Configure(PIOC, PIO_INPUT,
PIO_PC25B_TIOA6, // D5 Input for Trigger PIO_PC25B_TIOA6, // D5 Input for Trigger
PIO_DEFAULT); PIO_DEFAULT);
} }
void TC0_Handler() { 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 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"); Serial.println("Cosmic");
//rega1 = TC2->TC_CHANNEL[0].TC_RA; // Read the RA on channel 1 (PPS period) //rega1 = TC2->TC_CHANNEL[0].TC_RA; // Read the RA on channel 1 (PPS period)
//stsr1 = //stsr1 =
// tempevtvar=!tempevtvar;
digitalWrite(Event_LED, 1);
EventTimestamp[EventsThisSecond] = TC0->TC_CHANNEL[0].TC_RA; //read the main clock and copy it to the event register 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 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.
@ -229,16 +274,16 @@ void ADCSetup() {
} }
void PowerOn(){ void PowerOn() {
digitalWrite(Power_LED, 1); digitalWrite(Power_LED, 1);
} }
void EventFlashOn(){ void EventFlashOn() {
digitalWrite(Event_LED, 1); digitalWrite(Event_LED, 1);
} }
void EventFlashOff(){ void EventFlashOff() {
digitalWrite(Event_LED, 0); digitalWrite(Event_LED, 0);
} }
@ -249,7 +294,7 @@ String SerialNumberReadout() {
unsigned int pdwUniqueID[4]; unsigned int pdwUniqueID[4];
/* Send the Start Read unique Identifier command (STUI) /* Send the Start Read unique Identifier command (STUI)
* by writing the Flash Command Register with the STUI command. by writing the Flash Command Register with the STUI command.
*/ */
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI; EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI;
do { do {
@ -257,7 +302,7 @@ String SerialNumberReadout() {
} while ((status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY); } while ((status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY);
/* The Unique Identifier is located in the first 128 bits of the /* The Unique Identifier is located in the first 128 bits of the
* Flash memory mapping. So, at the address 0x400000-0x400003. Flash memory mapping. So, at the address 0x400000-0x400003.
*/ */
pdwUniqueID[0] = *(uint32_t *)IFLASH1_ADDR; pdwUniqueID[0] = *(uint32_t *)IFLASH1_ADDR;
pdwUniqueID[1] = *(uint32_t *)(IFLASH1_ADDR + 4); pdwUniqueID[1] = *(uint32_t *)(IFLASH1_ADDR + 4);
@ -265,37 +310,37 @@ String SerialNumberReadout() {
pdwUniqueID[3] = *(uint32_t *)(IFLASH1_ADDR + 12); pdwUniqueID[3] = *(uint32_t *)(IFLASH1_ADDR + 12);
/* To stop the Unique Identifier mode, the user needs to send the Stop Read unique Identifier /* To stop the Unique Identifier mode, the user needs to send the Stop Read unique Identifier
* command (SPUI) by writing the Flash Command Register with the SPUI command. command (SPUI) by writing the Flash Command Register with the SPUI command.
*/ */
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI ; EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI ;
/* When the Stop read Unique Unique Identifier command (SPUI) has been performed, the /* When the Stop read Unique Unique Identifier command (SPUI) has been performed, the
* FRDY bit in the Flash Programming Status Register (EEFC_FSR) rises. FRDY bit in the Flash Programming Status Register (EEFC_FSR) rises.
*/ */
do { do {
status = EFC1->EEFC_FSR ; status = EFC1->EEFC_FSR ;
} while ((status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY); } while ((status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY);
int uid_ok = 0; int uid_ok = 0;
String uidtxt; String uidtxt;
uidtxt = String(pdwUniqueID[0]) + String(pdwUniqueID[1]) + String(pdwUniqueID[2]) + String(pdwUniqueID[3]); uidtxt = String(pdwUniqueID[0]) + String(pdwUniqueID[1]) + String(pdwUniqueID[2]) + String(pdwUniqueID[3]);
return uidtxt; return uidtxt;
} }
float ADCTemp(){ float ADCTemp() {
//Routine uses the internal temperature sensor in the Arduino DUE //Routine uses the internal temperature sensor in the Arduino DUE
//Note this uses the ADC //Note this uses the ADC
float trans = 3.3/4096; float trans = 3.3 / 4096;
float offset = 0.8; float offset = 0.8;
float factor = 0.00256; float factor = 0.00256;
int fixtemp = 27; int fixtemp = 27;
uint32_t ulValue = 0; uint32_t ulValue = 0;
uint32_t ulChannel; uint32_t ulChannel;
//BUG: The ADC needs to be reset using these register values; otherwise the values read out are WRONG. //BUG: The ADC needs to be reset using these register values; otherwise the values read out are WRONG.
//REG_ADC_MR = 0x00000000; // Void this register //REG_ADC_MR = 0x00000000; // Void this register
//REG_ADC_CHER = 0; // No channels running //REG_ADC_CHER = 0; // No channels running
@ -318,8 +363,8 @@ uint32_t ulChannel;
// Disable the corresponding channel // Disable the corresponding channel
adc_disable_channel(ADC, ADC_TEMPERATURE_SENSOR); adc_disable_channel(ADC, ADC_TEMPERATURE_SENSOR);
float treal = fixtemp + (( trans * ulValue ) - offset ) / factor; float treal = fixtemp + (( trans * ulValue ) - offset ) / factor;
return treal; return treal;
} }

BIN
CosmicPiHVSetpoints.ods Normal file

Binary file not shown.

View file

@ -7,7 +7,7 @@ void ThresholdSet(int ThreshA, int ThreshB) {
// Serial.println("Test of threshold setting"); // Serial.println("Test of threshold setting");
// Serial.print(ThreshA); // Serial.print(ThreshA);
//Serial.println(analogRead(A1)); //internal readback of the DREF value only, not returned to main code. //Serial.println(analogRead(A1)); //internal readback of the DREF value only, not returned to main code.
Wire.beginTransmission(0x28); // transmit to device #94 (0x5F) Wire.beginTransmission(I2CPot); // transmit to device #94 (0x5F)
// device address is specified in datasheet // device address is specified in datasheet
Wire.write(0x11); // sends instruction byte Wire.write(0x11); // sends instruction byte
Wire.write(ThreshA); // sends potentiometer value byte Wire.write(ThreshA); // sends potentiometer value byte
@ -59,7 +59,7 @@ void VbiasSet(int Vbias) {
digitalWrite(SS_pin, LOW); // SS low digitalWrite(SS_pin, LOW); // SS low
for (int i = 0; i < 8; i++) // There are 8 bits in a byte for (int i = 0; i < 8; i++) // There are 8 bits in a byte
{ {
digitalWrite(MOSI_pin, bitRead(_send, i-7)); // Set MOSI digitalWrite(MOSI_pin, bitRead(_send, 7-i)); // Set MOSI
digitalWrite(SCK_pin, HIGH); // SCK high digitalWrite(SCK_pin, HIGH); // SCK high
//bitWrite(_receive, i, digitalRead(MISO_pin)); // Capture MISO //bitWrite(_receive, i, digitalRead(MISO_pin)); // Capture MISO
digitalWrite(SCK_pin, LOW); // SCK low digitalWrite(SCK_pin, LOW); // SCK low