Percent = Value ** 1600 is one option but you're pissing away a lot of resolution.
Percent = Value ** 1600 is one option but you're pissing away a lot of resolution.
Thanks Henrik,
Is there a way to get better resolution ?
X = 4096 * 100
Percent = div32 value
Lcdout (dec2 percent)
To get .1% is easy, same aproach:Is there a way to get better resolution ?
Since you've got slightly over 4000 counts the smallest unit is around 0.025% but I don't know if you need, or even want, the display to show that?Code:Percent = Value ** 16000 ' Percent is now 0-1000 LCDOUT $FE, 1, Percent / 10, ".", Percent // 10
Or you could do it this way as there is no need to do another math operation on the variable:
Percent = Value ** 16000 ' Percent is now 0-1000
LCDOUT $FE, 1, Percent / 10, ".", Percent DIG 0
Just format the variable....
Dave Purola,
N8NTA
EN82fn
many thanks guys, I'll give it a go when I'm home from work
This works nicely, apart from one small issue, in that it won't display 100. It reached 99 and that's it !Code:pc1 = CH1_PWM ** 1600 lcdout $FE,$80,"CH1"," ",dec PC1
By resolution, I didn't realise that you were referring to the decimal resolution displayed, but was referring to the maths (I assume that whatever divisions were happening the increments for each 1% would be rounded down to an integer as PBP doesn't support FP maths).
Is there a way where I can display 100 for 4095 steps ?
Well, to be fair you said your value ranged from 0 to 4096, that's 4097 "steps" ;-)
pc1 = CH1_PWM ** 1601
There WILL be rounding (or truncating rather) issues, yes.
pc1 = CH1_PWM ** 16004 is better and will give you the result in steps of 0.1% as show before.
I feel I've written about the */ and ** so many times I've lost count, it's also described in the manual, but it's apparently one of those things...so here goes:
The ** multiplies the two values you give it. This results in an intermediate 32bit result. PBP then returns the top 16bits of those 32bits. This means it does an inherent divide by 65536 so you COULD think of the ** operator as a "multiply by units of 1/65536 command".
So x = value ** 1601 is PBP lingo for x = value * 0.02443 and what's 4095*0.02443? Correct, it's 100.
How did I find 1601? Well you want an "output value" of 100 for an "input value" of 4095 so, (100/4095)*65536=1600.39 but since you really wanted it to display 100 and not 99 we had to round that up to 1601. Same thing for the 0.1% resoultion, then we need to round it up to 16004.
I hope that makes sense.
/Henrik.
EDIT: Forgot, the */ and ** works slightly different depending on if you have LONGs enabled or not. The above describes how it works when DON'T have LONGs enabled.
Many thanks, and sorry for making you have to repeat yourself ;-)
Bookmarks