Maker Pro
Maker Pro

GPS NMEA, Failover Circuit upgrade attempt.

Answer found on picaxe manual.

All 8 and 14 pin chips

Due to the internal structure of input3 (C.3) on these chips, a 1N4148 diode is required between the pin and V+ for serin to work on this particular pin ('bar' end of diode to V+) with this circuit. All other pins have an internal diode.


So the diode on pin B.0 is not needed due to the existance of an internal diode.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
Roger that Constantine. It's my error. The diode is needed and its polarity is correct.

Chris
 
Roger that Constantine. It's my error. The diode is needed and its polarity is correct.
:)

Ok that is what i first thought but in my previous post i have stated that according to the picaxe manual only pin c.3 needs an external diode. All other pins are protected via internal diodes.
So in my case at pin b.0 you where correct about the diode was not needed.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
This is a long thread so it's possible that I may have missed something, though I did go back and read from page 1 on. I must admit that I'm a bit confused. I believe I read that you're using the "hserin" command on C5 and B0 but as far as I can ascertain B1 is only pin available for that command on the 14M2.

Chris
 
I believe I read that you're using the "hserin" command on C5 and B0 but as far as I can ascertain B1 is only pin available for that command on the 14M2.

The picaxe manual states the following:
The serin command is used to receive serial data into an input pin of the microcontroller. It cannot be used with the serial download input pin, which requires use of the serrxd command instead.

The previous diagrams where incorrectly designed by ny nistake. After reading the code i noticed that GPS2 is connected to pin B.1 not (B.0).

So there are two issues here:

1) Pic C.5 is the serial download pin. In the simulation it works but..... Can it really be used ?

2) The serin command is used to receive data into an INPUT pin of the microcontroller.
"C" pins are the input pins of picaxe 14m2 so can B.1 be used ?
Though all pins can be set as input or output pins....

I am not sure...

I will wait to make that clear before i correct the diagram.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
I thought that I read (within this topic) that "hserin" is the command being used. Am I wrong?

Chris
 
Sir CDRIVE,

hmmm, hserin is a marking of pin B.1 but i do not know what that stands for !
 

Attachments

  • PICAXE 14m2.jpg
    PICAXE 14m2.jpg
    79.3 KB · Views: 67

CDRIVE

Hauling 10' pipe on a Trek Shift3
Never mind it was brain fart. You asked Sadler about the "hserin" command and he replied with an explanation of it. Somehow hserin got embedded in my old brain but it has no relevance your project. I opened one of Sadler's text files that contained code he wrote for you. He's using the "serin" command not "hserin".

Fact is, Sadler was doing a great job walking you through this. Personally, I wish I hadn't stepped on his toes. :(

Chris
 
1) Pic C.5 is the serial download pin. In the simulation it works but..... Can it really be used ?
that question still remains...

Never mind it was brain fart
Dont worry i have theese all the time !

Fact is, Sadler was doing a great job walking you through this.
As a matter of fact he does. I really have no words to thank him enough.
Thank you also for your try to help.
 
Ok there is an other issue concerning the program code. The way it is works fine as long as the picaxe is getting serial input from both GPS's.

What if one or all of them are not phisically connected to the picaxe ? Then it will indefinitly wait until it gets inout and that is something we do not want.

We want the picaxe in case of a disconnected cable to be able to raise the buzzer (just like when both gps give bad data) and be able to continiue running the code untill one or all GPS are restored.

I have used the Timeout feature like Ash suggested (in p.m.) and came up with this the following code which i am not sure if it is correct.

What i did is after GPS1_READ tag i have instructed it to wait 2000ms and if it does not get $GSA then to proceed to GPS2_READ and do the same and if it does not get $GSA from GPS2 at the same time to execute tag Timeout_alarm which turns on the buzzer and then goes back to Main.

So if both GPS are not connected the buzzer should keep being high. At the end of GPS1_read and GPS2_read i have added a low buzzer command that will silence the buzzer in case GPS comms have been restored and the code should continiue being executed normally.
 

Attachments

  • (attempt) GPS CODE WITH TIMEOUT.txt
    5 KB · Views: 95
That's great Constantine, I think there is a slight issue though. The way its setup, if the GPS1 is read ok and GPS2 timeouts... the buzzer goes high.

I've modified this slightly and created a timeout variable for each GPS, if both variables = 1 then both GPS's have timed out and the buzzer goes high.

Code:
#picaxe 14m2 'Identify the PICAXE being used as an 14M2.

let b11 = 0        '
let b12 = 0
let b13 = 0
let b14 = 0
let b15 = 0
let b16 = 0
let b17 = 0
let b18 = 0

#DEFINE GPS1_Data b11
#DEFINE GPS1_Signal b12
#DEFINE GPS2_Data b13
#DEFINE GPS2_Signal b14

#DEFINE GPS1_Error     b15
#DEFINE GPS2_Error     b16
#DEFINE GPS1_DOP         w9
#DEFINE GPS2_DOP         w10

#DEFINE Buzzer         C.0
#DEFINE Relay         B.5
#DEFINE GPS1_SERIN     C.5
#DEFINE GPS2_SERIN     B.1
#DEFINE GPS1_FAULT    C.1
#DEFINE GPS2_FAULT    C.2

#DEFINE GPS1_TIMEOUT    b17
#DEFINE GPS2_TIMEOUT    b18

main: 'Start 'main' program.

    GPS1_Read:                    'Read GPSA Sentence from GPS1
        SERIN[2000,TIMEOUT1], GPS1_SERIN, N4800_4, ("$GPGSA"),b0,b0,b0,b1,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b2,b3,b4,b5
        pause 1                '1us Delay
        w9=b2-48*10+b4-48*10+b5-48    'Convert ASCII to Binary
        pause 1                '1us Delay
        GPS1_TIMEOUT=0            'Reset Timeout
        LOW BUZZER                'Reset BUZZER
    goto GPS1_Scan                'Read bits and quality of signal/data

    GPS2_Read:                    'Read GPSA Sentence from GPS1
        SERIN[2000,TIMEOUT2], GPS2_SERIN, N4800_4, ("$GPGSA"),b0,b0,b0,b6,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b7,b8,b9,b10
        pause 1                '1us Delay
        w10=b7-48*10+b9-48*10+b10-48    'Convert ASCII to Binary
        pause 1                '1us Delay
        GPS2_TIMEOUT=0            'Reset Timeout
        LOW BUZZER                'Reset BUZZER
    goto GPS2_Scan                'Read bits and quality of signal/data
  
    'TIMEOUT FUNCTION
    TIMEOUT1:
    Let GPS1_TIMEOUT=1
    goto GPS2_Read
  
    TIMEOUT2:
    Let GPS2_TIMEOUT=1
        if GPS1_TIMEOUT=1 AND GPS2_TIMEOUT=1 then
        HIGH BUZZER                'HIGH BUZZER if both serin commands timeout
        endif
    goto main
 
So instead of useing a tag you use a variable. A different variable for each GPS input.
I had no idea that was possible.

Picaxe manual had no example of how to use timeout and that gave me a really hard time to understand.

Ok. the way you wrote the code now the puicaxe will have to get the a complete GSA sentence or it will timeout. is that correct ?
 
I have combined the code you wrote with the timeout with the rest of the code (from GPS1_READ and below) and when gps1 has lower DOP or when gps2 is timeout then relay will not go high....

have i done something wrong ?
 
Is it just me or when GPS1 is normal and GPS2 is timeout then the picaxe will not go to Active_GPS tag ?

And the relay will remain low. right ?

In that case if Low relay is connecting GPS1 to the output we are good. I think.

if gps1 is timeout and GPS2 active then it will go to Active_GPS tag then the relay will go high and we are again good.

what do you think ?

We must not forget to change this:

Active_DOP:
if GPS2_DOP < GPS1_DOP then 'If GPS2_DOP has lower DOP
HIGH Relay 'Set GPS2 as output
endif
if GPS1_DOP < GPS2_DOP then 'If GPS1_DOP has lower DOP
LOW Relay 'Set GPS1 as output
endif
pause 5000
goto main 'Go to 'main' program.
 
So instead of useing a tag you use a variable. A different variable for each GPS input.
I had no idea that was possible.

Picaxe manual had no example of how to use timeout and that gave me a really hard time to understand.

Ok. the way you wrote the code now the puicaxe will have to get the a complete GSA sentence or it will timeout. is that correct ?

If a GPS times out it goes to the TIMEOUT1 or TIMEOUT 2 section and the variable becomes a 1. If both variables are 1 then the buzzer goes high.

A timeout will only occur if the picaxe does not recieve a GPGSA NMEA Sentence... this is regardless of whether the data is complete. So even if the picaxe receives a GPGSA opening and just a bunch of commas.. it will not timeout

Is it just me or when GPS1 is normal and GPS2 is timeout then the picaxe will not go to Active_GPS tag ?

And the relay will remain low. right ?

In that case if Low relay is connecting GPS1 to the output we are good. I think.

if gps1 is timeout and GPS2 active then it will go to Active_GPS tag then the relay will go high and we are again good.

what do you think ?

We must not forget to change this:

Active_DOP:
if GPS2_DOP < GPS1_DOP then 'If GPS2_DOP has lower DOP
HIGH Relay 'Set GPS2 as output
endif
if GPS1_DOP < GPS2_DOP then 'If GPS1_DOP has lower DOP
LOW Relay 'Set GPS1 as output
endif
pause 5000
goto main 'Go to 'main' program.

Let me check this..
 
I have combined the code you wrote with the timeout with the rest of the code (from GPS1_READ and below) and when gps1 has lower DOP or when gps2 is timeout then relay will not go high....

have i done something wrong ?

I found an error in the program, because I created two new variables one of them kept overwriting w9.

I've now moved w9 to w10 and w10 is now w11.


For clarity here is the complete current code.
 

Attachments

  • GPS2.txt
    4.9 KB · Views: 110
Is it just me or when GPS1 is normal and GPS2 is timeout then the picaxe will not go to Active_GPS tag ?

And the relay will remain low. right ?

In that case if Low relay is connecting GPS1 to the output we are good. I think.

if gps1 is timeout and GPS2 active then it will go to Active_GPS tag then the relay will go high and we are again good.

what do you think ?

We must not forget to change this:

Active_DOP:
if GPS2_DOP < GPS1_DOP then 'If GPS2_DOP has lower DOP
HIGH Relay 'Set GPS2 as output
endif
if GPS1_DOP < GPS2_DOP then 'If GPS1_DOP has lower DOP
LOW Relay 'Set GPS1 as output
endif
pause 5000
goto main 'Go to 'main' program.

Your right it will not go to Active GPS.. At the end each TIMEOUT1 and TIMEOUT2 loop I think we need change goto too GPS1_Scan and GPS2_Scan respectively.
 

Attachments

  • GPS2.txt
    4.9 KB · Views: 105
Ok. i have a few questions here but before i state them i should say that if relay is High and then GPS1 has good data and GPS2 is timeout then the relay stays high (still gps2 connected) while we should make it go low since only GPS1 is active and good.

Also i noticed that when both GPS1 and GPS2 are timeout the buzzer goes high and when it goes to Active_GPS tag buzzer goes low.

hmmm... Why after timeout1 you goto GPS1_scan ? what will be there to scan if gps1 is timeout ? The same for timeout2.

I was thinking that we may be able to avoid the above if we change the following.

'TIMEOUT FUNCTION
TIMEOUT1:
Let GPS1_TIMEOUT=1
goto GPS2_read

TIMEOUT2:
Let GPS2_TIMEOUT=1
if GPS1_TIMEOUT=1 AND GPS2_TIMEOUT=1 then
HIGH BUZZER 'HIGH BUZZER if both serin commands timeout
endif
if GPS1_TIMEOUT=0 AND GPS2_TIMEOUT=1 then
LOW Relay
endif


goto main

this way if GPS1 is ok and GPS2 is timeout then relay goes High (GPS1 is connected)
if GPS2 is ok and GPS1 is timeout then when gps2 scan occures we instruct it to check if PGS1_timeout = 1 and then to set relay High.



My way of thinking for the above is the following.

If Gps1 is timeout then we have to check Gps2 status so that if 1 is timeout then 2 has to be set as output and we dont care about the DOP value as we are in "single input mode"
The same goes if Gps1 is good and Gps2 is timeout then Gps1 has to be set as output and we again dont care about it's DOP value as we again are in "single input mode"

then we goto main to check things all over again and in case all gps are NOT timeout then the program will continiue normally and go through GPS1_read - GPS1_scan - GPS2_read - GPS2_scan and then Active GPS (as far as good qualiti data is concerned) and last Active_DOP to decide the relay status.
 
Last edited:
Here is the whole code as i have altered it according to my prev. post.

#picaxe 14m2 'Identify the PICAXE being used as an 14M2.

let b11 = 0 '
let b12 = 0
let b13 = 0
let b14 = 0
let b15 = 0
let b16 = 0
let b17 = 0
let b18 = 0

'The variables below have been assigned to labels, so now.. instead of writing b11 i can write GPS1_Data and the program automatically subsitutees b11 where the text GPS1_Data is written.
'This helps making the program readable and simple when lots of variables is used.

#DEFINE GPS1_Data b11
#DEFINE GPS1_Signal b12
#DEFINE GPS2_Data b13
#DEFINE GPS2_Signal b14


#DEFINE GPS1_Error b15
#DEFINE GPS2_Error b16
#DEFINE GPS1_DOP w10
#DEFINE GPS2_DOP w11

#DEFINE Buzzer C.0
#DEFINE Relay B.5
#DEFINE GPS1_SERIN C.5
#DEFINE GPS2_SERIN B.1
#DEFINE GPS1_FAULT C.1
#DEFINE GPS2_FAULT C.2

#DEFINE GPS1_TIMEOUT b17
#DEFINE GPS2_TIMEOUT b18

main: 'Start 'main' program.

GPS1_Read: 'Read GPSA Sentence from GPS1
SERIN[2000,TIMEOUT1], GPS1_SERIN, N4800_4, ("$GPGSA"),b0,b0,b0,b1,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b2,b3,b4,b5
pause 1 '1us Delay
w10=b2-48*10+b4-48*10+b5-48 'Convert ASCII to Binary
pause 1 '1us Delay
GPS1_TIMEOUT=0 'Reset Timeout
LOW BUZZER 'Reset BUZZER
goto GPS1_Scan 'Read bits and quality of signal/data

GPS2_Read: 'Read GPSA Sentence from GPS1
SERIN[2000,TIMEOUT2], GPS2_SERIN, N4800_4, ("$GPGSA"),b0,b0,b0,b6,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b7,b8,b9,b10
pause 1 '1us Delay
w11=b7-48*10+b9-48*10+b10-48 'Convert ASCII to Binary
pause 1 '1us Delay
GPS2_TIMEOUT=0 'Reset Timeout
LOW BUZZER 'Reset BUZZER
goto GPS2_Scan 'Read bits and quality of signal/data

'TIMEOUT FUNCTION
TIMEOUT1:
Let GPS1_TIMEOUT=1
goto GPS2_Read

TIMEOUT2:
Let GPS2_TIMEOUT=1
if GPS1_TIMEOUT=1 AND GPS2_TIMEOUT=1 then
HIGH BUZZER 'HIGH BUZZER if both serin commands timeout
endif
if GPS1_TIMEOUT=0 AND GPS2_TIMEOUT=1 then
LOW Relay
endif
goto main



GPS1_Scan:
if b1=49 then
Let GPS1_Signal=0 'if b1=1 then the GPS has no signal
endif

if b1=50 then
Let GPS1_Data=0 'if b1=2 then data might be missing or corrupt
Let GPS1_Signal=0
endif

if b1=51 then
Let GPS1_Signal=1 'if b1=3 we have signal and complete data
Let GPS1_Data=1 'if b0=44 there is a comma before DOP and thus complete data
endif

if b0!=44 then
Let GPS1_Data=0 'if b0 is not a comma (,) then data might be missing or corrupt
endif

'Error variable is held between 0 and 3. If more than 3 sentences are bad
'the value becomes 3 and the GPS is considered inactive. (Filters anomalies)
if GPS1_Signal=0 then
if GPS1_Error<3 then
inc GPS1_Error
endif
endif

if GPS1_Signal=1 then
if GPS1_Error>0 then
dec GPS1_Error
endif
endif
goto GPS2_Read 'Read GPSA Sentence from GPS2



GPS2_Scan:
if GPS1_TIMEOUT=1 then
High relay
endif
if b6=49 then
let GPS2_Signal = 0 'if b6=1 then the GPS has no signal
endif

if b6=50 then
Let GPS2_Data=0 'if b6=2 then data might be missing or corrupt
Let GPS2_Signal=0
endif

if b6=51 then
Let GPS2_Signal=1 'if b6=3 we have signal and complete data
Let GPS2_Data=1
endif

if b0!=44 then
Let GPS1_Data=0 'if b0 is not a comma (,) then data might be missing or corrupt
endif

'Error variable is held between 0 and 3. If more than 3 sentences are bad
'the value becomes 3 and the GPS is considered inactive. (Filters anomalies)
if GPS2_Signal=0 then
if GPS2_Error<3 then
inc GPS2_Error
endif
endif

if GPS2_Signal=1 then
if GPS2_Error>0 then
dec GPS2_Error
endif
endif
goto Active_GPS

Active_GPS:
if GPS1_Error =3 then
if GPS2_Error=3 then
HIGH Buzzer 'No active GPS, sound alarm
HIGH GPS1_FAULT
HIGH GPS2_FAULT
endif

if GPS2_Error<3 then
LOW Buzzer
HIGH Relay 'Set GPS2 as output
HIGH GPS1_FAULT
LOW GPS2_FAULT
endif
else
if GPS2_Error=3 then
LOW Buzzer
LOW Relay 'Set GPS1 as output
LOW GPS1_FAULT
HIGH GPS2_FAULT
endif

if GPS2_Error<3 then 'During this state DOP determines output if GPS1/2 Data ok
LOW Buzzer
LOW GPS1_FAULT
LOW GPS2_FAULT
if GPS1_Data=1 AND GPS2_Data=1 then 'Only compare DOP if both GPS data is complete with no errors
goto Active_DOP
endif
endif
endif
goto main

Active_DOP:
if GPS2_DOP < GPS1_DOP then 'If GPS2_DOP has lower DOP
HIGH Relay 'Set GPS2 as output
endif
if GPS1_DOP < GPS2_DOP then 'If GPS1_DOP has lower DOP
LOW Relay 'Set GPS1 as output
endif
pause 5000
goto main 'Go to 'main' program.
 
Also i dont understand how Active_GPS tag works...

isnt it suppesed to chech the "bold" number in the sentence ?

$GPGSA,A,3,02,24,25,32,,,,,,,,,2.79,1.62,2.27*0E,3.01,1.99,2.25*015*00

where 1 = nofix (bad data)
2 = 3dfix (bad or missing data)
3 = 3dfix (and complete data)

i have simulated with 1 and 2 and doesnt look to affect the output of the faut leds.

What am i missing here ?
 
Top