Professional Documents
Culture Documents
Faculty of Engineering
Discussion
Following code can be used to turn the stepper motor in clockwise direction.
void main() {
TRISC=0;
while(1){
PORTC = 0X01;
delay_us(900);
PORTC = 0X02;
delay_us(900);
PORTC = 0X04;
delay_us(900);
PORTC = 0X08;
delay_us(900);
}
In order to reverse the above stated direction of the stepper motor, the signal pattern of the bits
should be given in the opposite direction as below.
void main() {
TRISC=0;
while(1){
PORTC = 0X08;
delay_us(900);
PORTC = 0X04;
delay_us(900);
PORTC = 0X02;
delay_us(900);
PORTC = 0X01;
delay_us(900);
}
1
INTRODUTCTION TO CONTROLS AND ROBOTICS EC248
Servo motor is used to turn the motor in a desired angle using a PWM pulse.
90 0 +90 0 90
The above rotational pattern could be implemented to a servo motor using a PIC microcontroller
from the below code.
int i;
void main() {
TRISC=0;
while(1){
for(i=0; i<100; i++){
PORTC.RC0 = 1;
delay_us(750); //-90 Rotation
PORTC.RC0 = 0;
delay_us(19500);
}
2
INTRODUTCTION TO CONTROLS AND ROBOTICS EC248
= 20
1
=
1
=
20 103
= 50
As seen in the above code, the pulse width (time high) for the servo motor to turn at different
angles can be given as follows.
`
+90o
2500s
-90o
750s
1500s