CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Some problem to calculate this?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Some problem to calculate this?
PostPosted: Wed Dec 16, 2009 4:35 pm     Reply with quote

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








PostPosted: Wed Dec 16, 2009 6:15 pm     Reply with quote

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

View user's profile Send private message

Re: Some problem to calculate this?
PostPosted: Thu Dec 17, 2009 3:57 am     Reply with quote

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








PostPosted: Thu Dec 17, 2009 5:13 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group