Updated the event timing functionality to remove the need for a diode.

Summary of new functionality:
Upon event interrupt, the current value of the TC0 counter is pushed to the counter buffer.
The TC2 status (interrupt unlatch) is reset at the end of the interrupt call.
Running it to test the GPS accuracy, we've got a fixed offset of 54 clock counts, variation up to +2 counts.
This commit is contained in:
James Devine 2016-04-23 17:02:48 +02:00
parent a0550a01f5
commit a3a422fd41

View file

@ -320,10 +320,10 @@ void TC0_Handler() {
// hence the debug flag which I look at with a scope to be sure. // hence the debug flag which I look at with a scope to be sure.
// I may introduce a small delay line to ensure this is true, so far it is. // I may introduce a small delay line to ensure this is true, so far it is.
ppsfl = HIGH; // Seen a rising edge on the PPS // ppsfl = HIGH; // Seen a rising edge on the PPS
#if FLG_PIN //#if FLG_PIN
digitalWrite(FLG_PIN,ppsfl); // Flag set (for debug) // digitalWrite(FLG_PIN,ppsfl); // Flag set (for debug)
#endif //#endif
rega0 = TC0->TC_CHANNEL[0].TC_RA; // Read the RA reg (PPS period) rega0 = TC0->TC_CHANNEL[0].TC_RA; // Read the RA reg (PPS period)
stsr0 = TC_GetStatus(TC0, 0); // Read status and clear load bits stsr0 = TC_GetStatus(TC0, 0); // Read status and clear load bits
@ -359,6 +359,21 @@ static char t2[DATE_TIME_LEN];
static char *wdtm = t1; // Write date/time pointer static char *wdtm = t1; // Write date/time pointer
static char *rdtm = t2; // Read date/time pointer static char *rdtm = t2; // Read date/time pointer
// Pull all data (16 values) from the ADC into a buffer
uint8_t AdcPullData(struct Event *b) {
int i;
for (i=0; i<ADC_BUF_LEN; i++) { // For all in ADC pipeline
while((ADC->ADC_ISR & 0x01)==0); // Wait for channel 0 (2.5us)
b->Ch0[i] = (uint16_t) ADC->ADC_CDR[0]; // Read ch 0
while((ADC->ADC_ISR & 0x02)==0); // Wait for channel 1 (2.5us)
b->Ch1[i] = (uint16_t) ADC->ADC_CDR[1]; // Read ch 1
}
}
// Swap read write event buffers and indexes along with their time strings // Swap read write event buffers and indexes along with their time strings
// each second, so we have the current and previous second numbers // each second, so we have the current and previous second numbers
@ -383,30 +398,30 @@ void TC6_Handler() {
// and if its high we are seeing the PPS here, but if the // and if its high we are seeing the PPS here, but if the
// flag is not set then this is a cosmic ray event. // flag is not set then this is a cosmic ray event.
if (ppsfl == HIGH) { // Was ther a PPS ? // if (ppsfl == HIGH) { // Was ther a PPS ?
ppsfl = LOW; // Yes so we have seen it here // ppsfl = LOW; // Yes so we have seen it here
SwapBufs(); // Every PPS swap the read/write buffers // SwapBufs(); // Every PPS swap the read/write buffers
#if EVT_PIN //#if EVT_PIN
digitalWrite(EVT_PIN,LOW); // Not an event // digitalWrite(EVT_PIN,LOW); // Not an event
#endif //#endif
} else { // } else {
#if EVT_PIN //#if EVT_PIN
digitalWrite(EVT_PIN,HIGH); // Event detected // digitalWrite(EVT_PIN,HIGH); // Event detected
#endif //#endif
if (widx < PPS_EVENTS) { // Up to PPS_EVENTS stored per PPS if (widx < PPS_EVENTS) { // Up to PPS_EVENTS stored per PPS
// Read the latched tick count getting the event time // Read the latched tick count getting the event time
// and then pull the ADC pipe line // and then pull the ADC pipe line
wbuf[widx].Tks = TC2->TC_CHANNEL[0].TC_RA; wbuf[widx].Tks = TC0->TC_CHANNEL[0].TC_CV;
AdcPullData(&wbuf[widx]); AdcPullData(&wbuf[widx]);
widx++; widx++;
} }
} // }
#if FLG_PIN //#if FLG_PIN
digitalWrite(FLG_PIN,ppsfl); // Flag out // digitalWrite(FLG_PIN,ppsfl); // Flag out
#endif //#endif
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 = TC_GetStatus(TC2, 0); // Read status clear load bits stsr1 = TC_GetStatus(TC2, 0); // Read status clear load bits
} }
@ -539,20 +554,6 @@ void AdcSetup() {
REG_ADC_CHER = 3; // Channels 0 and 1 REG_ADC_CHER = 3; // Channels 0 and 1
} }
// Pull all data (16 values) from the ADC into a buffer
uint8_t AdcPullData(struct Event *b) {
int i;
for (i=0; i<ADC_BUF_LEN; i++) { // For all in ADC pipeline
while((ADC->ADC_ISR & 0x01)==0); // Wait for channel 0 (2.5us)
b->Ch0[i] = (uint16_t) ADC->ADC_CDR[0]; // Read ch 0
while((ADC->ADC_ISR & 0x02)==0); // Wait for channel 1 (2.5us)
b->Ch1[i] = (uint16_t) ADC->ADC_CDR[1]; // Read ch 1
}
}
// This is the nmea data string from the GPS chip // This is the nmea data string from the GPS chip
#define GPS_STRING_LEN 256 #define GPS_STRING_LEN 256