Digital PID: Interfacing the uC PIC18F and Matlab...Digital PID: Interfacing the uC PIC18F and...

Post on 09-Mar-2021

8 views 0 download

Transcript of Digital PID: Interfacing the uC PIC18F and Matlab...Digital PID: Interfacing the uC PIC18F and...

Digital PID: Interfacing the uC PIC18F and Matlab

Autores:

César Domingues

Rafael Mariano

Revisão:

Heitor Vinicius Mercaldi

Vilma A. Oliveira

Contents

1. System overview

2. Plant characteristics

3. Microcontroler algorithm

4. Development

5. Implementation of the algorithm in the

microcontroller

Lab. Controle de Sistemas

SEL-0328 14/10/2014

System overview

MICROCONTROLLER

POWER DRIVER

chopper PWM

MOTOR ENCODER

MICROCOMPUTER

RS-232

interface Feedback control system components

MATLAB

PIC18F

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Plant Characteristics

Encoder

Resolution 1024

DC Motor

Permanent Magnet

Voltage 12V

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Motor Transfer Function

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Controler Transfer Function

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Oficina Controladores PID

09/05/2014

Hardware

Conversor

RS232

PIC18F45K22

+5V 0V

Oscilator

8MHz

Encoder

PWM

Output

Motor

RESET

RC2

RC0 MCLR

RC7

RC6

OSC1

OSC2

VSS VDD

Kit PIC18F45K22

Plant

Power

Amplifier

Specific QEI Hardware

Motor supply

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Main Routine Begin

Waiting

Serial character from

MATLAB

Read serial

‘uart_rd’

Compute PID & set PWM

‘PWM1_set_duty(un)’

Send speed response

‘freq_txt’

‘a’

‘b’

Lab. Controle de Sistemas

SEL-0328 14/10/2014

PID &

PWM

Aquisition

points ?

Set reference

and registers

Compute PID output ‘un’

Read encoder counter

‘TMR1H and TMR1L’

and

Compute speed error ‘en = referencia – frequency’

PID timer

overflow ? Ts=1ms

Interrupt clear

Set PWM dutty = 0

Return

Compute PID & set PWM Sub-routine

Set duty cycle ‘PWM1_set_duty(un)’

‘>501’

‘<501’

‘No’

Running

encoder counter

‘Yes’

Increment points

counter

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Aquisition

points ?

Send to MATLAB

trought RS-232

‘uart1_write_text(freq

_txt)’

Send speed

response

Return

Send Speed response Sub-routine

‘>501’

‘<501’

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Lab. Controle de Sistemas

SEL-0328 14/10/2014

mikroC integrated development

environment (IDE)

Implementation of the Algorithm in the

Microcontroller

while(i<501){

frequency = frequency + (TMR1H * 256 + TMR1L);

frequency = frequency*1000;

frequencias[i] = frequency;

frequency = (frequency/1024)*2*pi;

en = referencia - frequency;

i++;

//Calculate the error by a difference equation

un = 0.007996*en - en1*0.01335 + en2*0.005612 + 0.1651*un1 + 0.8349*un2; //0.001

en2 = en1;

en1 = en;

un2 = un1;

un1 = un;

un = un*255;

un = (int)un;

//seta pwm

PWM1_set_duty(un);

}

//controller output : u(n-1) = un1 u(n-2) = un2

//erro : e(n-1) = en1 e(n-2) = en2

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Gravação

Lab. Controle de Sistemas

SEL-0328 14/10/2014

END

Thank you very much.

Lab. Controle de Sistemas

SEL-0328 14/10/2014