Compare commits

...

3 commits

2 changed files with 122 additions and 86 deletions

View file

@ -200,6 +200,39 @@ bool setGPS_OutputFreq16MHz()
return gps_set_sucess;
}
// 360Hz
bool setGPS_OutputFreq360Hz()
{
int gps_set_sucess=0;
uint8_t setOutputFreq[] = {
0xb5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x68, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0x62, 0xca,
};
sendUBX(setOutputFreq, sizeof(setOutputFreq)/sizeof(uint8_t));
gps_set_sucess=getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
}
// 5Hz
bool setGPS_OutputFreq5Hz()
{
int gps_set_sucess=0;
uint8_t setOutputFreq[] = {
0xb5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0xfe, 0xfb,
};
sendUBX(setOutputFreq, sizeof(setOutputFreq)/sizeof(uint8_t));
gps_set_sucess=getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
}
void sendUBX(uint8_t *MSG, uint8_t len) {
gpsPort.flush();
@ -257,4 +290,4 @@ boolean getUBX_ACK(uint8_t *MSG) {
}//else
}//If
}//While
}//getUBX_ACK
}//getUBX_ACK

View file

@ -15,11 +15,19 @@ SoftwareSerial gpsPort(2, 3); // RX, TX
#define FIXOut 4 //Pin Out at IDC. Indicator for GPS Lock on pin 4
#define LDO_Enable A3 //GPS Voltage regulator Enable on pin A3
boolean GPSOK;
const char softwareversion[] = "1.05" ; //Version of this program, sent to serialport at startup
#define softwareversion "1.05" //Version of this program, sent to serialport at startup
NMEAGPS gps; // This parses the GPS characters
gps_fix fix; // This holds on to the latest values
#define MHz (1000000lu)
#define KHz (1000lu)
#define Hz (1)
#define SPEED 1
#define UNITS MHz
#define STRINGIFY1(x) #x
#define SPEED_STR STRINGIFY1(SPEED) STRINGIFY1(UNITS)
#define SPEED_ARG (UINT32_C(SPEED) * UNITS)
//-------------------------- SETUP -----------------------
@ -27,9 +35,8 @@ void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("");
Serial.print(F("Zachtek GPS referenced RF, Software version: "));
Serial.println(softwareversion);
Serial.println(F(""));
Serial.print(F("Zachtek GPS referenced RF, Software version: " softwareversion));
pinMode(LDO_Enable, OUTPUT); // Set Voltage Regulator Enable pin as output.
@ -58,27 +65,56 @@ void setup()
delay(500);//Wait for GPSmodule to complete it's power on.
//Program GPS to output RF
if (setGPS_OutputFreq1MHz()) {
Serial.println ("GPS Initialized to output RF at 1MHz");
Serial.println ("Initialization is complete.");
Serial.println ("");
if (setGPS_OutputFreq(SPEED_ARG)) {
Serial.print (F("GPS Initialized to output RF at "));
Serial.println (F(SPEED_STR "\nInitialization is complete.\n"));
GPSOK = true;
}
else
{
Serial.println ("Error! Could not program GPS!");
Serial.println (F("Error! Could not program GPS!"));
GPSOK = false;
}
}
//--------------------------
void handle_serial() {
static uint8_t state = 0;
static uint32_t acc;
uint8_t ch = Serial.read();
if(ch == 'F') { state = 1; acc = 0; }
if(state == 1 && ch == '\n') {
if(setGPS_OutputFreq(acc)) {
Serial.print (F("GPS Initialized to output RF at "));
Serial.println (acc);
GPSOK = true;
}
else
{
Serial.println (F("Error! Could not program GPS!"));
GPSOK = false;
}
state = 0;
} else if(state) {
if (ch >= '0' && ch <= '9') {
acc = acc * 10 + ch - '0';
} else if (ch == 'M') {
acc *= 1000000lu;
} else if (ch == 'K') {
acc *= 1000lu;
}
}
}
//-------------------------- Main loop -----------------------
void loop()
{
while (Serial.available()) {
handle_serial();
}
while (gps.available( gpsPort )) {
fix = gps.read();
if (fix.valid.location && fix.valid.date && fix.valid.time)
@ -108,81 +144,68 @@ void loop()
//--------------------------
bool setGPS_OutputFreq100kHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x20, 0x1B
};
// For details of the UBX protocol, see
// https://www.u-blox.com/sites/default/files/products/documents/u-blox7-V14_ReceiverDescriptionProtocolSpec_%28GPS.G7-SW-12001%29_Public.pdf
// Documentation of this packet is under the heading CFG-TP5 (35.19.2) in the current documentation.
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x20, 0x1B
};
#define OFFSET_FREQUENCY_LOCKED (12)
#define OFFSET_CKSUM (38)
// Note: Normally payload_start is 2 bytes past the start of buf, because the first two bytes
// are the message type and are not checksummed.
void ubx_compute_checksum(uint8_t *payload_start, uint8_t *payload_end, uint8_t *cksum) {
uint8_t ck_a=0, ck_b=0;
for(const uint8_t *p = payload_start; p != payload_end; p++)
{
ck_a += *p;
ck_b += ck_a;
}
cksum[0] = ck_a;
cksum[1] = ck_b;
}
bool setGPS_OutputFreq(uint32_t freq) {
for(int i=0; i<4; i++) {
setOutputFreq[OFFSET_FREQUENCY_LOCKED+i] = freq & 0xff;
freq <<= 8;
}
ubx_compute_checksum(setOutputFreq+2, setOutputFreq+38, setOutputFreq+38);
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
bool gps_set_sucess = getUBX_ACK(setOutputFreq);
// Serial.println(F("Set output Freq Done"));
return gps_set_sucess;
}
bool setGPS_OutputFreq1Kz()
{
return setGPS_OutputFreq(1*KHz);
}
bool setGPS_OutputFreq1MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x40, 0x42, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x8A, 0x8B
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(1*MHz);
}
bool setGPS_OutputFreq2MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x80, 0x84, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x1B, 0x7F
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(2*MHz);
}
bool setGPS_OutputFreq4MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x09, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0xEF, 0x00, 0x00, 0x00, 0x3F, 0x8C
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(4*MHz);
}
//8MHz is the highest low-jitter frequency possible
bool setGPS_OutputFreq8MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x12, 0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0xD4, 0x28
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(8*MHz);
}
//10 MHz is very jittery. Numbers that can be done with an integer division from 48MHz will produce
@ -190,34 +213,14 @@ bool setGPS_OutputFreq8MHz()
//If 10MHz low jitter is needed then one option is to output 2MHz and then filter out the 5th overtone arriving at 10MHz in that way.
bool setGPS_OutputFreq10MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0xF6, 0x10
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(10*MHz);
}
//16MHz is above the specs for lUblox Neo-6, only included for experiments.
//This will not produce as clean Square wave.
bool setGPS_OutputFreq16MHz()
{
int gps_set_sucess = 0;
uint8_t setOutputFreq[] = {
0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x24, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x60, 0x12
};
sendUBX(setOutputFreq, sizeof(setOutputFreq) / sizeof(uint8_t));
gps_set_sucess = getUBX_ACK(setOutputFreq);
//Serial.println("Set output Freq Done");
return gps_set_sucess;
return setGPS_OutputFreq(16*MHz);
}