Professional Documents
Culture Documents
Faculty of Engineering
Module Details
Module Code EC 2481 Module Title INTRODUCTION TO CONTROLS & ROBOTICS
Program: Name:
Stream: (Civil/Electronics/Mechanical)
Assessment details
All academic misconduct is considered seriously and defined as dishonest and in direct opposition to the values of a learning community.
Misconduct may result in penalties from failure to exclusion from the campus.
Further help and guidance on how to avoid academic misconduct can be obtained from your academic advisor/tutor]
Marks: [ All marks are subject to external moderation and approval of board of examinations]
INTRODUCTION
The objective of this experiment is to control servo and stepper motors using the
microcontroller.
APPARATUS
Stepper motor
Servo motor
ULN2003A
PicKit 2 Programmer and PC with Micro C Pro
DC Power Supply
Demonstration Board
Procedure
Observe the operation of the stepper motor and write a program code to change the rotational
direction of the motor.
void go_forward();
void go_backward();
unsigned int i;
void main() {
TRISB = 0x00; //Port B as output
go_forward();
go_backward();
}
void go_forward(){
for(i=0;i<10;i++){ //Repeat 10 rounds
PORTB = 0x01;
delay_ms(200); // slow down change pace a little
PORTB = 0x02;
delay_ms(200); // slow down change pace a little
PORTB = 0x04;
delay_ms(200); // slow down change pace a little
PORTB = 0x08;
delay_ms(200); // slow down change pace a little
}
}
void go_backward(){
for(i=0;i<10;i++){ //Repeat 10 rounds
PORTB = 0x08;
delay_ms(200); // slow down change pace a little
PORTB = 0x04;
delay_ms(200); // slow down change pace a little
PORTB = 0x02;
delay_ms(200); // slow down change pace a little
PORTB = 0x01;
delay_ms(200); // slow down change pace a little
}
}
The above graph indicate the Stepper motor sequence pattern. Reverse this sequence pattern,
then we can change the rotational direction of the motor.
PART 2: SERVO MOTOR CONTROL
Procedure
Servo Motor Wiring :
Red – Vcc
Brown – Ground
Orange/Yellow – PWM Signal
void main() {
PWM1_Start();
PWM1_Set_Duty(13); // 1ms pulse width for 5% duty cycle
Delay_ms(1500); //slow down change pace
PWM1_stop();
PWM1_Start();
PWM1_Set_Duty(19); //1.5ms pulse width for 7.5% duty cycle
Delay_ms(1500); //slow down change pace
PWM1_stop();
PWM1_Start();
PWM1_Set_Duty(26); //2ms pulse width for 10% duty cycle
Delay_ms(1500); //slow down change pace
PWM1_stop();
PWM1_Start();
PWM1_Set_Duty(19); // 1ms pulse width for 5% duty cycle
Delay_ms(1500); //slow down change pace
PWM1_stop();
What is the period and frequency of the pulse train needed to be sent to the servo motor to
control its position?
Period (T) = 20 ms
Frequency (f) = 50 Hz
What are the pulse width (time high) value needed to position the motor at the
𝑡
Duty cycle =
𝑇
-90 degree position
1ms
× 100 = 5%
20ms
0 degree position
1.5ms
× 100 = 7.5%
20ms