04-18-2019 06:32 AM
I have a VSD speed setpoint that ranges from 0-4000 in HEX representing 0-100% of my max speed
I am trying to use a slider that is numerical 0-4000 that inputs the values over two bytes via RS485 as 40 00 which is 4000 in hex
I have all the comms working I just cannot figure out how to convert the literal decimal value to its hex format..
not 4000 in decimal = 0F A0
I want 4000 in decimal to = 40 00
any help in the right direction would be greatly appreciated
Solved! Go to Solution.
04-18-2019 06:45 AM
That's a crazy way to pass numbers.
Decimal to string. Width of 4.
String to Hex. Datatype U16.
04-18-2019 06:48 AM
Would you mind showing some code?
Are you sending the data as a string?
What format does the data need to be in (4000 vs 40 00,etc)?
There are plenty of ways of converting numerics to strings and parsing them or manipulating them to look certain ways.
04-18-2019 06:53 AM
Hi,
sure you can do that, but have you thought about setting the slider's range from 0 to 1 (or "100%") and use it only as factor in your BD?
Regards
04-18-2019 06:55 AM - edited 04-18-2019 06:56 AM
Hi David,
I just cannot figure out how to convert the literal decimal value to its hex format..
Are you REALLY sure about this decimal/hex thing?
Using your approach you are missing 37.5% of the possible setpoint range!
You could set values of x000-x999, but you miss all the range from xA00 to xFFF…
(Well, you miss even more values, like x0A0-x0FF, too!)
Would it help to just change the formatting of the slider to numeric hex format?
04-18-2019 08:59 AM
I am trying to create a dynamic PDU,
4000 in hex is 100% of the setpoint speed
2000 is 50%
maybe I am thinking of it in the wrong way
04-18-2019 09:26 AM - edited 04-18-2019 09:27 AM
You are definitely thinking about it the wrong way. It looks like 0-4000 hex is your range from 0-100%. I'm not sure why it wouldn't scale to FFFF hex.
You don't want 4000 in decimal converted to 4000 in hex, the table doesn't show that at all.
The table is a somewhat confusing example because it never shows a "hex" character (A-F) except for 1% at A4.
Take your percentage, divide by 1000, and multiply times 4000, an integer constant formatted as hex display.
04-18-2019 09:48 AM
I think this is what you are looking for...
04-18-2019 01:45 PM
What's wrong just formatting the tick marks in hex? (make sure the slide datatype is U16)
04-18-2019 08:31 PM
I decided to go with a 0-100% slide bar with the correct correction factor