15
Digital PID: Interfacing the uC PIC18F and Matlab Autores: César Domingues Rafael Mariano Revisão: Heitor Vinicius Mercaldi Vilma A. Oliveira

Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Digital PID: Interfacing the uC PIC18F and Matlab

Autores:

César Domingues

Rafael Mariano

Revisão:

Heitor Vinicius Mercaldi

Vilma A. Oliveira

Page 2: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 3: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 4: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Plant Characteristics

Encoder

Resolution 1024

DC Motor

Permanent Magnet

Voltage 12V

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Page 5: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Motor Transfer Function

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Page 6: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Controler Transfer Function

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Page 7: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 8: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Specific QEI Hardware

Motor supply

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Page 9: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 10: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 11: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 12: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Lab. Controle de Sistemas

SEL-0328 14/10/2014

mikroC integrated development

environment (IDE)

Page 13: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

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

Page 14: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

Gravação

Lab. Controle de Sistemas

SEL-0328 14/10/2014

Page 15: Digital PID: Interfacing the uC PIC18F and Matlab · PIC18F Lab. Controle de Sistemas SEL-0328 14/10/2014 . Plant Characteristics Permanent Encoder Resolution 1024 DC Motor Magnet

END

Thank you very much.

Lab. Controle de Sistemas

SEL-0328 14/10/2014