1. Trang chủ
  2. » Luận Văn - Báo Cáo

project subject encoder motor speed control by pid

32 0 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Here''''s an explanation of each term: Proportional P Term: The proportional term is based on the current error, which is the difference between the desired setpoint and the actual output..

Trang 1

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

PROJECT

Microprocessor (HMI) ME4162

Subject: Encoder motor speed control by PID Group 15

Students ID Class/Year Jobs

Phan Anh Vũ

Nguy n Duy Th o ễả

Bùi Gia Hi u ế

20206097 20206089 20208002

CĐT02-K65 CĐT02-K65 CĐT01-K65

Code, report

Hardware setup, content prepares

Code, material prepares

Instructure: TS Dương Văn Lạc HÀ N I, 01/2022

Trang 2

2

COURSE PROJECT EVALUATION

I EVALUATION CRITERIA 1) Report Book Score

- Content doenot meet the requirements

- Poor content - Poor presentatiomultiple typos

- The content is quitesketchy and limited - Limited presentation - Relatively many typos

- Clear layout - The content is quitcomplete, accurate - Relatively good presentation - Few typos

- The layout of the reportis clear

- Complete, accurate content

- Good presentation - There are full membersto coordinate the implementation

Self-assessment score: 8.5/10 Signature: ……… ……… ………

2) Product Score

- Not done - The producdoes not work

- Sketchy product, incomplete functionality - Poor aesthetics - Active products

- The product is relatively sketchy, and the functionalityis limited - Limited aesthetics - Active products

- The product is relatively complete, and the function is quite complete - Aesthetically pleasing products - The product workswell

- The product is quite complete, fully functional- Aesthetically pleasing products

- Reliable operation products

- There are full membersto coordinate the implementation

Self-assessment score: 8/10 Signature: ……… ……… ………

3) Project defense Score

- Not understanding,not answering questions correctly

- Answering questions is very limited

- Understanding anapplying learned swords is very limited

- Answering questions is limited - Understanding anapplying learned swords is limited

- Answers questionrelatively well - Understand and apply the learned swords relatively well

- Correct and completeanswers to all question- Understand and makegood use of the knowledge learned - Ability to analyze, evaluate, create II OFFICIAL RATING SCORE

Report Book Score

(10%) Product

Score ĐSP

(40%) Defense

Score *

(50%)

AVERAGE SCORE ĐKQ= 10%Đ +40%Đ +50%ĐBCSPBV

2 Nguyễn Duy Thảo 20206089

*Noted: ĐBV ≤ min {Đ , ĐBCSP}

Trang 4

4 Introduction

In the realm of mechatronics and embedded systems, the quest for precision and efficiency is a driving force behind innovation The intersection of hardware and software in this domain opens up avenues for students to delve into exciting projects that address real-world challenges One such project that encapsulates this spirit is the "Encoder Motor Speed Control by Atmega16."

At the heart of this project lies the Atmega16 microcontroller, a powerful and versatile component that serves as the brain orchestrating the intricate dance of an encoder motor Encoder motors are pivotal in various applications, from robotics to industrial automation, where precise control over speed and position is paramount The objective of this project is to develop a robust and efficient system that not only controls the speed of an encoder motor but does so with a high degree of accuracy

The utilization of Atmega16 brings to the forefront its capability to interface seamlessly with peripherals and sensors, making it an ideal choice for projects demanding precision control The integration of encoder feedback into the control loop enables real-time adjustments, ensuring that the motor responds promptly to changes in the desired speed

Throughout this essay, we will explore the intricacies of the project, from the theoretical foundations of motor control to the practical implementation of algorithms on the Atmega16 microcontroller The significance of encoder motors in various applications and the role of precise speed control will be discussed, shedding light on the project's relevance in the broader context of mechatronics

As we navigate through the technical details, it becomes evident that this project not only serves as a valuable learning experience for students in the field of electronics and robotics but also has the potential to contribute to advancements in automation and control systems By the end of this essay, readers will gain insights into the complexities of encoder motor speed control and the proficiency of Atmega16 in tackling such challenges, inspiring further exploration and innovation in the ever-evolving landscape of mechatronics

Trang 5

Hardware Info 1 Components:

Microprocessor Atmaga16: - 8-bit AVR RISC architecture - Modified Harvard architecture - 16 KB Flash program memory - 1 KB SRAM

- 512 Bytes EEPROM - Clock Speed: 0 to 16 MHz

- Timers/Counters: Two 8-bit and one 16-bit Timer/Counter units

- Interrupts: Supports internal and external interrupts

Buttons

Trang 6

6 LCD LM016M:

- 16x2 character LCD

- Alphanumeric characters and symbols - 5x8 dot matrix for each character - Parallel interface with microcontrollers - Requires several I/O pins

- Power: Operates on low voltage (usually 5V) - Compact and suitable for space-limited projects

Trang 7

Encoder Motor: 50RPM (12V) - Transmission ratio 171:1 - No-load current: 60mA

- Maximum current under load: 1.3A - No-load speed: 50RPM (50 rounds per minute) - Maximum speed under load: 27RPM (27 rounds per

minute)

- Rated pulling force Moment: 4KG.CM - Maximum Moment Force: 9KG.CM - Gearbox length L: 25mm

Trang 8

8 2 Circuit Diagram:

Fig2.1 Circuit diagram 3 PID Principle:

In this project, we use Atmega16 as a brain of the whole system and use 16MHz quartz PID (Proportional-Integral-Derivative) control is a widely used technique in control systems, including the speed control of DC motors In PID control, three terms are combined to create a control output that adjusts the system to achieve and maintain a desired setpoint Here's an explanation of each term:

Proportional (P) Term:

The proportional term is based on the current error, which is the difference between the desired setpoint and the actual output It produces an output that is proportional to the magnitude of the error

The proportional term helps the system respond to the current error, but it alone may result in steady-state error, where the system settles with a non-zero difference between the setpoint and the actual output

Trang 9

Mathematically, the proportional term (P) is given by:

Integral (I) Term:

The integral term addresses the accumulation of past errors over time It helps eliminate state error by integrating the error over time This term is useful for systems with inherent biases or offsets

steady-The integral term becomes significant when the system has been away from the setpoint for an extended period, accumulating a large integral value

Mathematically, the integral term (I) is given by:

Control Output:

The overall control output, often denoted as U(t), is the sum of the proportional, integral, and derivative terms

U(t)=P+I+D

determine the sensitivity of each term and need to be tuned to achieve the desired system response PID controller adjusts the motor input voltage (or current) to maintain the motor speed close to the desired setpoint The feedback signal often comes from a sensor, such as an encoder, providing information about the motor speed The PID controller continuously adjusts the motor input to minimize the difference between the setpoint and the actual speed

Trang 10

10

Software Programing

We implement a speed control system using a PID (Proportional-Integral-Derivative) controller on an ATmega16 microcontroller The system continuously monitors the encoder input, calculates the current speed, and adjusts the motor's PWM signal to maintain the desired speed The user can

alcd.h: This header file provides a set of functions and macros for interacting with an alphanumeric LCD, and it is meant to be included in other source files to enable LCD functionality in an embedded system

Trang 11

mega16_bits.h: bit definitions for the ATmega16 microcontroller These definitions are used to manipulate specific bits in the microcontroller's registers for various peripherals such as timers, interrupts, ADC, etc

stdarg.h: This file is used to define macros for accessing a variable number of arguments in functions like printf and scanf

stdbool.h: This file provides a boolean data type and the constants true and false

Trang 12

12 2 Main file:

This code is written to control the speed of a motor using a PID (Proportional-Integral-Derivative) controller Here's an overview of the code:

Header Section:

The code starts with a header section that provides information about the microcontroller, such as the chip type, program type, core clock frequency, memory model, external RAM size, and data stack size

Header Files: The necessary header files are included, such as <mega16.h> (for specific definitions), <delay.h> (for delay functions), <alcd.h> (for alphanumeric LCD functions), <stdbool.h> (for boolean type), <stdio.h>, <stdlib.h>, and <math.h>

ATmega16-Pin and Parameter Definitions:

Various macro definitions are used to define pins and parameters For example, pin definitions for up_sw, down_sw, start_sw, mode_sw, enable_pin, encoder_pin, encoder_revolution, gear_ratio, etc

Global Variables:

Global variables are declared to store various parameters and states, such as set_mode, run_mode, mode_press, start_press, speed_set, encoder, speed_target, output, error values, and PID coefficients (ki, kp, kd)

Interrupt Service Routines: External Interrupt (ext_int0_isr):

Triggered on external interrupt 0 (used for encoder input)

Detects the direction of encoder rotation (Clockwise or Counterclockwise) and updates the encoder variable accordingly

Timer 2 Overflow (timer2_ovf_isr): Triggered on Timer 2 overflow

Controls the main timing of the system, updating variables and triggering the PID controller periodically

Main Function:

Port Configuration: Configures the input/output ports of the microcontroller

Trang 13

Timer Configurations:

Initialization: Initializes LCD display and other peripherals Main Loop:

Infinite loop (while(1)) where the main control logic resides Setting Function:

PID Speed Computation and PWM Speed Output Functions:

The pid_speed_compute function computes the PID control output based on the current speed error, integral, and derivative terms

The pwm_speed_out function adjusts the PWM output to control the motor speed PID Computation Function (pid_speed_compute):

PID Algorithm: Computes the PID control output based on the error (difference between set speed and actual speed), integral of error, and derivative of error

PWM Output Function (pwm_speed_out):

PWM Mapping: Maps the PID control output to PWM signals for controlling the motor speed Main Loop:

adjust settings

PID Control Algorithm:

The PID gains (Kp, Ki, Kd) are set dynamically based on user-set values (kp_set, ki_set, kd_set) PWM Control:

The pwm_speed_out function adjusts the motor speed by mapping the PID control output to PWM EEPROM Usage:

Uses EEPROM to store and retrieve PID gains (ki, kp, kd) between program runs

Trang 14

14 Code pid_speed.c:

/******************************************************* Chip type: ATmega16

Program type: Application

AVR Core Clock frequency: 16.000000 MHz Memory model: Small

External RAM size: 0 Data Stack size: 256

*******************************************************/ #include <mega16.h>

#include <delay.h>

// Alphanumeric LCD functions #include <alcd.h>

#include <stdbool.h>

#include <stdio.h> #include <stdlib.h> #include <math.h>

#define up_sw PINB.0 #define down_sw PINB.1 #define start_sw PINB.2 #define mode_sw PINB.3

#define enable_pin PORTD.3 #define encoder_pin PIND.6 #define encoder_revolution 11 #define gear_ratio 171

// Declare your global variables here bool set_mode=false;

Trang 15

bool run_mode=false; bool mode_press,start_press; long speed_set;

float encoder; float speed_taget;

float output, errorValue,perrorValue,edot,error_integral ; long timer2;

int count; char str[17];

float ki_set,kp_set,kd_set; float rpm;

eeprom float ki,kp,kd; ////////////////// void setting();

void pid_speed_compute();

void pwm_speed_out(float pwm_value); // External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isr(void) {

// Place your code here

if (encoder_pin == 0) //CCW direction encoder=encoder- 1;

else //else, it is zero -> CW direction encoder=encoder+1;

}

// Timer 2 overflow interrupt service routine interrupt [TIM2_OVF] void timer2_ovf_isr(void) {

// Place your code here TCNT2=99;

Trang 16

16 if(run_mode){

timer2++;

if(timer2>=10){ count++; timer2=0;

pid_speed_compute(); pwm_speed_out(output); }

} }

void main(void) {

// Declare your local variables here

// Input/Output Ports initialization // Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=P Bit2=P Bit1=P Bit0=P

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (1<<PORTB3) | (1<<PORTB2) | (1<<PORTB1) | (1<<PORTB0);

Trang 17

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=Out Bit4=Out Bit3=out Bit2=In Bit1=In Bit0=In

DDRD=(0<<DDD7) | (0<<DDD6) | (1<<DDD5) | (1<<DDD4) | (1<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);

// State: Bit7=T Bit6=P Bit5=0 Bit4=0 Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (1<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

// Timer/Counter 2 initialization // Clock source: System Clock // Clock value: 15.625.000 kHz // Mode: Normal top=0xFF // OC0 output: Disconnected // Timer Period: 10 ms

TCCR2=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (1<<CS02) | (1<<CS01) | (1<<CS00);

TCNT2=99;

// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 16000.000 kHz // Mode: Fast PWM top=ICR1 // OC1A output: Non-Inverted PWM // OC1B output: Non-Inverted PWM

Ngày đăng: 17/06/2024, 17:07

Xem thêm: