Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,832
Hi,
It works OK for me, I wonder if Vlad has changed the compiler, I still use the old version.
E
Hi E,
Which PIC is this for?

I used your program #621, it works ok.
I added [ Goto read0 ] before 'END', and it works once, then prints 2x BYTES each time, is this a problem?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,832
hi C,
You may recall we used 18F4520 way back, its that PIC.

If you want to loop, you MUST clear the inpmsg ie: inpmsg=""

E
Hi E,
Your test program is working (SIM) on my main computer with [ achr as STRING ] and on the laptop BYTE, perhaps not updated.
Now let's see if I can transpose into the MAIN program again.
Thanks,
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,832
Hi E,
It's gone a bit complicated!
If you recal, the program READs a GPS also, which has a long $STRING and is placed into STR1 by an INTERRUPT.
Testing your CODE in the MAIN program, jumps to the INTERRUPT after END.
I'll have to try to copy this method, if I can. I'm trying to remember triggers the INTERRUPT.
C
 

ericgibbs

Joined Jan 29, 2010
21,451
hi C,
This is a clip from an earlier GPS program, it uses the UART Receive Intr, gets the GPS message string and sets a msgflg, which the Main program detects.
Is this what you are asking.?
E


INTCON.PEIE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0


On High Interrupt
Save System

PIR1.RCIF = 0

Hserin Chr
If Chr = "$" Then 'start
rxi = 0
Endif

str1(rxi) = Chr
Hserout str1(rxi) 'show for testing only
bcd1(rxi) = Chr And 0x0f 'load BCD array
rxi = rxi + 1

If Chr = "?" Then 'temp LF, get ALL msg before processing
Hserout CrLf, CrLf
msgflg = 1
Endif

Resume
 

Thread Starter

camerart

Joined Feb 25, 2013
3,832
hi C,
This is a clip from an earlier GPS program, it uses the UART Receive Intr, gets the GPS message string and sets a msgflg, which the Main program detects.
Is this what you are asking.?
E


INTCON.PEIE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0


On High Interrupt
Save System

PIR1.RCIF = 0

Hserin Chr
If Chr = "$" Then 'start
rxi = 0
Endif

str1(rxi) = Chr
Hserout str1(rxi) 'show for testing only
bcd1(rxi) = Chr And 0x0f 'load BCD array
rxi = rxi + 1

If Chr = "?" Then 'temp LF, get ALL msg before processing
Hserout CrLf, CrLf
msgflg = 1
Endif

Resume
Hi E,
Yes, this is what I'm asking. It's coming back to me.

I think I have a tuned up version, either by you or 'J':
-----------------------------------------------------------------------------------
On High Interrupt 'On Interrupt#####i1.rcif =0
Save System

If RCSTA.OERR = True Then 'any error reboot serial module..
RCSTA.CREN = 0
RCSTA.CREN = 1
valid = 0
rxin = 0
Goto jump
Endif

If str_done = 1 Then
char = RCREG 'temp = RCREG 'Simply dump the character'CCCCCCCCCCCCCCCCCCCCC
Goto jump 'Completed string has not been processed yet by MAIN program
Endif


char = RCREG 'temp = RCREG'CCCCCCC
'Now check for valid string to save. Must contain $ (GNRMC) at first, then read rest until EOL
Select Case rxin
Case 0 'Must be $ sign
If char = "$" Then
str1(rxin) = char
valid = 1
Else
valid = 0
rxin = 0
Endif
Case Else


If valid = 1 Then str1(rxin) = char 'buffer(rxin) = temp 'get character(reading clears the RCIF)CCCCCCCC

EndSelect

If str1(rxin) = "?" Or str1(rxin) = 0x0a Then 'If buffer(rxin) = "?" Then
valid = rxin 'set length of valid string
str_done = 1 'Flag we have a completed string. Main program to check for this and process
Goto msg_eol 'Jump out of the INTERRUPT ROUTINE
Else
If valid = 1 Then rxin = rxin + 1
If rxin = 80 Then
rxin = 0 '80 position circular buffer. If overflow, start from scratch
valid = 0
Endif
Endif
jump:

Resume
==============================================================

''''''PASTE: $GPNMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,W*6A?
'''OR PASTE: $REMOTE,1100,1200,1300,1400,1500W,?

Hserout CrLf

msg_eol:
INTCON.GIE = 0 '?????
strtp = ""
strpr = ""
strtx1 = ""
strtx2 = ""
strtx3 = ""
strtx4 = ""
strtx5 = ""
strtim = ""
strlat = ""
strlong = ""
msg1 = ""

'For g = 0 To rxin 'rxiCCC
'Hserout str1(g)
'Next g
Hserout CrLf, CrLf
csv = 0
For txi = 1 To rxin 'rxiCCCCCCC
char = str1(txi)
strchr = Chr(char)
If strchr <> "," Then
msg1 = msg1 + strchr
Else
csv = csv + 1
If str1(1) = "R" Then Gosub get_valr 'REMOTE
If str1(5) = "C" Then Gosub get_valg 'GPS
Endif
Next txi
========================================================
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,832
Hi E,
I think I'm on the right track today?
I removed the CODE we recently added from outside the INTERRUPT and had a go at adding the QEIDEG from the 4431 into it. HERE:

There is an issue with the 4431 QEI, but I got it to output numbers. (I left the correction till later)

The 4620 works with the SIM.

If anyone can check for obvious errors, while I keep checking please.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,832
Hi,
I don't understand 'CASE'
Here is a section from the 18LF4620 program:
----------------------------------------------------------
get_valq: '$QEIDEG,123,?
Select Case csv 'COMMA POSITION VALUES
Case 2
QEIDEG = leftStr(msg1, 3)
Case Else
EndSelect
msg1 = ""
Return
----------------------------------------------------------
The 18F4431 PIC sends the number of degrees, from the QEI/incremental encoder 0-359. Marked in RED 'above' via the TX and RX on the 18LF4620.

So far, I've got the program to READ the DEG, but then it switches to the end '?'
C
 

ericgibbs

Joined Jan 29, 2010
21,451
hi,
If you recall the original GPS message has comma ',' separated parameters [csv] in the message, we count the occurrence of the comma's, so that we can find the parameters we want from the message.
E
So when we use Case, we are testing for the comma count value.

Your clip:
get_valq: '$QEIDEG,123,?

Select Case csv 'test for the comma count value
Case 2 ' IF its comma count 2 then do this bit of Code, else try 3 and so on
QEIDEG = leftStr(msg1, 3) ' It is 2 so QEIDEG = are the characters in the 'msg' starting at character 1 , for 3 characters
Case Else ' if no comma counts are found then quit the Case test

EndSelect
msg1 = ""
Return
 

Thread Starter

camerart

Joined Feb 25, 2013
3,832
hi,
If you recall the original GPS message has comma ',' separated parameters [csv] in the message, we count the occurrence of the comma's, so that we can find the parameters we want from the message.
E
So when we use Case, we are testing for the comma count value.

Your clip:
get_valq: '$QEIDEG,123,?

Select Case csv 'test for the comma count value
Case 2 ' IF its comma count 2 then do this bit of Code, else try 3 and so on
QEIDEG = leftStr(msg1, 3) ' It is 2 so QEIDEG = are the characters in the 'msg' starting at character 1 , for 3 characters
Case Else ' if no comma counts are found then quit the Case test

EndSelect
msg1 = ""
Return
Hi E,
For some reason, this is difficult to understand!
CASE 2 = goto comma 2
goto the left and save 3 digits '123'

Is this correct?
The SIM does this, then goes on the remove the '123' and replace it with '?'. How do I stop it replacing the '?' ?
C
 

ericgibbs

Joined Jan 29, 2010
21,451
hi C,
$QEIDEG , 222 , ?

Look at the msg : comma=1 appears between G and 2, then comm=2 appears between 2 and ?
So the Case is set comma =2, thats why its getting '?'

If that msg is always the same format, why not use
wanted value = midStr($QEIDEG,222,?, 9,3)
E

Typo Correction :
The above line should be: wanted QEIDEG value = midStr(msg, 9,3) // mistyped the string info.!

As I posted below:
Select Case csv 'test for the comma count value
Case 2 ' IF its comma count 2 then do this bit of Code, else try 3 and so on
QEIDEG = MidStr(msg,9, 3) ' It is 2 so QEIDEG = are the characters in the 'msg' starting at character 9 , for 3 characters
Case Else ' if no comma counts are found then quit the Case test
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,832
hi C,
$QEIDEG , 222 , ?

Look at the msg : comma=1 appears between G and 2, then comm=2 appears between 2 and ?
So the Case is set comma =2, thats why its getting '?'

If that msg is always the same format, why not use
wanted value = midStr($QEIDEG,222,?, 9,3)
E

Select Case csv 'test for the comma count value
Case 2 ' IF its comma count 2 then do this bit of Code, else try 3 and so on
QEIDEG = leftStr(msg1, 3) ' It is 2 so QEIDEG = are the characters in the 'msg' starting at character 1 , for 3 characters
Case Else ' if no comma counts are found then quit the Case test
Hi E,
There is an error witht eh'?' in your example, so before we go any farther I had better explain what's happening.
I'm trying to check if the DATASWITCH is switching correctly, which has 3x inputs now.

1/RX from the 18F4431 TX, [ Hserout "$QEIDEG", ",", #qeideg, ",", CrLf ],

2/plus the GPS NMEA sentence,

3/plus a radio input from the REMOTE, which hasn't been thought of yet, so I'm using a made up sentence [ $REMOTE,1100,1200,1300,1400,1500W,? ] that I have to transmit via another computer and a terminal macro.

All very complicated, so firstly, if I check the 18F4431 sentence marked in RED above. The #qeideg part is all I need. It is the generated QEI Degrees, from the incremental encoder 0 to 359. I added the commas for the CASE selection above.

You may have a better idea>
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,832
hi C
WRT,
I did ask for:
Post a exact single line copy of the message String you want to parse.

Not a just a part of a msg.
E
Hi E,
What does "WRT" mean?

I posted the whole sentence, but it will have CRLF instead of ?, as it will come from the 18F4431 as '1/' in the previous message.
C
 
Top