from decimal to hex
moomoo
Posts: 27
I have a picopic· 16 bit servo controller. I can only type in hex values in the serout command and not ascii represented hex.
SEROUT 1, 240,[noparse][[/noparse] 120, 1, $05, $DC, 100]
1 =··· OUTPUT PIN ON BS2SX
240 = BAUD RATE
120 = SERVO CONTROLLER ADDRESS
1 =··· CHANNEL ON THE SERVO CONTROLLER
$05 = LOWBYTE OF 1500 OR 1.5ms
$DC = HIGHBYTE OF 1500
100 = SPEED OF THE SERVO
I'M USING THE MEMSIC 2125 AND THE INPUT OF THE·MEMSIC·IS THE OUTPUT OF THE SEROUT COMMAND.
The problem is that the servo controller only excepts the hex commands this way only. It will not except HEX X.LOWBYTE, HEX X.HIGHBYTE and it will not except a decimal number or anything ascii.
I have the memsic setup to represent 1500 as "level and center" of my humanoid and that it's values deviate from 1500.
Now the question, how do I have 1500 ( or any number ) turned into hex value·and place this into the serout command for this to work right. I feel like I've tried everything.
I need help, please.
·
SEROUT 1, 240,[noparse][[/noparse] 120, 1, $05, $DC, 100]
1 =··· OUTPUT PIN ON BS2SX
240 = BAUD RATE
120 = SERVO CONTROLLER ADDRESS
1 =··· CHANNEL ON THE SERVO CONTROLLER
$05 = LOWBYTE OF 1500 OR 1.5ms
$DC = HIGHBYTE OF 1500
100 = SPEED OF THE SERVO
I'M USING THE MEMSIC 2125 AND THE INPUT OF THE·MEMSIC·IS THE OUTPUT OF THE SEROUT COMMAND.
The problem is that the servo controller only excepts the hex commands this way only. It will not except HEX X.LOWBYTE, HEX X.HIGHBYTE and it will not except a decimal number or anything ascii.
I have the memsic setup to represent 1500 as "level and center" of my humanoid and that it's values deviate from 1500.
Now the question, how do I have 1500 ( or any number ) turned into hex value·and place this into the serout command for this to work right. I feel like I've tried everything.
I need help, please.
·
Comments
SEROUT 1, 240,[noparse][[/noparse] 120, 1, position.LOWBYTE, position.HIGHBYTE, 100]
Again, don't get wrapped around the axle on the Hex thing; its a format for humans, the devices don't care. What you need to understand about the HEX modifier, however, is that it converts a value to its text representation, hence your version did not work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
That includes the Scientific Calculator in any version of Microsoft Windows.
I am also sure you can download a shareware calculator to do the same thing.
So...
It really is not that hard to convert.
Alternatively, you can set up a table in Excel and then just peek at it rather than keyin values as required.· Personally, I like the table as it seems far more efficent and easier to use.
AND also,
Code usually limits the range of Hex numbers.· You are not going to use this for scientiful or engineering calulations - mostly it counts up to 255 or up to 4095 as a more convient format than Binary [noparse][[/noparse]which is really hard to deal with in anything over 16 or so].
HEX works very well with the modularity of pages and addresses·in memory when you begin to work with such issues.·
Decimal does not so obviously relate to pages [noparse][[/noparse]for instance 1K of memory is not really 1000 Bytels, but 1024 Bytes in Decimal·or 400 Bytes in HEX].
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
G. Herzog in Taiwan
Post Edited (Kramer) : 1/1/2005 2:23:25 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester?
http://hometown.aol.com/newzed/index.html
For the sake of arguement, I tried the position.lowbyte thing again and that doesn't work. They have made the firmware to only except hex values ONLY and nothing else! That is what is so frustrating. There is nothing in pbasic to convert a decimal to hex?
My input data is a stream of decimal numbers.
The program·needs to convert·decimal number·to hex equivalent.
The hex value is then placed into the serout command to the servo controller.
Is there another way?
Anthony
Note that the 100 at the end of the stream will affect how fast the servo moves.· You may want to change this to 0.
Let me say this again -- and please believe me because I've been doing this stuff a very long time -- Hex values are for programmers' convenience and the machines don't care; internally everything is binary (1s and 0s).
And before you vent toward me again, let me point out that the PicoPic manual contains nothing but BASIC Stamp examples.· Do you think that would be the case if there was a problem using the BASIC Stamp to control this device?....· I don't.
Try this little test program:
If your connections are correct (do you have a common ground between your BASIC Stamp and the PicoPic?) this should cause a servo connected to port #1 to sweep back and forth.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
In your original post you stated that $05 = LOWBYTE of 1500 and $DC = HIGHBYTE. I believe the order is reversed.
For DEC 1500:
HEX HIGHBYTE = $05
HEX LOWBYTE = $DC
I'm not sure it matters now in the discussion, but you might check it.
Dave G
Can you forgive me for my venting?
I just read your reply and I read Dave G's reply about it being reversed and then I looked back at your example.........and I feel like an IDIOT!!!!
I've had the SEROUT 1, 240,[noparse][[/noparse] 120, 1, position.LOWBYTE, position.HIGHBYTE, 100] reversed as Dave pointed out and you've had it written right the whole time and I wasn't paying attention to that at all.
I'M AN IDIOT!!!!!!!
Thank you so much, Ron, for your patience and the fact that you went through the trouble to look up the manual for the picopic and read it.
Again, please forgive me!
And thank you too, Dave!
Rage is another form of blindness.
Calculator, then View
Scientific
See attached image
Please forgive me for not really looking at the context of the question.
And, Happy New Year to all.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
G. Herzog in Taiwan
Post Edited (Kramer) : 1/2/2005 1:06:33 PM GMT
Thanks!
Mike
Not to follow up on the "IDIOT" thing, We all get balled up at times: But it was Mr. Jon Williams with a " J " not " RON " That answered Your post.
Please edit Your post.As this is disrespectful to Mr. Williams. Its A southern Thing I hope You understand.
___Most Respectively______________$WMc%________Happy New Year
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there