Maker Pro
Maker Pro

GPS NMEA, Failover Circuit upgrade attempt.

I have followed your scenario table and managed to simulate all scenarios listed. I forgot to move the buzzer reset after each serin command.. so this is now removed.

Also, if both GPS's have timed out.. GPS2 is selected by default... I'm can't figure out why this is happening, but if they both time out neither GPS will work anyway... so this might not be an issue, unless you want to look into it.

:) Everything else seems to work ok and as expected. Below is the updated code as of 11 Aug:

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

'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.4
#DEFINE GPS2_SERIN B.1
#DEFINE GPS1_BAD_DATA C.1
#DEFINE GPS2_BAD_DATA C.2
#DEFINE GPS1_TIMEOUT_LED B.4
#DEFINE GPS2_TIMEOUT_LED B.3

#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
        Let GPS1_TIMEOUT=0 'Reset Timeout
        LOW GPS1_TIMEOUT_LED 'Turns off gps1 timeout LED indicator at pin b.4
    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
        Let GPS2_TIMEOUT=0 'Reset Timeout
        LOW GPS2_TIMEOUT_LED ' Turns off gps2 timeout LED indicator at pin b.3
    goto GPS2_Scan 'Read bits and quality of signal/data


    TIMEOUT1:
    Let GPS1_TIMEOUT=1
    goto GPS1_Scan
  
      TIMEOUT2:
    Let GPS2_TIMEOUT=1
    goto GPS2_Scan

    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
  
        if GPS1_TIMEOUT=1 then
            HIGH GPS1_TIMEOUT_LED ' turns on gps1 timeout led indicator at pinb.4
            Let GPS1_Error=3
        else
            LOW GPS1_TIMEOUT_LED ' turns off gps1 timeout led indicator at pinb.4
        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
      
        if GPS2_TIMEOUT=1 then
            HIGH GPS2_TIMEOUT_LED ' turns on gps2 timeout led indicator at pinb.4
            Let GPS2_Error=3
        else
            LOW GPS2_TIMEOUT_LED ' turns off gps2 timeout led indicator at pinb.4
        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_BAD_DATA
            HIGH GPS2_BAD_DATA
            endif

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

            if GPS2_Error<3 then 'During this state DOP determines output if GPS1/2 Data ok
            LOW Buzzer
            LOW GPS1_BAD_DATA
            LOW GPS2_BAD_DATA
          
                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, if both GPS's have timed out.. GPS2 is selected by default... I'm can't figure out why this is happening, but if they both time out neither GPS will work anyway...
I have also noticed that but as you already pointed out, This does not matter because there will be no input anyway !!!


I seem to have an other minor problem concerning the circuit.
I use a 9Volt battery to power the circuit and run the tests. While are all connected according to the diagram.
at both GPS timeout situation, Relay is engaged but when i remove the wire from the Relay to +9V then the picaxe will reset. There is an 1N4001 protection diode installed reverse biased (cathode to +9V and anode to Collector of bc337, in parallel with the relay coil)

Why would that happen ?

i will have to test and see if that also happens during normal operation.

Would it be better if i use a 5volt relay and feed it from the regulator output ?
 
I wrote a code that turns on and off the relay through the 1K resistor and the bc337 and it works fine. Indeed it does the same thing when pulling a cable though.

Well it is fine as long as it works good while i dont pull cables :)
 
I wrote a code that turns on and off the relay through the 1K resistor and the bc337 and it works fine. Indeed it does the same thing when pulling a cable though.

Well it is fine as long as it works good while i dont pull cables :)

I'm glad you solved this I was quite perplexed :) are you testing the code soon?
 
I have run the first test today with one gps connected but it didn't work.
Picaxe is responding as if all inputs are timeout no matter if i have the gps connected or not.

Strange thing is that the GPS is giveing me different picture on the Oscope. It is indeed idle high and pulses go low about 15-17 Volt p-p.

I will try inserting the diode as mentioned in the manual for pin c.3 but i doubt it will make any difference.

The fact is that i use the gps in "bad data state" where it can not get sattelite signal but still should it not be enough for the picaxe not to enter timeout state ?

Picaxe should have sensed the data ti serial in port c.4 and not go to timeout.
 
Last edited:
I wonder if there is a way to use the computers serial port and run the simulation like that instead of feeding sentences through the serial window.
 
The fact is that i use the gps in "bad data state" where it can not get sattelite signal but still should it not be enough for the picaxe not to enter timeout state ?

Picaxe should have sensed the data ti serial in port c.4 and not go to timeout.

Same thing with pin b.1
 
I'm not sure why this is happening Constantine, will have to read more into it. :(

It should at least read the sentence and not go into a timeout..


Try removing the timeout qualifier in the serin command see if that works.
 
Last edited:
I will.

in the meanwhile i noticed that if i power up the picaxe with the gps1 connected then the chip does nothing. no leds go high. nothing. When i disconnect it then it starts working and goes to timeout.
While when i power it up with gps2 connected it just lits GPS1 timeout led and nothing else and again goes to timeout when disconnecting it.
 
Bad thing is that with this version of software connect to real life picaxe button does not work. says it is disabled in beta version.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
Have you downloaded the latest PE-6 version? The current version is no longer Beta. I'm running V 6.0.8.8

Chris
 
I have the 6.0.8.10 and still gives me the message "this feature is currently disabled in this beta version"

Wait... on the top it says logicator for picaxe 6.0.8.10
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
My version does not say Beta.

BTW, while reading through some of the code posted I noticed that the comments on the Pause 1 lines states "Pause for 1uS". That's actually a 1 millisecond (1mS) pause.

Code:
 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
            Let GPS1_TIMEOUT=0 'Reset Timeout
            LOW GPS1_TIMEOUT_LED 'Turns off gps1 timeout LED indicator at pin b.4
        goto GPS1_Scan 'Read bits and quality of signal/data

Chris
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
can you use the "connect to real life picaxe" button ? what message it gives you ?
I can't answer that right now but according to the official Picaxe forum it's enabled.

I do have a question though. I notice that your last schematic does not show any connection to C.5 program download pin. Does it? This pin should always have the 10K, 22K resistor configuration connected to it. If it's left hanging the chip will think that a new program is about to be downloaded.

Chris
 
Here are Oscope images of the gps output and the picaxe input pin c.4 with the 1n4148 diode installed (though stated by it's manual that it is only needed for pin c.3
 

Attachments

  • GPS OUTPUT.PNG
    GPS OUTPUT.PNG
    8.5 KB · Views: 64
  • PICAXE SERIAL INPUT PIN.PNG
    PICAXE SERIAL INPUT PIN.PNG
    8.5 KB · Views: 76
Hmmm thinking about the problem i came with the idea to transmit data from the picaxe to the pc instead of receiving from the GPS. so i wrote this

main:
SERout C.4, N4800_4, ("$GPGSA")
wait 1
SERout C.4, N4800_4, ("Hello")
goto main

and it actually works. at hyperterminal i get $GPGSAHello.

So that makes me think that the picaxe chip is not damaged.

We must be missing something here.....
 
Top