View previous topic :: View next topic |
Author |
Message |
Guest
|
Some problem to calculate this? |
Posted: Wed Dec 16, 2009 4:35 pm |
|
|
Some problem to calculate this?
The question is not on the PIC itself. But how to get the bit to follow the power on the output of my pot.
If pot is in minimum I want 32 bit, and then the bit must follow in most linearly way to the pot is in max, and then give me 288 bit.
Code: |
Gnd--res--Vcc
|
out
|
I supply the out to AD converter on my pic.
Vcc=5 Gnd=0 ADRef=0. That will be 0-255bit and then 0-5 volt in theory...
But how to make it like:
Situation_1: Pot-> min=32bit and max=288bit
Situation_2: Pot-> min=17bit and max=158bit
Situation_3: ...
I can't figure how to make the calculation... |
|
|
Guest
|
|
Posted: Wed Dec 16, 2009 6:15 pm |
|
|
Maybe I solved it:-)
Inspiration for other there want to make calculation on pwm!
Code: | int16 CalcPWM(int8 AD, int8 RP2){
const int8 MaxAD=250;
int8 pmin;
int16 pmax;
int16 Res;
if (AD>MaxAD){AD=MaxAD;}
pmax=0.90*4*(RP2+1);
pmin=0.10*4*(RP2+1);
Res=pmin+(AD*((pmax-pmin)/(float)MaxAD));
return (Res);
} |
|
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
Re: Some problem to calculate this? |
Posted: Thu Dec 17, 2009 3:57 am |
|
|
Anonymous wrote: | Some problem to calculate this?
The question is not on the PIC itself. But how to get the bit to follow the power on the output of my pot.
If pot is in minimum I want 32 bit, and then the bit must follow in most linearly way to the pot is in max, and then give me 288 bit.
Code: |
Gnd--res--Vcc
|
out
|
I supply the out to AD converter on my pic.
Vcc=5 Gnd=0 ADRef=0. That will be 0-255bit and then 0-5 volt in theory...
But how to make it like:
Situation_1: Pot-> min=32bit and max=288bit
Situation_2: Pot-> min=17bit and max=158bit
Situation_3: ...
I can't figure how to make the calculation... |
The reason no one is helping is because your question is missleading.
You have used the word bit after your values. You shouldn't have.
You basically want calculations to convert your A2D reading in to different ranges e.g.
Range 1: min = 32 to max = 288
Range 2: min = 17 to max = 158
Are you using 8bit, 10bit, 12bit or other resolution for your A2D e.g which PIC are you using and what are your settings for it ?
DEVICE= ? |
|
|
Guest
|
|
Posted: Thu Dec 17, 2009 5:13 am |
|
|
Hello
The problem is solved, I posted the above solution. It take some time about 1ms but dosen't matter because the duty is only set once! It run nice and work. Thanks @Wayne_
Maybe the explanation was bad. I use 8 bit cpu. And what I mean with _bit_ was only that the minimum and maximum read from my "pot" was. |
|
|
|