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

PID Control HELP!!!

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



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

PID Control HELP!!!
PostPosted: Mon Aug 11, 2003 2:00 pm     Reply with quote

Me again: Just try to make it clearer so you know my question

I try to work on the PID control subroutine by using the adc to control a pressure valve. My question is, when I have an output from the PID control equation, I want to (convert) or mask the output to a range 0-500 which is the # of steps for stepper motor control. For example, if my output from PID is

0 = 0 step (if output = 0, 0 step [Minimum] )
.
.
.
40 = 500 steps (if output = 40, then 500 steps [Max])

What is the subroutine to convert the PID output to step #?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516897
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: PID Control HELP!!!
PostPosted: Mon Aug 11, 2003 4:19 pm     Reply with quote

A const array lookup table would work nicely for this. Just create a rom array with your 41 values in it.

:=Me again: Just try to make it clearer so you know my question
:=
:=I try to work on the PID control subroutine by using the adc to control a pressure valve. My question is, when I have an output from the PID control equation, I want to (convert) or mask the output to a range 0-500 which is the # of steps for stepper motor control. For example, if my output from PID is
:=
:=0 = 0 step (if output = 0, 0 step [Minimum] )
:=.
:=.
:=.
:=40 = 500 steps (if output = 40, then 500 steps [Max])
:=
:=What is the subroutine to convert the PID output to step #?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516901
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: PID Control HELP!!!
PostPosted: Mon Aug 11, 2003 4:26 pm     Reply with quote

<font face="Courier New" size=-1>:=Me again: Just try to make it clearer so you know my question
:=
:=I try to work on the PID control subroutine by using the adc to control a pressure valve. My question is, when I have an output from the PID control equation, I want to (convert) or mask the output to a range 0-500 which is the # of steps for stepper motor control. For example, if my output from PID is
:=
:=0 = 0 step (if output = 0, 0 step [Minimum] )
:=.
:=40 = 500 steps (if output = 40, then 500 steps [Max])
:=
:=What is the subroutine to convert the PID output to step #?
-------------------------------------------------------------

So, your goal is convert an input range of 0-40 to a
output range of 0-500 ? That requires multiplication.

To find the multiplication factor, do: 500/40 = 12.5

So you need to multiply your input value by 12.5, to get
your output value. Here is one way to do it:

<PRE>
char input; // 8-bit input value of 0-40
int16 temp; // Temporary varible
int16 output; // 16-bit output value of 0-500
<BR>
temp = (int16)input; // Put input into a 16-bit variable
<BR>
output = temp * 12; // Multiply input value by 12
output += (temp >> 1); // Then add half the input value (.5)
</PRE></font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516902
R.J.Hamlett
Guest







Re: PID Control HELP!!!
PostPosted: Tue Aug 12, 2003 2:26 am     Reply with quote

:=<font face="Courier New" size=-1>:=Me again: Just try to make it clearer so you know my question
:=:=
:=:=I try to work on the PID control subroutine by using the adc to control a pressure valve. My question is, when I have an output from the PID control equation, I want to (convert) or mask the output to a range 0-500 which is the # of steps for stepper motor control. For example, if my output from PID is
:=:=
:=:=0 = 0 step (if output = 0, 0 step [Minimum] )
:=:=.
:=:=40 = 500 steps (if output = 40, then 500 steps [Max])
:=:=
:=:=What is the subroutine to convert the PID output to step #?
:=-------------------------------------------------------------
:=
:=So, your goal is convert an input range of 0-40 to a
:=output range of 0-500 ? That requires multiplication.
:=
:=To find the multiplication factor, do: 500/40 = 12.5
:=
:=So you need to multiply your input value by 12.5, to get
:=your output value. Here is one way to do it:
:=
:=<PRE>
:=char input; // 8-bit input value of 0-40
:=int16 temp; // Temporary varible
:=int16 output; // 16-bit output value of 0-500
:=<BR>
:=temp = (int16)input; // Put input into a 16-bit variable
:=<BR>
:=output = temp * 12; // Multiply input value by 12
:=output += (temp >> 1); // Then add half the input value (.5)
:=</PRE></font>

I think, he actually wants 40-500, which gives a multiplication of 11.5*, and adding 40. The same basic code will work, as:

char input; // 8-bit input value of 0-40
int16 temp; // Temporary varible
int16 output; // 16-bit output value of 0-500
output = 40; // put in the 40 offset
temp = (int16)input; // Put input into a 16-bit variable
output += temp * 11; // Multiply input value by 11
output += (temp >> 1); // Then add half the input value (.5)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516913
Sherpa Doug
Guest







Re: PID Control HELP!!!
PostPosted: Tue Aug 12, 2003 6:47 am     Reply with quote

:=So, your goal is convert an input range of 0-40 to a
:=output range of 0-500 ? That requires multiplication.
:=
:=To find the multiplication factor, do: 500/40 = 12.5
:=
:=So you need to multiply your input value by 12.5, to get
:=your output value. Here is one way to do it:
:=
:=<PRE>
:=char input; // 8-bit input value of 0-40
:=int16 temp; // Temporary varible
:=int16 output; // 16-bit output value of 0-500
:=<BR>
:=temp = (int16)input; // Put input into a 16-bit variable
:=<BR>
:=output = temp * 12; // Multiply input value by 12
:=output += (temp >> 1); // Then add half the input value (.5)
:=</PRE></font>

For readabiltiy I would prefer to reduce 500/40 to 25/2.

output = (temp * 25) / 2 // Multiply input value by 25/2

I know my old ver 2.6x compiler would optimize this to a multiply by 25 and a shift. For anyone who has ever used Forth this should be obvious.

___________________________
This message was ported from CCS's old forum
Original Post ID: 144516917
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