Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,837
hi C,
You know an Array Byte is 8 Bits long, and you can get two BCD chars in a Byte, value from 0 0 thru F F.

So, why are you adding a '$' in the array(0).?
Also, what if while reading the GPS message, the 'W' is not received.?
Remember, we tested for the 'comma's in the message to check that a message was valid or incomplete.

We covered and fully debugged receiving and formatting this GPS message coding about 7+ years ago.:rolleyes:

E
Hi E,
Bearing in mind that I'm new to ARRAYS, I'm pretty sure that the Incremental encoder is outputting 2x BYTEs 0-255 and 0-255, which when combined give 0-359 Degrees. I have been testing the rest of the (10) ARRAY in the same way, giving each one any number between - and 255, which is working.

My previous post mentioned errors when the send array and the receive array are of different size, so I thought of a similar idea to a start and stop BIT, but in this case BYTEs, to count the BYTES between start and end, so that they both can match. I presume the GPS NMEA sentences use a $ at the beginning and a * at the end for the same reason??, so I thought I could do the same, although I know they have a checksum.

7+years:)
anyway, since then some things have changed, (from memory) I think the NMEA sentences are tested at the beginning $ and at the end W, so if one is missing it skips till another message?? I can check, if you want. Also I can now set them to only send 1x chosen message.
C.
 

ericgibbs

Joined Jan 29, 2010
21,452
hi C,
I would use this method for the encoder.
E

Dim enclen as byte' number of Words to get
Dim enc1 as Word' 16 Bit
Dim encdata(5) as Word. ' store upto 5 Words

;routine
enclen=0
loop1: 'do loop to get all the encoder data
Get encoder ' assume a value of 02
enc1.HB=encoder
get encoder 'assume a value of 59
enc1.LB
encdata(0)=enc1 ' contains 0259
enclen=enclen+1 ' get next
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
hi C,
I would use this method for the encoder.
E

Dim enclen as byte' number of Words to get
Dim enc1 as Word' 16 Bit
Dim encdata(5) as Word. ' store upto 5 Words

;routine
enclen=0
loop1: 'do loop to get all the encoder data
Get encoder ' assume a value of 02
enc1.HB=encoder
get encoder 'assume a value of 59
enc1.LB
encdata(0)=enc1 ' contains 0259
enclen=enclen+1 ' get next
Hi E,
So far I've been only using BYTEs.
Say I have a (10) BYTE array and the first 2x are the Incremental encoder, and the next 1x is a voltage, if I use WORDs then I would have 1/2 a WORD left over, is it ok to stick to BYTEs?
C.
 

sagor

Joined Mar 10, 2019
1,050
Hi E,
So far I've been only using BYTEs.
Say I have a (10) BYTE array and the first 2x are the Incremental encoder, and the next 1x is a voltage, if I use WORDs then I would have 1/2 a WORD left over, is it ok to stick to BYTEs?
C.
I would say stick to bytes for now, until you get everything working properly. Going to words just complicates things when something gets "broken", as you have to debug the bytes within the word anyway. So why not stick to bytes for now....
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
I would say stick to bytes for now, until you get everything working properly. Going to words just complicates things when something gets "broken", as you have to debug the bytes within the word anyway. So why not stick to bytes for now....
Hi E and S,
Good plan.
From memory, I think with the existing NMEA sentences, there is a 'Max STRING length' or similar, that sets the number of BYTES in the STRING. If I'm correct, and I can get the NMEA GPS to be read via SPI, then the BYTE method will work in a similar way. As you might guess, I'm on my limits,and may need reminding about
WORDs etc.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi E,

We covered and fully debugged receiving and formatting this GPS message coding about 7+ years ago.:rolleyes:

Just bumped into the later GPS NMEA error set-up, so I thought I'd post it. As you can see it is very comprehensive, and far beyond anything I could dream up, by JOHNINTX.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
Can someone clarify some points for me please?
See diagram: DATA before being sent can be in different forms, BIN, HEX, DEC, ASCII, and passes via SPI as binary BITS. I know it sometimes needs converting e,g, using # for Terminal view, but does it ever need converting before passing SPI, and once received does it need converting for any other reason, than Terminals view?

EDIT: When an NMEA sentence is being retrieved, it is a mixtre of ASCII and DEC characters. What is the mechanism that sorts out what's what?

EDIT EDIT: I think I understand the answer now.
E
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
I'm swapping ARRAY DATA between MASTER/SLAVE via SPI, but not quite correctly.
One question: Does it matter which order the SSPBUF RD/WR is written in the program?
See image:
C
 

Attachments

ericgibbs

Joined Jan 29, 2010
21,452
hi C,
It depends upon what you are going to do with data after you have got the complete array.

I prefer to keep it in the same order as the sending device output.

So if the sender sends 01 ..... 59 store as 01(0) .... 59(1) .......... then don't store as 59(0) ..... 01(1)

How many Bytes do you get from the Sender that is a single Parameter.?

Post a typical Sender string
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
hi C,
It depends upon what you are going to do with data after you have got the complete array.

I prefer to keep it in the same order as the sending device output.

So if the sender sends 01 ..... 59 store as 01(0) .... 59(1) .......... then don't store as 59(0) ..... 01(1)

How many Bytes do you get from the Sender that is a single Parameter.?

Post a typical Sender string
E
Hi E,
I'm figuring things out, and have 2x ARRAYS the same length [ s2m(10) SLAVE to MASTER and m2s(10)

Here are the MAIN LOOP sections from programs from each PIC.
C
Code:
main:

s2m(0) = "$"  '36  'Can be "ASCII", DEC, HEX or BIN
s2m(1) = CAP2BUFL -----(From incremental encoder)
s2m(2) = CAP2BUFH
s2m(3) = 100  '0x1e  '30
s2m(4) = 0x28  '40
s2m(5) = 0x32  '50
s2m(6) = 0x3c  '60
s2m(7) = "W"
s2m(8) = 0x50  '80
s2m(9) = 0x5a  '90
    
For s2minc = 0 To 9

    m2s(m2sinc) = SSPBUF
    While slave4431_cs = 1  'Waiting till CS goes ON =0
        Wend
    While Not SSPSTAT.BF
        Wend
    SSPBUF = s2m(s2minc)
    WaitUs 2  '?
    
'[[[ HSEROUT NOT USED- TX PIN NOW '1'IN ]]]

    Serout PORTA.2, 9600, "S2M(S2MINC) ", #s2m(s2minc), "    ", s2m(s2minc), CrLf  'CAP2BUFL
    WaitMs 50
    Serout PORTA.2, 9600, "M2S(M2SINC) ", #m2s(m2sinc), "    ", m2s(m2sinc), CrLf, Cr
    WaitMs 50

    s2minc = s2minc + 1

Next s2minc

s2minc = 0

Toggle yled

Goto main
End                                 
'-------------------------------------------------
MAIN:

m2s(0) = "H"  '72  'DEC or HEX, the result when read in ASCII is the same.
m2s(1) = "E"  '69
m2s(2) = "L"  '76
m2s(3) = "L"  '76
m2s(4) = "O"  '79
m2s(5) = "W"  '87
m2s(6) = "O"  '79
m2s(7) = "R"  '82
m2s(8) = "L"  '76
m2s(9) = "D"  '68

'S2M is read by SSPBUF

slave4431_cs = 0  'CS ON

For s2minc = 0 To 9

    SSPBUF = m2s(m2sinc)  'm2s = 8-9
    While slave4431_cs = 1  'Waiting till CS goes ON =0
        Wend
    While Not SSPSTAT.BF
        Wend
    s2m(s2minc) = SSPBUF
    WaitUs 2

    qeideg.LB = s2m(1)
    qeideg.HB = s2m(2)
    qeideg = qeideg / 4

    Hserout "M2S(M2SINC)= ", #m2s(m2sinc), "    ", m2s(m2sinc), CrLf  'See if m2sinc = each number?
    WaitMs 50
    Hserout "S2M(S2MINC)= ", #s2m(s2minc), "    ", s2m(s2minc), CrLf, CrLf
    WaitMs 50
    
    m2sinc = m2sinc + 1
'If m2sinc = 9 Then m2sinc = 0
Next s2minc

m2sinc = 0

Hserout " QEIDEG=  ", #qeideg, CrLf, Cr

slave4431_cs = 1  'CS OFF
WaitMs 1000

Toggle rled

Goto MAIN
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
There seems to be something else giving errors, when MASTER/SLAVE between 2 PICs!

As I work down each ARRAY, with a terminal view screen, e,g a fault appears as I get to (3) in both ARRAYS.
With a duplicate line=no fault, omment the line out=ok.

I've had a suggestion to use simplex instead, i,e, M2S then S2M. Up to now, all the peripherals that are working use SIMPLEX.
Let's see how I get on.
C
 
Last edited:

sagor

Joined Mar 10, 2019
1,050
You are incrementing the "For" index twice in the first Main program:
Code:
For s2minc = 0 To 9

    m2s(m2sinc) = SSPBUF
.
.
.


s2minc = s2minc + 1

Next s2minc
You can't do that, it will increment by 2 probably.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
You are incrementing the "For" index twice in the first Main program:
Code:
For s2minc = 0 To 9

    m2s(m2sinc) = SSPBUF
.
.
.


s2minc = s2minc + 1

Next s2minc
You can't do that, it will increment by 2 probably.
Hi S,
Yes, I spotted that yesterday, but thanks.

The MASTER is receiving correct DATA from the SLAVE.
The SLAVE gets errors as I'm going down the list setting up its receive then printing. It's ok to start, and if a $ is received a $ shows, then the next is ok, then, for some reason, the $ stops being received and there's something else shown.
All a bit strange.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
I now have 2x program pairs 1x pair S2M and the other pair M2S, both work ok with SPI. They needed careful timing to work.

I've been trying to blend them into 1x pair of programs where S2M and M2S cross, as they are supposed to, but this always gives erros.

1/ Is this a sign of poor programming?
2/ Is it advisable to simply get them to work in 2x programs, but alternatively, S2M then M2S and so on?

EDIT: ANSWER- Poor Programming :)
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
Good news!

All 6x peripherals are now working on the BASE transmitter: HC-12, Joysticks, GPS, Compass, Incremental encoder and Altimeter.
and only 4x years to do it. [ Can I have a job? ]
Got to do quite a bit of tidying, then a similar job on the REMOTE, which is very similar, and we have the tools to play with. i,e, add joystick up and REMOTE goes up.

Thanks to all that helped, so far.
Cheers, Camerart.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi, (Choosing which GRID?)
With QEIDEG, any angle, 0-359 DEG can be dialled, by turning the QEIDEG knob.

In #1, there is an image 'SQUARE and CIRCLE GRID'. I'm at the stage where I have to decide which one is best for this project.

e,g, with SQUARE GRID and QEIDEG at 0 Deg, forward would send the REMOTE northerly in parallel with the vertical lines. With CIRCLE GRID and QEIDEG at 0 DEG, forwards would send the REMOTE away from the centre.

Does anyone have preference which one to choose?

EDIT: We have decided that the GRID is the best as it is most similar to LONG/LAT therefore easier for me to visualise and probably fewer geometry calculation, so for now it's grid.
C
 
Last edited:
Top