PDA

View Full Version : Math for A/D conversion



Pickplayer
- 13th November 2016, 23:57
How can I display on PC a leading 0 for example, If I am reading a voltage of 2.0498 how do i display only 2.04? If I use Hseout
"Voltage="dec2 I get 2.98 same with debug. The only way I can get the leading 0 to dislpay is to read out all 4 digits. I wold like to display only 2 digits .04.

HenrikOlsson
- 14th November 2016, 06:20
If you have 20498 in a variable (representing 2.0498V) and you want 2.04 divide the value by 100 so that the value becomes 204 then HSEROUT[DEC value/100, ".", DEC2 value //100]

If you want to round off the value (instead of truncating) add 50, then divide by 100.

/Henrik.

Pickplayer
- 14th November 2016, 19:46
Thanks Henric
The values in the variable are after divide// for remainder with 0 as leading bit remainder = 0498

HenrikOlsson
- 15th November 2016, 06:07
Hi,
I'm sorry, is there still a question in there somewhere or did you solve the problem?

/Henrik.

Pickplayer
- 17th November 2016, 20:03
Henrik: Yes it is still a question The values in the variable are after divide// for remainder with 0 as leading bit remainder = 0498 any time I have a remainder in a calculation of leading bit 0 debug will not read it. for instance if the remainder is 0498 debug reads 498, if I debug dec 4 then it will read all four digits. If I debug dec2 then it reads 98. I hope I made myself clear enough as to understand my delema.

HenrikOlsson
- 17th November 2016, 20:13
And the answer is the same as before. Divide by 100 then use DEC2 to display the result.

If the variable contains 498 and you want that to display as 04 after a decimal point divide by 100 (result = 4) use DEC2 to display with a leading 0. And, again as before, if you rather round than truncate add 50, then divide by 100, then use DEC2. HSEROUT[DEC2 (498+50)/100] will display 05.

/Henrik.

PickPlayer
- 23rd November 2016, 20:33
Henrik: The light finally turned on thanks!!