Pot Calibration / BS2sx
Archiver
Posts: 46,084
Hello everybody,
I'm stuck.
I need to read 2 10k-potentiometer values (P0 and P1) using a LTC1098
DAC and calculate an output value(POut, 8 bit) to set a DS1267 digital
pot.
The whole setup mimics a conventional joystick axis.
If P0 reads "0" and P1 reads "255" I need the output to be 127.
("Idle" setting)
If one of P0 or P1 changes, the POut should change accordingly.
=> POut = (P0 +P1)/2 (one of the pots is always on Idle setting)
That works OK as long as I can make use of the whole Pot range.
Due to mechanical constraints I don't get the full range from 0 to 255
on P0 and P1, but s.th. like from 8 to 245 on P0 and 12 to 251 on P1.
How can I project the range of the input pots into full 8 bit?
Any help would be much appreciated.
I'm stuck.
I need to read 2 10k-potentiometer values (P0 and P1) using a LTC1098
DAC and calculate an output value(POut, 8 bit) to set a DS1267 digital
pot.
The whole setup mimics a conventional joystick axis.
If P0 reads "0" and P1 reads "255" I need the output to be 127.
("Idle" setting)
If one of P0 or P1 changes, the POut should change accordingly.
=> POut = (P0 +P1)/2 (one of the pots is always on Idle setting)
That works OK as long as I can make use of the whole Pot range.
Due to mechanical constraints I don't get the full range from 0 to 255
on P0 and P1, but s.th. like from 8 to 245 on P0 and 12 to 251 on P1.
How can I project the range of the input pots into full 8 bit?
Any help would be much appreciated.
Comments
>I'm stuck.
>I need to read 2 10k-potentiometer values (P0 and P1) using a LTC1098
>DAC and calculate an output value(POut, 8 bit) to set a DS1267 digital
>pot.
>The whole setup mimics a conventional joystick axis.
>
>If P0 reads "0" and P1 reads "255" I need the output to be 127.
>("Idle" setting)
>If one of P0 or P1 changes, the POut should change accordingly.
>
> => POut = (P0 +P1)/2 (one of the pots is always on Idle setting)
>
>That works OK as long as I can make use of the whole Pot range.
>Due to mechanical constraints I don't get the full range from 0 to 255
>on P0 and P1, but s.th. like from 8 to 245 on P0 and 12 to 251 on P1.
>
>How can I project the range of the input pots into full 8 bit?
>
>Any help would be much appreciated.
P0 span: 245-8 = 237
P1 span: 251-12 = 239
Convert to 0 to 255:
P0 = P0 - 8 */ 275
P1 = P1 - 12 */ 273
Pout = (P0 + P1)/2
Why */275 and */273? That is the stampese way of approximating
255/237 (=~275/256) and 255/239 (=~275/256). The division by 256 is
implied in the */ operator.
For better results (to lessen the roundoff error) I would probably use:
P0 = P0 min 8 - 8 */ 2754
P1 = P1 min 12 - 12 */ 2731
Pout = (P0 + P1+10)/20
The "min 8" protects the calibration in case suddenly the pot puts
out a 7 at the minimum, which would really throw off the computation
(division does not work on twos complement math). The 2754 and 2731
include one more significant digit in the approximation, e.g.,
255/237 * 10 = 2754/256. In the last step, the "+10" and "/20"
completes the round-off.
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
Your response saved my day, it works fine.
Again, thanks & have a nice day.
--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
> >Hello everybody,
> >I'm stuck.
> >I need to read 2 10k-potentiometer values (P0 and P1) using a
LTC1098
> >DAC and calculate an output value(POut, 8 bit) to set a DS1267
digital
> >pot.
> >The whole setup mimics a conventional joystick axis.
> >
> >If P0 reads "0" and P1 reads "255" I need the output to be 127.
> >("Idle" setting)
> >If one of P0 or P1 changes, the POut should change accordingly.
> >
> > => POut = (P0 +P1)/2 (one of the pots is always on Idle setting)
> >
> >That works OK as long as I can make use of the whole Pot range.
> >Due to mechanical constraints I don't get the full range from 0 to
255
> >on P0 and P1, but s.th. like from 8 to 245 on P0 and 12 to 251 on
P1.
> >
> >How can I project the range of the input pots into full 8 bit?
> >
> >Any help would be much appreciated.
>
>
>
>
>
> P0 span: 245-8 = 237
> P1 span: 251-12 = 239
>
> Convert to 0 to 255:
>
> P0 = P0 - 8 */ 275
> P1 = P1 - 12 */ 273
> Pout = (P0 + P1)/2
>
> Why */275 and */273? That is the stampese way of approximating
> 255/237 (=~275/256) and 255/239 (=~275/256). The division by 256 is
> implied in the */ operator.
>
> For better results (to lessen the roundoff error) I would probably
use:
>
> P0 = P0 min 8 - 8 */ 2754
> P1 = P1 min 12 - 12 */ 2731
> Pout = (P0 + P1+10)/20
>
> The "min 8" protects the calibration in case suddenly the pot puts
> out a 7 at the minimum, which would really throw off the computation
> (division does not work on twos complement math). The 2754 and 2731
> include one more significant digit in the approximation, e.g.,
> 255/237 * 10 = 2754/256. In the last step, the "+10" and "/20"
> completes the round-off.
>
> -- regards,
> Tracy Allen
> electronically monitored ecosystems
> mailto:tracy@e...
> http://www.emesystems.com