Hi Scott,
As long as a 31 bit number will do, there is a way to deal with larger numbers with PBP. Multiplying 2 word sized variables together gives a 32-bit result. You can't use the result directly, but if you immediately follow it with a DIV32 statement you can work with some pretty big numbers.
10000/255 = 39.21568627 So round that to 3 decimal places and multiply by 1000 = 39216Code:PotValue Var byte Dummy Var Word W1 Var Word Dummy = 39216 ' 10,000/255 * 1000 rounded W1 = PotValue ' Copy to a Word variable Dummy = Dummy * W1 ' 32-bit result is in PBP system vars Dummy = Div32 1000 ' divide 32 bit result by 1000 ' ** Dummy now holds the resistance value. **
Now multiply that number times the POT value (0-255)
39216 * 255 = 10,000,080 This is the largest number, so it fits easily in 31-bits.
Then in the very next statement divide by 1000 with the Div32
10,000,080 / 1000 = 10,000 integer
Granted with only 256 steps, accuracy is probably not very important, but it should do the job.
For more info on the Div32 operator, see page 33 in the PicBasic manual.
Another way to approach it might be to use the A/D convertor to read the Pot's position. This would increase the resolution to 10-bit or 1024 steps = 9.775 ohms per step.
Best regards,
Darrel




Bookmarks