You are on page 1of 5

Title

Motor Position Control using a PID Controller

Abstract

Introduction

A control system monitors and regulates the behaviour of a plant by adjusting input parameters
to achieve a particular objective. The control system can operate in an opened or closed-loop;
however, the latter can ensure the desired goal is achieved by measuring the output parameter
that is being controlled. Electronics control systems are widely used in various industries;
therefore, engineering students need to develop the ability to conduct system modelling, system
analysis and controller design and analysis. These tasks can be implemented using state-of-the
art software such as MATLAB.

The purpose of the study is to:

 Define specifications for motor position control.


 Develop a mathematical model of a permanent magnet DC motor (PMDC motor).
 Implement DC motor position control system using a PID controller.
 Tune the PID controller parameters to achieve system control requirements.

Materials and method

The materials used in this experiment was:

 A computer with the MATLAB software

These materials will be used to

 To study Control Systems Design and Analysis

Results
LCD stop clock C program

#define F_CPU 8000000UL


#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "lcd.h"
#include <avr/interrupt.h>

volatile int count2=0;


volatile int count=0;
int i=0, j=0, k=0 ,l=0 ; // i-->milliseconds, j-->seconds, k-->minutes, l-->hours,
//unsigned char num = 216;
//unsigned char a = 7; //single digit
char str[2];
char str2[2];
char str3[2];
char str4[3];
int main(void)
{
DDRB=0xFF;
DDRD = 0xFF;
PORTD |= (1<<2);
GIMSK |= (1<<INT0);
GIMSK |= (1<<INT1);
MCUCR |= 0x0A;
OCR1A = 30;
TCCR1A = 0x00;
TCCR1B = 0x0C; //CTC mode, 256 prescaler
TIMSK = (1<<OCIE1A); //enable Timer1 compare match int.

sei();

lcd_init();

lcd_gotoxy(1,2);
itoa(l,str,10);
lcd_print("00");

lcd_gotoxy(4,2);
itoa(k,str2,10);
lcd_print("00");

lcd_gotoxy(8,2);
itoa(j,str3,10);
lcd_print("00");

lcd_gotoxy(12,2);
itoa(i,str4,10);
lcd_print("000");
while(1)
{
lcd_gotoxy(1, 2);
itoa(l/10, str, 10);
lcd_print(str);
itoa(l%10, str, 10);
lcd_print(str);

lcd_gotoxy(4,2);
itoa(k/10, str2, 10);
lcd_print(str2);
itoa(k%10, str2, 10);
lcd_print(str2);

lcd_gotoxy(8,2);
itoa(j/10, str3, 10);
lcd_print(str3);
itoa(j%10, str3, 10);
lcd_print(str3);

lcd_gotoxy(12,2);
itoa(i/10, str4, 10);
lcd_print(str4);
itoa(i%10, str4, 10);
lcd_print(str4);
}
}
ISR(INT0_vect){
if (!(PIND & (1<<2)))
{
count++;
if (count==2)
count=0;
_delay_ms(20);
}
}
ISR(INT1_vect){
if (!(PIND & (1<<3)))
{
i = 0;
j = 0;
k = 0;
l = 0;
count2++;
if (count2==2)
count2=0;
_delay_ms(20);
}

}
ISR(TIMER1_COMPA_vect){
if(count == 1) {
i++;
if (i == 1000){
j++;
i = 0;
}

if (j == 60){
k++;
j = 0;
}

if (k == 60){
l++;
k = 0;
}
if (l == 24)
{
l = 0;
k =0;
j =0 ;
i = 0;
}

if (count2 == 1){

lcd_gotoxy(1,2);
clear_lcd();

lcd_gotoxy(1, 2);
itoa((l=0), str, 10);
lcd_print("00");

lcd_gotoxy(4,2);
itoa((k=0), str2, 10);
lcd_print("00");

lcd_gotoxy(8,2);
itoa((j=0), str3, 10);
lcd_print("00");

lcd_gotoxy(12,2);
itoa((i=0), str4, 10);
lcd_print("000");
}
}
Discussion

In this code, there were 3 interrupts used; these were two external interrupts and a timer
interrupt. The two external interrupts (INT0 AND INT1) were used to program the debouncing
of a push button for different tasks on the stopclock. The timer interrupt
(TIMER1_COMPA_vect) was used in timing the stop clock.

INT0

When the button presses, it picks up the falling edge, and can start or stop the stop clock. The
program then waits for the button to be pressed again to start back the stop clock.

INT1

When the button presses, it picks up the falling edge, and resets the stop clock. This starts the
stop clock all over.

TIMER1(compare matching)

In compare mode a register called Output Compare Register is loaded with a value of choice and
the timer will compare the current value of timer with that of Output Compare Register
continuously and when they match it triggers an interrupt. The timer was configured to reset it
self to 0; this is called CTC - Clear Timer on Compare match. This is a 16 bits register, so a
prescaler was setup as prescribed. The output compare register used was OC1A (as
TIMER1_COMPA_vect was used) and it was configured to 30 timer cycles using the formula:

# timer cycles = ( (Delay/N(prescaler)) * frequency) – 1. , where the desired delay was 1


millisecond, the prescaler was 256, and the frequency was 8MHz.

This value was used to achieve the wanted delay that the stop clock should run at.

Literature cited

No literature cited.

You might also like