PDA

View Full Version : Need help with scaling



champion
- 10th November 2006, 15:08
I know this info has probably been posted before so I apologize for the repeat, but I cannot find what I'm looking for with the search function.

I am simply measuring angular displacement with a pot, using PBP's pot function. However, it is important to me to be able to display the angle in degrees and minutes. Therefore, I have done some mathematic scaling on paper to yield minutes. Here's what I've got:

360 degrees is broken into 255 units, thus 1.412 deg/unit

however, when I try and scale the reading I get from the pot command by this 1.412, it only uses 1.0.

What should I try???

Melanie
- 10th November 2006, 16:09
Take your 0-255 unit

Multiply by 1412 into a Dummy Variable

Then use DIV32 to divide by 10

example...

255 x 1412 / 10 = 36006

If you multiplied by 14118 and divided by 100 you would be more accurate yealding...

255 x 14118 / 100 = 36000

Either results gives you two decimnal places (remember we're playing integers here, so the two decimal places are the rightmost two characters of the result.

That won't be minutes though... it'll be DECIMAL degrees... you'll have to do some more math to calculate that into minutes.

You have a POT that rotates exactly 360 degrees?

champion
- 10th November 2006, 17:56
No, the pot has no detents or stops. It will rotate freely from 0 to 360 and back to 0. It's needed for my application to reduce the chance of damage if someone were to try and just spin the pot. Thanks a lot for your help with a rather elementry question.

champion
- 10th November 2006, 18:46
ok, how about this. Now that I have gotten into degrees, I have fractions of degrees that I can show on the LCD by outputing the 1 and 0 bit of the degree measurement. In order to convert these two bits into minutes, I have to be able to combine the 1 and 0 bits as one integer and multiply by 60. Again, this has probably already been mentioned before but I still can't find it in the search function. Thanks.

P.S.
I know this is a beginner's question, but I will bet that you all were beginners at one point as well so take it easy on me please. thanks!!!

sayzer
- 10th November 2006, 18:51
P.S.
I know this is a beginner's question, but I will bet that you all were beginners at one point as well so take it easy on me please. thanks!!!




I knew PBP when I was born :)



------------------------

champion
- 10th November 2006, 18:57
I knew PBP when I was born :)



------------------------

Me too, I just forgot it while I was in college :(

champion
- 10th November 2006, 19:34
I guess what I'm asking is how to take the 0 and 1 bit from one number and put them into a seperate number so that I can further scale just those two bits. Thanks!!!

SteveB
- 10th November 2006, 20:34
I guess what I'm asking is how to take the 0 and 1 bit from one number and put them into a seperate number so that I can further scale just those two bits. Thanks!!!

This will give you a value with just the first two bits of the original byte:

TwoBits = OrigByte & %00000011

HTH,
Steve

SteveB
- 10th November 2006, 21:31
Here may be a more complete answer to your question:


PotValue VAR BYTE
Degrees VAR WORD
Minutes VAR WORD


Degrees = Potvalue * 14118 ' Convert to degrees and fractional Degrees
' scaled by 10000.
' It does not matter that we assign Degrees a value before DIV32,
' since DIV32 uses only internal PBP variable in the calculation
' It is important that DIV32 follows right after the Multiply
'
Degrees = DIV32 10000 ' Returns degrees
Minutes = R2 ' Returns the remainder of the division,
' which is fractional degress scaled by 10000
Minutes = (Minutes * 6)/1000 ' returns minutes

Here are a couple of nice threads by Darrel Taylor dealing with exploiting PBP's integer math:

Retrieving 32bit Multiply Result (http://www.picbasic.co.uk/forum/showthread.php?t=24)
Retrieving Div32 Remainder (http://www.picbasic.co.uk/forum/showthread.php?t=48) (This one explains "Minutes = R2". See the last post in the thread)
32-bit Variables and DIV32, Hourmeter 99999.9 (http://www.picbasic.co.uk/forum/showthread.php?t=1942)

Steve

SteveB
- 10th November 2006, 21:52
It seems a little over-kill to be getting minutes when the accuracy of your measurements is not even 1 degree. That, and a pot is also not likely to give you very consistant accuracy as well. Even if you used 10 bits, you are still looking at a LSB of .35 degrees (21 minutes).

Just my 2 cents,
Steve

champion
- 10th November 2006, 21:58
Thanks again for all of your help. I have tried this, and I get a two bit result, however they are not the last two digits of the potvalue * conversion. I will do more research inside the threads you listed to figure out exactly what these two bits are representing. Thank you very much for your help, and I will be sure not to forget it when/if you ever have a question in the future.

champion
- 13th November 2006, 03:20
Steve, actually I am trying to have accuracy down to 1 minute. I have come to the conclusion however, like you say, that a pot will not have the repeatability that I will need to take on this task. I have moved on to an optical encoder with 8192 pulses per revolution and a gear ratio of 3:1. Thanks for all of your help.