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.

PIC18f4431 PID loop implementation

Status
Not open for further replies.

dmta

Member level 2
Member level 2
Joined
Mar 25, 2013
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Earth
Visit site
Activity points
1,650
Hi all !!!!!

I want to implement a PID motor position controller in PIC18F4431. I read the motor position using a quadrature encoder and use the built in QEI to get the motor position. The PID loop is calculated every 0.52S inside the TIMER1 overflow ISR. This is my code (all variables are global).

How do I now convert this to PWM to drive the motor ?

Code:
void interrupt(){
	if(PIR1.TMR1IF==1){                   // every 0.52 seconds the PID O/P is calculated
          
        	  ERR_P1 = ERR_P2;            // get previous position error
	          ERR_P2 = SET_P - POS;       // calculate present position error
        	  ERR_AC = ERR_AC + ERR_P2;   // calculate accumilated error
	          PID_P  = (float)Kp*ERR_P2 + (float)Ki*ERR_AC*0.52 + (float)Kd*(ERR_P2-ERR_P1)/(0.52);
                    
        	  PIR1.TMR1IF = 0;
	}
}

BTW I am using a 360 pulses per revolution quadrature encoder and operating in the X4 mode of the QEI module i.e. when the shaft rotates 1 round (360°) the motor max value of "POS" will be 360×4-1=1439
 
Last edited:

Hi there,

I am also working with same topic but I need to do with analog controlling . I have a doubt in your pid loop... why ain't you considering speed of the motor in error calculation?
How did you get Kp, Ki and Kd values?
 

Hi Jinzpaul4u,

I didn't consider the speed because I am controlling the pisition of the motor and the Kp, Ki and Kd values I put as 1 as a test value. I have read that there are many ways of calculating these values eg-ziegler nichols method.

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top