Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Similar documents
RANGKAIAN LENGKAP. Universitas Sumatera Utara

Gambar A-1 Foto alat prototype infrared thermometer

LAMPIRAN A FOTO ALAT

LAMPIRAN. Program Keseluruhan Sistem Pengontrolan Level Air

LAMPIRAN. 1. Program Alat

// WRITE data to be written to EEPROM

Software Design Considerations, Narrative and Documentation

LAMPIRAN A. Universitas Sumatera Utara

LAMPIRAN A. Foto Alat

LAMPIRAN A PROGRAM UTAMA ROBOT NOMOR 2

Set of pulse decoding algorithms for quadrature rotary and linear encoders*

Lampiran I. Rangkaian Lengkap Alat. Universitas Sumatera Utara

LAMPIRAN A List Program CodeVision Generato Data...A-1 List Program CodeVision Multiplexer...A-11 List Program CodeVision Demultiplexer...

LAMPIRAN A. Listing Program. Program pada Borland Delphi 7.0 A-1 Program pada CodeVisionAVR C Compiler A-6

// Voltage Reference: AREF pin #define ADC_VREF_TYPE ((0<<REFS1) (0<<REFS0) (0<<ADLAR))

LAMPIRAN A FOTO Radio Control Helikopter dan Pengendalinya

LAMPIRAN - A. Instruksi Mikrokontroler

Universitas Sumatera Utara

8-bit Microcontroller. Application Note. AVR033: Getting Started with the CodeVisionAVR C Compiler

LAMPIRAN A FOTO ROBOT BERKAKI ENAM

8-bit Microcontroller. Application Note. AVR033: Getting Started with the CodeVisionAVR C Compiler

Project : Version : Date : 11/04/2016 Author : Freeware, for evaluation and non-commercial use only Company : Comments:

How2Use DT-AVR ATMEGA168 BMS. By: IE Team. Picture 1 The layout of DT-AVR ATMEGA168 BMS

LAMPIRAN A. Universitas Sumatera Utara

J. Basic. Appl. Sci. Res., 3(2s) , , TextRoad Publication

Lampiran. Universitas Sumatera Utara

LAMPIRAN A. I. Gambar alat percobaan I.1. Power supply. 1. Rangkaian sekunder 2. Dioda. 3. Heatsink 4. Power supply (keseluruhan)

LAMPIRAN A GAMBAR SISTEM

How2Use DT-AVR ATMEGA128L BMS. Oleh: IE Team. Picture 1 The layout of DT-AVR ATMEGA128L BMS

Serial Compact Flash Serial CF Card Module User Manual

Burglar Alarm Final Report

Automatic Gate Prototype Based on Microcontroller of Atmel ATMega16

W.E.S.L.E.Y. Waste Eliminating System for Lazy Engineering Youths. Final Report December 9, 2003 John Mercado

ECE477: Team 10 Software Design Considerations, Narrative, and Documentation

AN703. Micro64/128. Accessing the 36k of SRAM 12/3/04

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Embedded Systems and Software

Lampiran 1 Tabel data normalisasi lemari tabung LPG dari alat Konsentrasi Gas LPG Konsentrasi Gas

ATMega16 AVR AVR AVR DIP. (in-circiut programming) desktop MOSI MOSIT. AVRProg. header. (toggle)

Final Design Report. Team Name: No Rest for the Weary

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Embedded Systems Programming. ETEE 3285 Topic HW3: Coding, Compiling, Simulating

LAMPIRAN A LIST PROGRAM SERVER DAN CLIENT

Embedded Systems and Software

LAMPIRAN. Universitas Sumatera Utara

ET-BASE AVR ATmega64/128

// sets the position of cursor in row and column

Digital and Analogue Project Report

DT-ROBOT Line Follower

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Programming Microcontroller Assembly and C

12.1. Unit 12. Exceptions & Interrupts

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

ADC: Analog to Digital Conversion

Distributed Real-Time Control Systems. Chapter 10 Real-Time Digital Control

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Distributed Real- Time Control Systems. Lecture 7 Real- Time Control

Bachelor of Engineering in Computer and Electronic Engineering

TIMSK=0b ; /* enables the T/C0 overflow interrupt in the T/C interrupt mask register for */

Laboratory 4 Usage of timers

The Atmel ATmega328P Microcontroller

Getting Started With the Micro64

TekBots TM Oregon State University. mega User Guide

Topic 11: Interrupts ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

INTERRUPTS in microprocessor systems

WEATHER STATION WITH SERIAL COMMUNICATION

Microprocessors & Interfacing

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Use a semaphore to avoid the enqueue and dequeue functions from accessing and modifying count variable at the same time.

The Atmel ATmega168A Microcontroller

UBC104 Embedded Systems. Review: Introduction to Microcontrollers

SquareWear Programming Reference 1.0 Oct 10, 2012

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

Introduction to Embedded Systems

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

EE 354 Fall 2013 Lecture 9 The Sampling Process and Evaluation of Difference Equations

3. (a) Explain the steps involved in the Interfacing of an I/O device (b) Explain various methods of interfacing of I/O devices.

Laboratory 3 Working with the LCD shield and the interrupt system

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

CprE 288 Spring 2014 Homework 5 Due Fri. Feb. 21

Microcontroller basics

8051 Microcontroller

Arduino. (Digital-to-Analog Converter D/A D2A) (Digital to Analog Conversion) 3. (Analog to Digital conversion)

Timer 32. Last updated 8/7/18

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

CN310 Microprocessor Systems Design

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

PGT302 Embedded Software Technology. PGT302 Embedded Software Technology

Lecture (03) PIC16F84 (2)

Fundamental concept in computation Interrupt execution of a program to handle an event

21. PID control The theory of PID control

Microprocessors and Interfacng. Question bank

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

CHAPTER 1 GENERAL INFORMATION

ADC: Analog to Digital Conversion

Transcription:

AUTOMATIC CONTROL SYSTEMS Ali Karimpour Associate Professor Ferdowsi University of Mashhad Reference: Microcontroller Based Applied Digital Control Dogan Ibrahim, John Wiley & Sons Ltd, 2006

Liquid Level Digital Control System: A Case Study Topics to be covered include: Design of controller in time domain. 2

A typical liquid level control system 3

A typical liquid level control system Schematic of the system 4

System Model 5

Series Compensation Structure جبران سازي سري Ziegler-Nichols Design for PID Controller This procedure is only valid for open loop stable plants. Open-Loop Tuning Closed-Loop Tuning According to Ziegler and Nichols, the open-loop transfer function of a system can be approximated with time delay and single-order system, i.e. 6

Ziegler-Nichols Open-Loop Case طراحی زیگلر نیکولز حالت حلقه باز For open-loop tuning, we first find the plant parameters by applying a step input to the open-loop system. The plant parameters K, TD and T1 are then found from the result of the step test as shown in Figure. 7

Identification of System Model 5*200/256=3.906 v 2.5*3.906=9.76 v 200 8

Microcontroller program to send a step to D/A For program the Microcontroller we just need to: 1- Define PORTB as 200. 2- Enable DAC 3- Disable DAC That s all 9

Identification of System Model Gs is transfer function of tank+amplifier 10

Controller Design and Implementation 11 Controller Implementation s K K s e s u s D i p s K e s se K s su i p t K e dt t de K dt t du i p t K e T T t e t e K T T t u t u i p T t e K t e TK K T t u t u p i p 1 1 t e z K t e TK K t u z t u p i p 1 1 z TK K z e z u z D i p

Series Compensation Structure جبران سازي سري Continues block diagram Digital block diagram +z.o.h. 12

Sampling period Digital block diagram +z.o.h. First of all we need sampling period Time constant is 31 so we must consider T<3.1, we choose 0.1 13

System 14

Complete system 15

16

Microcontroller program to implement the controller Chip selection Project information Port configuration External interrupts LCD configuration ADC configuration Timers configuration Main program Controller output calculation Code WizardAVR Code WizardAVR Code WizardAVR Code WizardAVR Code WizardAVR Code WizardAVR Code WizardAVR By yourself By yourself 17

Chip selection Chip selection Tools Code WizardAVR Code WizardAVR 18

Project information /***************************************************** This program was produced by the CodeWizardAVR V2.05.0 Evaluation Automatic Program Generator Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Level Control Version : 1 Date : 2012/12/27 Author : Karimpour Company : Ferdowsi University of Mashhad Comments: This is a simple example for class. Chip type : ATmega16 Program type : Application AVR Core Clock frequency: 4.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ 19 #include <mega16.h>

Port configuration 20

Port configuration void mainvoid // Input/Output Ports initialization // Port A initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00; DDRA=0x00; // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=0 PORTC=0x00; DDRC=0x01; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; 21

External interrupt configuration // void External mainvoid Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isrvoid.. // Place External your Interrupts code here initialization // INT0: On // INT0 Mode: Low level // External Interrupt 1 service routine // INT1: On interrupt [EXT_INT1] void ext_int1_isrvoid // INT1 Mode: Low level // INT2: Off // Place your code here GICR =0xC0; MCUCR=0x00; MCUCSR=0x00; GIFR=0xC0; // Global enable interrupts #asm"sei 22

LCD configuration // Alphanumeric LCD Module functions #include <alcd.h> 23 void mainvoid.. // Alphanumeric LCD initialization // Connections specified in the // Project Configure C Compiler Libraries Alphanumeric LCD menu: // RS - PORTC Bit 1 // RD - PORTC Bit 2 // EN - PORTC Bit 3 // D4 - PORTC Bit 4 // D5 - PORTC Bit 5 // D6 - PORTC Bit 6 // D7 - PORTC Bit 7 // Characters/line: 16 lcd_init16; while 1 // Place your code here

ADC configuration #include <delay.h> void mainvoid #define ADC_VREF_TYPE 0x40... // Read ADC the initialization AD conversion result unsigned // ADC Clock char frequency: read_adcunsigned 125.000 char khz adc_input // ADC Voltage Reference: AVCC pin ADMUX=adc_input // ADC Auto Trigger Source: ADC_VREF_TYPE Free Running & 0xff; // ADMUX=ADC_VREF_TYPE Delay needed for the stabilization & 0xff; of the ADC input voltage delay_us10; ADCSRA=0xA5; // SFIOR&=0x1F; Start the AD conversion ADCSRA =0x40; while 1 // Wait for the AD conversion to complete while // Place ADCSRA your code & 0x10==0; here ADCSRA =0x10; return ADCH; 24

Timers configuration // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isrvoid // Place your code here void mainvoid // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 15.625 khz // Mode: Normal top=0xff // OC0 output: Disconnected TCCR0=0x04; TCNT0=0x00; OCR0=0x00; // Timers/Counters Interrupts initialization TIMSK=0x01; // Global enable interrupts #asm"sei" 25

Total Program from CodeWizardAVR #include <mega16.h> #include <delay.h> #include <alcd.h> interrupt [EXT_INT0] void ext_int0_isrvoid // Place your code here interrupt [EXT_INT1] void ext_int1_isrvoid // Place your code here // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isrvoid // Place your code here #define ADC_VREF_TYPE 0x40 unsigned int read_adcunsigned char adc_input ADMUX=adc_input ADC_VREF_TYPE & 0xff; delay_us10; ADCSRA =0x40; while ADCSRA & 0x10==0; ADCSRA =0x10; return ADCW; 26

Total Program from CodeWizardAVR void mainvoid // Declare your local variables here PORTA=0x00; DDRA=0x00; PORTB=0x00; DDRB=0xFF; PORTC=0x00; DDRC=0x01; PORTD=0x00; DDRD=0x00; TCCR0=0x04; TCNT0=0x00; OCR0=0x00; TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00; GICR =0xC0; MCUCR=0x00; MCUCSR=0x00; GIFR=0xC0; TIMSK=0x01; UCSRB=0x00; ACSR=0x80; SFIOR=0x00; ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA5; SFIOR&=0x1F; SPCR=0x00; TWCR=0x00; lcd_init16; // Global enable interrupts #asm"sei" while 1 // Place your code here 27

// Reinitialize Timer 0 value TCNT0=0x64; time_set++; if time_set ==10 time_set = 0; yk // Controller = read_adc0; update must be here yk = yk *5000 / 1024; // convert ADC ek=ref-yk; uk = pk_1+kp+ki*ti* ek; uk = uk * 256/5000 ; if uk >255 uk_im = 255; else uk_im = unsigned char uk ; PORTB = uk_im ; PORTC.0 = 1 ; // write to D/A converter PORTC.0 = 0 ; pk_1 = uk-kp*ek ; u t u t T K e t T K TK e t p p Setting Timer i 28 // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isrvoid // Place your code here void Ts=0.1 mainvoid // Timer Timer/Counter counts 256 0 cycle. initialization // Clock source: System Clock // Clock Clock of value: timer 15.625 is 15625 khz Hz. // Mode: Normal top=0xff // Every OC0 156 output: counts Disconnected = 0.01 Sec. TCCR0=0x04; So 10 times of counter = 0.1 Sec. TCNT0=0x64; TCNT0=0x00; OCR0=0x00; So 256-100=156. // Start Timers/Counters of timer is 100 or Interrupts 0x64 in hex initialization TIMSK=0x01; // Global enable interrupts #asm"sei"

External interrupt program // External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isrvoid // ref++; Place your code here itoaref,ch; lcd_clear; lcd_putsch; // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isrvoid // ref--; Place your code here itoaref,ch; lcd_clear; lcd_putsch; 29

Parameter Definition and Initial Values #include <stdlib.h> unsigned int time_set = 0; int ref= 2280; float kp, ki, pk_1,ek,yk, uk, T; unsigned char uk_im ; char ch[20];. kp =279.0; T= 0.1 ; ki=42.3; pk_1 = 0; PORTC.0 = 0 ; // disable write D/A itoaref,ch; lcd_putsch;while 1 // Place your code here 30

Total Program of System /***************************************************** This program was produced by the CodeWizardAVR V2.05.0 Evaluation Automatic Program Generator Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Level Control Version : 1 Date : 2012/12/30 Author : Freeware, for evaluation and non-commercial use only Company : Ferdowsi University of Mashhad Comments: This is a simple example for lecture#16. Chip type : ATmega16 Program type : Application AVR Core Clock frequency: 4.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ 31

Total Program of System #include <mega16.h> #include <delay.h> #include <alcd.h> #include <stdlib.h> unsigned int time_set = 0; int ref= 2280; float kp, ki, pk_1,ek,yk, uk, T; unsigned char uk_im ; char ch[20]; // Alphanumeric LCD Module functions #define ADC_VREF_TYPE 0x40 // Read the AD conversion result unsigned int read_adcunsigned char adc_input ADMUX=adc_input ADC_VREF_TYPE & 0xff; // Delay needed for the stabilization of the ADC input voltage delay_us10; // Start the AD conversion ADCSRA =0x40; // Wait for the AD conversion to complete while ADCSRA & 0x10==0; ADCSRA =0x10; return ADCW; 32

Total Program of System // External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isrvoid // Place your code here ref--; itoaref,ch; lcd_clear; lcd_putsch; // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isrvoid // Place your code here ref++; itoaref,ch; lcd_clear; lcd_putsch; // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isrvoid // Reinitialize Timer 0 value TCNT0=0x64; time_set++; if time_set ==10 time_set = 0; yk = read_adc0; yk = yk *5000 / 1024; // convert ADC ek=ref-yk; uk = pk_1+kp+ki*t* ek; uk = uk * 256/5000 ; if uk >255 uk_im = 255; else uk_im = unsigned char uk ; PORTB = uk_im ; PORTC.0 = 1 ; PORTC.0 = 0 ; pk_1 = uk-kp*ek ; // write to D/A converter 33

Total Program of System void mainvoid // Input/Output Ports initialization // Port A initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00; DDRA=0x00; // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=0 PORTC=0x00; DDRC=0x01; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; 34

Total Program of System // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 15.625 khz // Mode: Normal top=0xff // OC0 output: Disconnected TCCR0=0x04; TCNT0=0x00; OCR0=0x00; // External Interrupts initialization // INT0: On // INT0 Mode: Low level // INT1: On // INT1 Mode: Low level // INT2: Off GICR =0xC0; MCUCR=0x00; MCUCSR=0x00; GIFR=0xC0; // Timers/Counters Interrupts initialization TIMSK=0x01; // ADC initialization // ADC Clock frequency: 125.000 khz // ADC Voltage Reference: AVCC pin // ADC Auto Trigger Source: Free Running ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA5; SFIOR&=0x1F; // Alphanumeric LCD initialization // Connections specified in the // Project Configure C Compiler Libraries Alphanumeric LCD menu: // RS - PORTC Bit 1 // RD - PORTC Bit 2 // EN - PORTC Bit 3 // D4 - PORTC Bit 4 // D5 - PORTC Bit 5 // D6 - PORTC Bit 6 // D7 - PORTC Bit 7 // Characters/line: 16 lcd_init16; 35

Total Program of System // Global enable interrupts #asm"sei" kp =279.0; T= 0.1 ; ki=42.3; pk_1 = 0; PORTC.0 = 0 ; // disable write D/A itoaref,ch; lcd_putsch; while 1 // Place your code here 36