Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PID algorithm for PIC18Fxxxx in C18

Status
Not open for further replies.

wael_sal

Newbie level 5
Joined
Mar 25, 2006
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,337
pid algorithm

Hi,
I trying to implement a PID algorithm in my code, I had referred to AN899 PID_main, yet the problem I am not familiar with assembly,
I need to use it for close loop speed control, is there any example code of PID inmlemented for PIC18F in C18?
I hope if any body familiar with PID routine to share his experience.

Best Regards
Wael
:?:
 

c18 float example

chanchal.chauhan said:
What type of control you are looking

Just go through the website. You will get some more information for PID control
https://www.picontrolsolutions.com/

Please give more details about your project than only anyone help you properly.

Regards
Chanchal


what the relation between the site you post and my question?
Regards
 

pid speed control algorithm

I have used a Pi controller for motor speed control using the Pic18f4431.
A Pi controller is usually enough for motor speed control.
Code space was not a probllem for me so I used float variables. One advantage with floats is you dont need to worry to much about overflow.
Tune the response by tweeking the float kCoeffs[] values.

In the init routine you set the 'Pi->Output' to your start up speed and then use that value to control the motor. IE:

PiCalc(&Pi);
pwm duty = (unsigned int)Pi->Output';

Code:
/*--------------------------------------------------------------------

  Title       : Header file for Pi controller. 
  Filename    : Pi.h
 
---------------------------------------------------------------------*/
 
 
/*--- Pi structure ---*/

typedef struct 
  {
  float Gain[2];    /* Pi gain values - Kp and Ki */
  float History[2]; /* Delay-line samples */
  float Output;     /* Pi Controller Output  */
  float Measured;   /* Measured Output sample */
  float Setpoint;   /* Reference Input sample */
  }PI;
   
/*--- Function prototypes ---*/

void PiInit(PI *Pi);
void PiCalc(PI *Pi);  
   
/*--- End of file ---*/


Code:
/*--------------------------------------------------------------------

  Title       : Pi controller. 
  Filename    : Pi.c
  
----------------------------------------------------------------------*/

#include "Pi.h"
  
/*--- Global variables ---*/

PI Pi;
float kCoeffs[] = {0.5, 0.2}; 
      
/*--- Program entry ---*/

void main(void)
  {
  PiInit(&Pi);
  
  Pi.Setpoint = 1.3;
  Pi.Measured = 1.25;
  
  for(;;){
    PiCalc(&Pi);
    }
  }
   
/*--- Initialise Pi ---*/

void PiInit(PI *Pi)
  {
  Pi->Gain[0] = kCoeffs[0];
  Pi->Gain[1] = kCoeffs[1];
  
  Pi->History[0] = 0.0;
  Pi->History[1] = 0.0;
      
  Pi->Output = 100.0;
  Pi->Setpoint = 0.0;
  Pi->Measured = 0.0;
  }
  
/*--- Calculate Pi ---*/  
  
void PiCalc(PI *Pi)
  {
  Pi->History[0] = Pi->Setpoint - Pi->Measured;
  Pi->History[1] += Pi->History[0];  
  Pi->Output += Pi->History[0] * Pi->Gain[0];    
  Pi->Output += Pi->History[1] * Pi->Gain[1];  
  }     
    
/*--- End of file ---*/
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top