Getting a 3x digit output to a calculation using a SINGLE. Oshonsoft.

Thread Starter

camerart

Joined Feb 25, 2013
2,129
Hi,
I'm READing a compass on an 18F4431, which needs to be TXed to an 18LF4620, which then will be PARSED.
There is a calculation, so a SINGLE is used as a variable for 'DEG'
The PARSE routine expects a $sentence with a known length, how can I get an output with no digits after the decimal point and be always 3x digits e,g, '001'
Cheers, Camerart
 

ericgibbs

Joined Jan 29, 2010
11,156
hi.
Post an example of the data Single data and the required output example, will the output still need to be a Single or a Word etc .?

E
 

Thread Starter

camerart

Joined Feb 25, 2013
2,129
hi.
Post an example of the data Single data and the required output example, will the output still need to be a Single or a Word etc .?

E
Hi E, "Hope all's well"
Here is the section regarding the Compass.
These GOSUBS are intialised in the main LOOP.

I've commented out the Average section, but this will be re-introduced later.
I've been trying WORD, SINGLE and STRING.
The sentence should be like this: $COMPDEG,XXX,W and always be this length.
Cheers, C.
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
11,156
Hi
Check Oshonsoft, this is one option.
you could combine the steps to give a shorter text code
E

example: $COMPDEG,22,W

parStr= mid$tr(10,2) '' 22
parStr="000"+parStr '' 00022
parStr=rightStr(parStr,3) '' 022
 

Thread Starter

camerart

Joined Feb 25, 2013
2,129
Hi
Check Oshonsoft, this is one option.
you could combine the steps to give a shorter text code
E

example: $COMPDEG,22,W

parStr= mid$tr(10,2) '' 22
parStr="000"+parStr '' 00022
parStr=rightStr(parStr,3) '' 022
Hi E,
Thanks for that, but the CODE where this is PARSED is quite complicated, and written by another member, so I'm reluctant to change it.
Each of the PARSED $sentences must be the correct length.
Previously, almost the same set-up was for an Incremental encoder which outputted 2xBYTEs, which combined into a WORD that was always 3Digits, but WORD now doesn't do the same, as thre is a calculation before it.

Here is the relevent line: [ Const ixCOMPDEG_W = 13 ]
C
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,344
IIRC there is code in the stuff we worked on that fakes up the padding of small numbers with leading zeroes. I’ll take a look when I can but I’m pretty sure it was in the compass message if you want to look yourself
 

Thread Starter

camerart

Joined Feb 25, 2013
2,129
IIRC there is code in the stuff we worked on that fakes up the padding of small numbers with leading zeroes. I’ll take a look when I can but I’m pretty sure it was in the compass message if you want to look yourself
Hi JT,
Ok, I'll have a look, and report back.
Thanks.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,129
Hi JT,
NOTE: The 18F4431 PIC where the Compass is now READ doesn't PARSE but SENDs it's READng [$COMPDEG,XXX,W] to the PARSE PIC 18LF4620.

I've just been testing WORD, SINGLE and STRING combinations, and none of the are giving even READing and calculating properly, so it looks like I'm going to go back a bit, and re-try.
C
 

JohnInTX

Joined Jun 26, 2012
4,344
Hi JT,
Ok, I'll have a look, and report back.
Thanks.
C.
It was something like:

degrees is an integer 0-359

Code:
'output ddd, 0dd or 00d depending on value of degrees integer

if degrees < 100 then
Heserout "0"  ' heading is 0-99, output leading 0

if degrees <10 then
Hserout "0" ' heading is 0-9, output second leading 0

Hserout #degrees ' output 1,2 or 3 remaining significant digits
Also recall that the fixed known length requirement was part of the checks on data integrity absent any checksum or CRC.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,129
It was something like:

degrees is an integer 0-359

Code:
'output ddd, 0dd or 00d depending on value of degrees integer

if degrees < 100 then
Heserout "0"  ' heading is 0-99, output leading 0

if degrees <10 then
Hserout "0" ' heading is 0-9, output second leading 0

Hserout #degrees ' output 1,2 or 3 remaining significant digits
Also recall that the fixed known length requirement was part of the checks on data integrity absent any checksum or CRC.
Hi Jt,
You have a much better memory than I do.
I did a search and found this: https://forum.allaboutcircuits.com/...errupts-and-parse.168960/page-16#post-1530066 #311 #312

I don't think it registered with me:rolleyes:

As the 18F4431 was empty, I'll start again and incorporate this section.
"and may be some time", said Captain Oates.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,129
Hi JT,
A bit bewildered, but it appears to be working :)
Better leave it today, and see what we've done tomorrow, when my head stops spinning ;)
Cheers, C.
____________________________________________________
 

Attachments

Last edited:
Top