User manual
Robotics experiment with PIC microcontroller l 55
For Robo-PICA, we prepare the speed control with PWM technique via soft-
ware by the motor.h library file. You can see detail in motor.h sourcecode in Listing 4-1
(in this chapter). motor.h library has PWM function for supporting 2 PWM modules of
PIC16F887 as follows :
Pwm1_Change_Duty(speed); // Motor A Duty
Pwm2_Change_Duty(speed); // Motor B Duty
You can put the required duty cycle value in (speed). The range is 0 to 255 for 0
to 100% duty cycle.
A4.1 Write the Listing A4-1. Compile and download the code to Robo-PICA. Turn-off
power switch.
A4.2 Remove the downlaod cable from Robo-PICA.
A4.3 Place the robot on the floor. Turn-on power to run the program. See the operation.
The Robo-PICA robot will move forward fastest in 2 seconds and spin left
5 second. After that the robot will move foraward with fastest speed again. The robot
will move this routine all times.
Listing A4-1 : The speed control program for Robo-PICA by using PWM.
#include <motor.h>
char i;
void main()
{
Forward(255); // Motor Forward
while(1)
{
Delay_ms(2000);
Pwm1_Change_Duty(220); // Motor A 85% Duty
Pwm2_Change_Duty(255); // Motor B 100% Duty
Delay_ms(5000);
Pwm1_Change_Duty(255); // Motor A 100% Duty
}
}
E
The suitable PWM duty cycle value for driving the robot is more than 70%.
If select the less value, the robot has not torque more enough for turning
or rotation.
INNOVATIVE EXPERIMENT