Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,840
hi C.
Dim s2m(10) As Byte.
Can only hold '99' or 'FF' max.
E
Hi E,
Interesting.
Is this correct, that to hold more than 99, the BYTE must be saved as a HEX BYTE not a NUMBER?
EDIT

EDIT: (0) (1) are from the Incremental encoder that I assume are BYTES, (2) (3) are 1 and 2, which don't change?
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,459
hi,
Basics,
A Byte is typically 8 Bits in Width.
So 0x11111111 is the maximum value it can be.

If I had a decimal number of say '123', it would have to be saved in the Array(0) as 0x7B

Is that what you mean.?
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
hi,
Basics,
A Byte is typically 8 Bits in Width.
So 0x11111111 is the maximum value it can be.

If I had a decimal number of say '123', it would have to be saved in the Array(0) as 0x7B

Is that what you mean.?
E
Hi E,
Not really.
99 is well within the 0x00-0xFF range, or was it a typo?
C
 

ericgibbs

Joined Jan 29, 2010
21,459
hi,
This is the query you initially asked.
When (0) goes above 2x digits-99 the results get messed up.
Can someone tell me why please?

As I have said, you cannot store more than 2, 'BCD' digits in a Byte Array location.

You could consider.
Dim s2m(10) as Single 'as an option

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
hi,
This is the query you initially asked.
When (0) goes above 2x digits-99 the results get messed up.
Can someone tell me why please?

As I have said, you cannot store more than 2, 'BCD' digits in a Byte Array location.

You could consider.
Dim s2m(10) as Single 'as an option

E
Hi E,
I'll have to keep playing to 'get it', it doesn't seem complicated, but it is.
I started with only a 2x BYTE array, which did increment (0) 0-255 (1) 0-1, this 99 stuff only started when I added (2) and (3).

Perhaps SINGLE will do the trick?

I'll carry on playing and report back.
Thanks, E.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
hi,
Look at this option.
Dim s2m(10) As Word
E
Hi E,
There's a lot of stuff rattling round my mind regarding BYTES, SPI, WORDS etc
I'm sure your CODE example would work ok, but in my case, the 'problem' BYTES are set-up in the SLAVE PIC, then sent to the MASTER via SPI, which is the one with the HSEROUT.
Working on 2x programs at the same time is a stretch, but I'm getting used to it. It will take a while.

Thanks, C.
 

ericgibbs

Joined Jan 29, 2010
21,459
hi C,
I can understand why you are having problems as you develop this software.
Checking through some of our earlier working programs, they no longer compile due to syntax errors.

The reason for this are due to the changes made in the Oshonsoft compiler version issues.
This, and the number of unsupported features in some of the later PIC types, has made me move away from using Oshonsoft.

E
 

sagor

Joined Mar 10, 2019
1,050
When over 99, is your sending unit sending 3 single digits, not 2?
That is, what is the format of the data of the sending unit? Is the length of data always 2 digits?
Array(0) can take any value from 0 to 255 binary (0xff Hex), so what format is the "99" in?
It may be that the sending unit is changing the digits, not that it is an error on the receiving end...
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
Hi E,
There's a lot of stuff rattling round my mind regarding BYTES, SPI, WORDS etc
I'm sure your CODE example would work ok, but in my case, the 'problem' BYTES are set-up in the SLAVE PIC, then sent to the MASTER via SPI, which is the one with the HSEROUT.
Working on 2x programs at the same time is a stretch, but I'm getting used to it. It will take a while.

Thanks, C.
Hi E,
hi C,
I can understand why you are having problems as you develop this software.
Checking through some of our earlier working programs, they no longer compile due to syntax errors.

The reason for this are due to the changes made in the Oshonsoft compiler version issues.
This, and the number of unsupported features in some of the later PIC types, has made me move away from using Oshonsoft.

E
Hi E,
Yes, I'm not sure if in this case it's the tools or the operator, time will tell.
I'm not sure if it makes it clearer, but I've edited #1182
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
When over 99, is your sending unit sending 3 single digits, not 2?
That is, what is the format of the data of the sending unit? Is the length of data always 2 digits?
Array(0) can take any value from 0 to 255 binary (0xff Hex), so what format is the "99" in?
It may be that the sending unit is changing the digits, not that it is an error on the receiving end...
Hi S,
I'm not used to ARRAYS yet, and not sure whether NUMBERS, HEX or ASCII is being sent, especially for the Incremental encoder, as this is what's making the error.
The length of the DATA (for this and other sections) is variable. I have in my files VAR LOOPS, and will have to dig them out.
My first tests were on 2BYTE ARRAYS, which counted from 0-359, then I added 2 more (4BYTE) and this is when the 'overflow' started.
It's possible that the error is something to do with a different number of BYTE ARRAYS in the MASTER or SLAVE, and being 2x programs, takes some getting used to.

First question: How can I check what is being sent from the HW Quadrature encoder on 18F4431?
C
 

sagor

Joined Mar 10, 2019
1,050
You seem to be using QEIDEG.LB and a .HB, yet your printout says QEIDEG(0) and QEIDEG(1). That is confusing, QEIDEG is a word, not an array. You equate 2 bytes to the word then print out the word as such. Your printout should show QEIDEG with no array designation.
Depending on how the compiler has allocated variable space, you may be overwriting other storage space, causing corrupted values.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
You seem to be using QEIDEG.LB and a .HB, yet your printout says QEIDEG(0) and QEIDEG(1). That is confusing, QEIDEG is a word, not an array. You equate 2 bytes to the word then print out the word as such. Your printout should show QEIDEG with no array designation.
Depending on how the compiler has allocated variable space, you may be overwriting other storage space, causing corrupted values.
Hi S,
True, it is confusing, and difficult to unravel. Can you point to my printout so I'm clear which one you're refering to please?

As I understand it, BYTES sent via SPI can be arranged in an ARRAY of BYTES, therefore: [ DIM s2m(10) as BYTE ], and this is sent serially across SPI.
I understand that QEIDEG is made up of .LB and .HB, which could be seen as a WORD but as BYTES are used for SPI, then this is what I used.

I thought that MASTER and SLAVE both have ARRAYS so that if (0) is sent then (0) is received and so on, but this doesn't seem to be the case, and in my example they are getting out of step.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
Hi,
Jumping between 2x programs MASTER/SLAVE, then changing PICKIT3 over, and Terminal view from each of the PICs, was causing difficulty, so now I have 2x separate systems i,e, 2x of everything, so I can WRITE to the SLAVE and instantly WRITE to the MASTER. Still not easy but I'll get used to it.

Anyway, I've gone back to a 2xBYTE ARRAY only from the Incremental encoder on SLAVE after being READ by the MASTER, here's the Terminal view. No WORDS only BYTES, and as can be seen it is now overflowing at 255.
C
 

Attachments

sagor

Joined Mar 10, 2019
1,050
QEIDEG, is it defined as an array as well? You are printing QEIDEG(0) and QEIDEG(1). If that is a WORD array, then you are printing out 4 bytes in total.
It may be just your text as written in the output (mistake?). But if moving bytes to a .LB and a .HB of a word, you just print the word, there is no subscript. That is, you print QEIDEG and it should be a value between 0 and 65535
Without seeing how you declared that variable, I'm only guessing....
 

Thread Starter

camerart

Joined Feb 25, 2013
3,840
QEIDEG, is it defined as an array as well? You are printing QEIDEG(0) and QEIDEG(1). If that is a WORD array, then you are printing out 4 bytes in total.
It may be just your text as written in the output (mistake?). But if moving bytes to a .LB and a .HB of a word, you just print the word, there is no subscript. That is, you print QEIDEG and it should be a value between 0 and 65535
Without seeing how you declared that variable, I'm only guessing....
Hi S,
I'm guessing quite a bit also, but using the above set-up, which makes life easier (still mistakes though) I am trying different things.

Using only the incremental encoder output LB and HB (I'm pretty sure they are HEX) and adding 2x HEX tests 111 and 222 into the SLAVE program, it is now sending 4x BYTEs correctly. I'll keep practicing, till I understand what's going on better.

The screen shot is from the MASTER terminal output, after coming through the SPI tunnel. The QEIDEG is what I typed, not a real BYTE or WORD.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,840
Hi,
I think I understand BYTE ARRAYs a bit better.
If the send and receive ARRAYS are dimensioned the same e,g, Dim s2m(10) as byte, and the number of BYTEs sent is the same number received, then no errors, if there is an inbalance between BYTEs sent and received, then there are errors.

Soon I will be trying to received NMEA sentences from GPS modules which also use SPI and BYTE ARRAYS, the NMEA sentences begin with a $ and I have chosen to count to the W (west) for what I want.
Going back to the S2M ARRAYs. If I add a $ at the beginning and a W at the end of the send ARRAY, and in the receive, I wait for the $ and count till the W, will this be useful.

I hope I've understood what's going on?
C
 

ericgibbs

Joined Jan 29, 2010
21,459
Going back to the S2M ARRAYs. If I add a $ at the beginning and a W at the end of the send ARRAY, and in the receive, I wait for the $ and count till the W, will this be useful.
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
 
Top