попытка дебажить PPS/SQW.
работа на SWSerial (8,9) вывод в консоль Serial и на LCD
This commit is contained in:
135
2024-07-27 12:36:14 +03:00
parent 7cccb3306c
commit 3f97f3f02a
6 changed files with 118 additions and 139 deletions

View File

@@ -23,12 +23,9 @@ static int pulse_count = 0;
static time_t gps_seconds_t = 0; // GPS time
static byte gps_sats = 0;
volatile bool GPS_sec = false; // flag for GPS-PPS
volatile unsigned long tmr_PPS;
// set interrupt flag
void gps_interrupt() {
tmr_PPS = micros();
Serial.print("DEBUG[INT] GPS interrupt: "); Serial.println(tmr_PPS);
//Serial.print("DEBUG[INT] GPS interrupt "); Serial.println(micros());
GPS_sec = true;
}
@@ -42,8 +39,6 @@ gps_fix fix; // This holds on to the latest values
//#define GPS_PORT_NAME "Serial"
#define GPS_PORT_NAME "AltSoftSerial"
#define DEBUG_PORT Serial
/***** Notice ********************************************
Edit file \Arduino\libraries\NeoGPS\src\NMEAGPS_cfg.h
UnComment line //#define NMEAGPS_PARSE_ZDA
@@ -70,19 +65,54 @@ gps_fix fix; // This holds on to the latest values
const long POSIX_Y2K_offset = 946684800; // = 10957 days = 30 years, NeoTime (GPS) & TimeLib (RTC) library use different Epoch year, 2000 & 1970
const long offset_28y = 883612800; // = 10227 days = 28 years, simple test for 2038 bug
const long offset_26w = 15724800; // = 182 days = 26 weeks, simple test for timezone
const long offset_135 = 123456; // = 135 seconds, simple test for timezone
const char baud19200 [] PROGMEM = "PUBX,41,1,3,3,19200,0";
const char baud38400 [] PROGMEM = "PUBX,41,1,3,3,38400,0";
const char GGA_off [] PROGMEM = "PUBX,40,GGA,0,0,0,0";
const char GLL_off [] PROGMEM = "PUBX,40,GLL,0,0,0,0";
const char GSA_off [] PROGMEM = "PUBX,40,GSA,0,0,0,0";
const char GSV_off [] PROGMEM = "PUBX,40,GSV,0,0,0,0";
const char VTG_off [] PROGMEM = "PUBX,40,VTG,0,0,0,0";
const char RMC_off [] PROGMEM = "PUBX,40,RMC,0,0,0,0";
const char ZDA_off [] PROGMEM = "PUBX,40,ZDA,0,0,0,0";
const char RMC_on [] PROGMEM = "PUBX,40,RMC,0,1,0,0";
const char ZDA_on [] PROGMEM = "PUBX,40,ZDA,0,1,0,0";
void GPS_setup() {
DEBUG_PORT.begin(38400);
DEBUG_PORT.println(F("DEBUG[GPS_setup()] start"));
pinMode(GPS_PPS_PIN, INPUT_PULLUP); // enable pullup on interrupt pin
attachInterrupt(digitalPinToInterrupt(GPS_PPS_PIN), gps_interrupt, RISING); // 100ms HIGH at start of second
GPS_sec = false;
gpsPort.begin(9600); // set PC to same baudrate for debug messages
gps.send_P(&gpsPort, (const __FlashStringHelper *) baud19200);
gpsPort.flush();
if (detRate(cfg_pin_GPS_Rx) != 38400) {
DEBUG_PORT.println(F("DEBUG[GPS_setup()] baudrate not 38400"));
gpsPort.begin(detRate(cfg_pin_GPS_Rx)); // set PC to same baudrate for debug messages
gps.send_P(&gpsPort, (const __FlashStringHelper *) baud38400);
gpsPort.flush();
delay(100);
gpsPort.end();
}
else
DEBUG_PORT.println(F("DEBUG[GPS_setup()] baudrate already 38400"));
gpsPort.begin(38400);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) GGA_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) GLL_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) GSA_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) GSV_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) VTG_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) RMC_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) ZDA_off);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) RMC_on);
delay(100);
gps.send_P(&gpsPort, (const __FlashStringHelper *) ZDA_on);
delay(100);
gpsPort.end();
gpsPort.begin(19200);
GPS_ON();
}
@@ -101,8 +131,6 @@ void GPS_PPS() { // do something on the flip of the GPS second
if (gps_seconds_t != 0) { // do only if value is set
// gps_seconds_t += offset_28y; // debug & testing only!
// gps_seconds_t += offset_26w; // debug & testing only!
// gps_seconds_t += offset_135;
Serial.println("DEBUG[GPS_PPS] difference PPS - SQW: " + String(tmr_PPS - tmr_SQW));
SetRTC(gps_seconds_t); // sync RTC with GPS
GPS_OFF();
}
@@ -127,13 +155,13 @@ void GPS_ON() {
gps_on = true;
gps_seconds_t = 0; // make shure GPS serial is alive before setting
pulse_count = 0;
Serial.println("GPS: ON"); // debug
//Serial.println("GPS: ON"); // debug
}
void GPS_OFF() {
if (gps_on) { // only if NOT off
gps_on = false;
Serial.println("GPS: OFF"); // debug
//Serial.println("GPS: OFF"); // debug
}
}