We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello Everyone, with the help of codes found in the net, I have written these codes for controlling pressure in a pneumatic system.The pressure sensor has the range 2.5-4.5 volts. The set point is 3.5 volts. [CODE] #include <stdio.h> #include <reg167.h> // **************** GLOBAL VARIABLES AND CONSTANTS ************************** // for sensors int sensorValue ; // for PID control int output ; float currentError=0; float setPoint=512 ; #define maxValue 1023 #define minValue 0 //ISR address #define INT 0x3F //**************** FUNCTION PROTOTYPES ************************* // General function void Initialize(void); // control function void PID(float); // A/D converter void AToDInitialize(void); unsigned int ReadSensor(unsigned int); // Interrupt routine void Interrupt(void); // ********************* MAIN PROGRAM ****************************** void main(void) { // ALWAYS DO THIS FIRST! Initialize(); while(1) ; } // *************************** FUNCTION DEFINITIONS ************************* // Function: Initialize // Purpose: Avoid floating pins by setting all of them to GND. // Input conditions: None // Arguments: None // Return value(s): None // Destroys: ALL REGISTERS - DPx and Px! void Initialize(void) { P3 |= 0x0400; //set port 3.10 output latch (TXD) DP3 |= 0x0400; // configure port 3.10 for output // Initialize Analog/Digital AToDInitialize(); // GLOBALLY ENABLE INTERRUPTS IEN = 1; } // Function: PID // Purpose: controller for driving the actuator // Input conditions: None // Arguments: Kp, Kd, Ki // Return value(s): None // Destroys: None void PID(float currentError) { static float oldError = 0 ; static float integralError = 0; int temp ; static float Kp = 1.2; static float Ki = 9.5; static float Kd = 0.05; // Accumulate error for integral control integralError += currentError; temp=(currentError) * Kp + (currentError - oldError)* Kd+Ki * integralError ; // Sanity checks if(output + temp > minValue) output = minValue ; else if(output + temp < maxValue) output = maxValue; else output += temp ; //P3.10=output; // Update your error oldError = currentError ; } /************* Sensor functions - AToD module *******************/ // Function: AToDInitialize // Purpose: Initialize AToD converter module // Input conditions: None // Arguments: None // Return values: None // Destroys: ADCON void AToDInitialize(void) { ADCON = 0x0000; // ADM = 0x00, fixed channel SINGLE conversion } // Function: ReadSensor // Purpose: Reads a sensor value from the specified analog input port (Port P5_0 to P5_15). // Input conditions: None // Arguments: input analog port to be read (0 to 15) // Return values: converted digital value // Destroys: no registers are destroyed unsigned int ReadSensor(unsigned int port_no) { ADCON = (ADCON & 0xFFF0) | port_no; ADST = 1; // start conversion while(ADBSY) // wait for conversion ; ADCIR = 0; // stop it return (ADDAT & 0x0FFF); } //************ INTERRUPT ROUTINE ******* void Interrupt(void) interrupt INT { sensorValue=ReadSensor(0); currentError=setPoint-sensorValue; PID(currentError) ; } [/CODE] As you can see 'output' is the output of PID contrller. I have set 3.10 port as output. How can I associate it with the output from the PID function? Thanks
How can I set the period? Using a timer (interrupt) Erik
Ok Erik, thanks. I have used timer interrupt. I used this: T3 = 0x9E58; What does it mean?what is overflow? Thanks
I have written these codes for controlling pressure in a pneumatic system.The pressure sensor has the range 2.5-4.5 volts. The set point is 3.5 volts. I have used timer interrupt. I used this: T3 = 0x9E58; What does it mean?what is overflow? STOP! without even a rudimentary knowledge of the '51 DO NOT make anything for "controlling pressure in a pneumatic system" Find some basic stuff to get the experience with then, after a while, you may be capable of the above without blowing the whole darn thing up. Erik
"without even a rudimentary knowledge of the '51 DO NOT make anything for "controlling pressure in a pneumatic system"" Same applies for '166, etc
Anup Saha asked: "Why do not you people try to give solution in a straight forward manner?" Well, arrogant as I may be, I think this thread is a perfect illustration of the fallacy of just handing out blobs of code. Anuraag Gunjan has now admitted at least twice to writing stuff with no understanding at all of what he's doing: "I have written this Function ... PWMCON0 = 0x0000; ... I do not know how PWMCON0 is set..." "I used this: T3 = 0x9E58; What does it mean? what is overflow?" This clearly demonstrates, I think, that simply dumping code on him has not actually helped him at all. Providing links to datasheets and other instructive materials gives the opportunity to gain the necessary understanding to make effective use of sample code - but it is up to the student to take that opportunity and gain the understanding. Understanding cannot be transferred simply by posting sample code!
So, Mr. Neil what Mr. Anup said about you is absolutely true.And the other accomplice Mr.Erik is no less than you.Poor you!Pundits are increasing in numbers day by day!If you do not want to reply just shut up! As I said in my posting, I have used the codes I found in net.So, what is your problem? There is no english book on C167.And many of this forum have given some links regarding the codes of c167.So, what is wrong if I ask when I can not make it out? Instead of telling the answer, you are railing at me,ridiculous!! Thank you Dr. Neil and Dr. Erik.Continue it,at least do something, do not keep your brains idle!
Mr.Neil, Stop please.Do you think that you are a Pundit? "A little learning is a dangerous thing". YOU are simply a gadfly!! Sorry, but you are unbearable. I think Mr.Anup Saha was correct about you.
"Do you think that you are a Pundit?" According to the Cambridge English Dictionary, "pundit; noun [C]: a person who knows a lot about a particular subject and is therefore often asked to give an opinion about it" http://dictionary.cambridge.org/define.asp?key=64201&dict=CALD
Oh, good grief. Anuraag Gunjan, Anup Saha, and most recently Pavan Mushunri (could you all be one-in-the-same?), with such a fundamental lack of knowledge about the platform you are dealing with, you need to get a grip on reality. You have presumably qualified folks giving you advice, arrogant or not is immaterial. As advised, take to heart all of the guidance you've been given and instead of grousing about it, execute it! After which, you'll never have to ask a question here again!
Thanks Dan, right answer! It is not the finest way, how some people use this forum. At my point of view, Dr. A. Neil and M. Kleshov are really the most helpfull persons at this forum , I have seen. Deep knowledge behind and always an idea how to solve a problem. But I allways tried to understand the points and to adapt to my specific problems, which seems hard stuff for some other people. By the way - thanks to all other people here, which gave me hints and help. And know let us finish this one, and enjoy the forum like before. Stefan
Oh, the crying and stamping of feet that happen when you do not give a baby exactly what it wants. Any similarity here? Erik
Why will you not take the time to understand what you are dealing with in, at least, the must basic way before you venture out and start controlling potentially dangerous stuff. codes found in the net and the thread is titled "My program" Please advise where you are going to apply "your code" to the pneumatic system so I can stay at least 1000 miles away. Erik
Erik, Ha ha. You are more than 1000 miles away--the name of that place (where you live) is HELL!!!lol. Ok, Erik, I am trying to understand.I am new in this business, and that is why asking your help..do not be so rude please--I know my questions are elimentary--but you know I have to start from somewhere. Do not worry, my system is alright and will be alright--I have the willingness to learn--but please answer even if it is elimentary. You know,there is no book from where I can learn well.I hope you understood me. Ciao
"the name of that place (where you live) is HELL!!!lol." What on earth is this moron raving about? Stefan