Continuation from cog31s GPS issue.


Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6543
Posted: 12:01am 08 Oct 2019      

Don't know what happend to my first post and not able to edit it.

  goc30 said  Hi geoffg

I have a small problem
I use an gps chip and I write prog to use this gps on mx170 (or mx470) with v5.05.2
my problem is that some cases, prog spend time is too long (where??)
normal main prog is executed in 150 to 200ms, but some times it is executed in 600ms
see capture screen
Run
19:44:58 ->   0.120
19:44:59 ->   0.172
19:45:00 ->   0.172
19:45:01 ->   0.172
19:45:02 ->   0.616
19:45:03 ->   0.616
19:45:04 ->   0.616
19:45:05 ->   0.616
19:45:06 ->   0.616
19:45:07 ->   0.571
19:45:08 ->   0.173
19:45:09 ->   0.173
19:45:10 ->   0.173
19:45:11 ->   0.174
19:45:12 ->   0.173
19:45:13 ->   0.173
19:45:14 ->   0.173
19:45:15 ->   0.650
19:45:16 ->   0.173
19:45:17 ->   0.582
19:45:18 ->   0.173
19:45:19 ->   0.173
19:45:20 ->   0.605
19:45:21 ->   0.649
19:45:22 ->   0.173
>


do you know what??

my prog
rec_gps_ref.zip


Most of the time your tfrgps sub runs without being interrupted by the serial routine.
When it DOES coincide, you notice the longer times.

I added a global counter to record the number of calls to the spcomrec4 sub during the tfrgps sub and added the count to the printout.

  Quote  > RUN
10:43:52 ->   0.084 0
10:43:54 ->   0.078 0
10:43:55 ->   0.085 0
10:43:56 ->   0.089 0
10:43:57 ->   0.087 0
10:43:58 ->   0.288 133
10:43:59 ->   0.117 0
10:44:00 ->   0.286 133
10:44:01 ->   0.088 0
10:44:02 ->   0.087 0
10:44:03 ->   0.087 0
10:44:04 ->   0.118 0
10:44:05 ->   0.085 0
10:44:06 ->   0.206 133
10:44:06 ->   0.088 0
10:44:07 ->   0.087 0
10:44:08 ->   0.087 0
10:44:09 ->   0.078 0
10:44:10 ->   0.085 0
10:44:11 ->   0.088 0
10:44:12 ->   0.208 133
10:44:12 ->   0.087 0
10:44:13 ->   0.087 0
10:44:14 ->   0.117 0
10:44:15 ->   0.085 0
10:44:16 ->   0.088 0
10:44:17 ->   0.087 0
10:44:18 ->   0.087 0
10:44:19 ->   0.078 0
10:44:20 ->   0.085 0
10:44:21 ->   0.088 0
10:44:22 ->   0.087 0
10:44:23 ->   0.087 0
10:44:24 ->   0.078 0
10:44:25 ->   0.085 0
10:44:26 ->   0.088 0
10:44:27 ->   0.288 136
10:44:28 ->   0.202 137
10:44:28 ->   0.087 0
10:44:29 ->   0.501 303
10:44:29 ->   0.078 0
10:44:30 ->   0.085 0
10:44:31 ->   0.202 134
10:44:31 ->   0.088 0
10:44:32 ->   0.087 0
10:44:33 ->   0.087 0
>


This was run on an explore64 and a real GPS.

It is likely that my GPS is configured differently to yours so I would expect some variation but it does suggest that the timing differences you see are caused by the program flow, not an underlining problem with MMBasic.


Modified program:

 OPTION EXPLICIT
 OPTION AUTORUN ON
 
 CONST top1s=31   '16
 CONST cnbcde = 3
 CONST cnbch = 18
 CONST cnbbuf = 10
 CONST ccptvdg = 5  'comptage nb sec sans reception com
 
 CONST maxto = 500  'ex ime out 5 sec
 
 DIM i AS INTEGER
 DIM i1 AS INTEGER
 DIM i2 AS INTEGER
 DIM intCall AS INTEGER
 
 DIM tmcde(cnbcde) AS STRING LENGTH 3
 DIM nbcde AS INTEGER
 
 DIM tmgps(cnbcde,cnbch) AS STRING LENGTH 20
 DIM nbgps(cnbcde) AS INTEGER
 DIM ptcde AS INTEGER
 DIM ptgps AS INTEGER
 DIM flggps(cnbbuf) AS INTEGER
 
 DIM txcrc AS STRING
 DIM nbcar AS INTEGER
 
 DIM cptm3 AS INTEGER
 DIM cptvdg AS INTEGER
 DIM ptime1 AS FLOAT
 DIM ptime2 AS FLOAT
 DIM validgps AS INTEGER
 
 DIM tmbuf(cnbbuf) AS STRING
 DIM flgtmbuf(cnbbuf) AS INTEGER
 DIM ptWrite AS INTEGER
 DIM ptRead AS INTEGER
 DIM txbufgps AS STRING
 DIM txchamp AS STRING
 DIM flgf AS INTEGER
 
 
 i=0
 i=i+1:tmcde(i)="GGA"
 i=i+1:tmcde(i)="GSA"
 i=i+1:tmcde(i)="RMC"
 nbcde=i
 txbufgps=""
 flgf=0
 
 OPEN "COM1:9600,255,spcomrec4" AS #2
 ptWrite=0
 ptRead=0
 FOR i=1 TO cnbbuf
   tmbuf(i)=""
   flgtmbuf(i)=0
 NEXT i
 '*****************************
 DO
   ptime1=TIMER
   intCall = 0
   tfrgps
   ptime2=TIMER
   IF ptime2-ptime1>50 THEN
     PRINT TIME$;" ->";STR$((ptime2-ptime1)/1000,4,3);" ";STR$(intCall)
   END IF
   PAUSE(10)
 LOOP
 '*****************************
 
 
SUB tfrgps()  'store in database
 LOCAL txt AS STRING
 LOCAL flgg AS INTEGER
 FOR i=1 TO cnbbuf
   ptRead=ptRead+1
   IF ptRead>cnbbuf THEN ptRead=1
   IF flgtmbuf(ptRead)=0 THEN EXIT FOR
   IF flgtmbuf(ptRead)=2 THEN
     txt=tmbuf(ptRead)
     spgps(txt,flgg)
     IF flgg>0 THEN
       flgtmbuf(ptRead)=0
       calccrc2(txt)
       IF (validgps AND 16)=16 THEN
         rangegps(txt,flgg)
       END IF
     END IF
   END IF
 NEXT i
END SUB
 
SUB calccrc2(txc AS STRING)
 LOCAL jc AS INTEGER
 LOCAL ic AS INTEGER
 LOCAL i3 AS INTEGER
 jc=INSTR(txc,"*")
 IF jc>2 THEN
   ic=0
   FOR i3=2 TO jc-1
     ic=ic XOR ASC(MID$(txc,i3,1))
   NEXT i3
   'print
 END IF
 txcrc=HEX$(ic)
 IF LEN(txcrc)=1 THEN txcrc="0"+txcrc
 IF txcrc=RIGHT$(txc,2) THEN
   validgps=(validgps OR 16)
 ELSE
   validgps=(validgps AND &hEF )
   PRINT txc
   PRINT txcrc;"<>";RIGHT$(txc,2)
 END IF
END SUB
 
SUB spgps(txg AS STRING, ergp AS INTEGER)
 LOCAL i AS INTEGER
 ergp=0
 FOR i=1 TO nbcde
   IF MID$(txg,4,3)=tmcde(i) THEN  'for gps($gp) or glosnass($gn) frames
     ergp=i
     EXIT FOR
   END IF
 NEXT i
END SUB
 
SUB rangegps(txcrc AS STRING, flge AS INTEGER)
 LOCAL b$ AS STRING LENGTH 1
 IF LEFT$(txcrc,1)="$" THEN
   ptgps=0
   ptcde=flge
   txchamp=""
   FOR i2=1 TO LEN(txcrc)
     b$=MID$(txcrc,i2,1)
     IF b$="," THEN
       ptgps=ptgps+1
       tmgps(ptcde,ptgps)=txchamp
       txchamp=""
     ELSE
       IF ASC(b$)>31 THEN txchamp=txchamp+b$
     END IF
   NEXT i2
   ptgps=ptgps+1
   IF ptgps<=cnbch THEN
     tmgps(ptcde,ptgps)=txchamp
   END IF
   flggps(ptcde)=2
   nbgps(ptcde)=ptgps
 END IF
END SUB
 
 
SUB spcomrec4
 LOCAL tx$ AS STRING 'length 3
 LOCAL i1 AS INTEGER
 LOCAL i2 AS INTEGER
 LOCAL a$ AS STRING LENGTH 1
 LOCAL vai AS INTEGER
 intCall = intCall + 1
 i1=LOC(#2)
 IF i1=0 THEN
   EXIT SUB
 ELSE
   tx$=INPUT$(i1,#2)
   FOR i2=1 TO i1
     a$=MID$(tx$,i2,1)
     vai=ASC(a$)
     IF a$="$" THEN
       ptWrite=ptWrite+1
       IF ptWrite>cnbbuf THEN ptWrite=1
       tmbuf(ptWrite)=""
       flgtmbuf(ptWrite)=1
     END IF
     IF vai=10 THEN
       flgtmbuf(ptWrite)=2
     ELSE
       IF vai>31 THEN tmbuf(ptWrite)=tmbuf(ptWrite)+a$
     END IF
   NEXT i2
 ENDIF
 
END SUB
 

VK7JH
MMedit