0% found this document useful (0 votes)
43 views12 pages

Interfacing With DC Pololu Motor

- The document discusses how to measure the speed of a DC motor with a 131.25:1 gear ratio using an integrated quadrature encoder that provides 8400 counts per revolution of the gearbox output shaft. - The motor speed can be calculated by counting the rising and falling edges of the encoder outputs A and B over a set time period. - Formulas are provided to convert the encoder pulse count to motor speed in RPM based on the gear ratio and time measured. - Code examples are given to set the PWM duty cycle based on a target user input speed and to measure the current speed from the encoder pulse count.

Uploaded by

Yash Maharaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views12 pages

Interfacing With DC Pololu Motor

- The document discusses how to measure the speed of a DC motor with a 131.25:1 gear ratio using an integrated quadrature encoder that provides 8400 counts per revolution of the gearbox output shaft. - The motor speed can be calculated by counting the rising and falling edges of the encoder outputs A and B over a set time period. - Formulas are provided to convert the encoder pulse count to motor speed in RPM based on the gear ratio and time measured. - Code examples are given to set the PWM duty cycle based on a target user input speed and to measure the current speed from the encoder pulse count.

Uploaded by

Yash Maharaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Interfacing with DC Pololu motor

How to measure the current speed as


per gear ratio at no load?
Specifications
• https://www.pololu.com/product/1447
• Suppose, we have one 12V brushed gearmotor with a 131.25:1 metal gearbox.
• Located behind it is an integrated quadrature encoder that provides a resolution of 64 counts
per revolution of the motors shaft which corresponds to 8400 counts per revolution of the
gearbox’s output shaft.
• Key specs
• At 12V: 80RPM and 300mA free-run 250oz-in (18Kg-cm) and 5A stall.
• Encoder wiring and function

Color Function and connection


Red motor power (connects to one motor terminal)
Black motor power (connects to the other motor terminal)
Green encoder GND
Blue encoder Vcc (3.5 – 20 V)
Yellow encoder A output
White encoder B output (This wire was not used)
PIC 18F8722
Driver IC
Port C_2 CCP1-out

Port B_6

Port B_7

Controller
Speed:
• The speed can be measured by counting the rising and falling edges of the
outputs A and B. Using just a single edge of one channel results in 16
counts per revolution of the motor shaft, so the frequency of the A output
in the above oscilloscope capture is 16 times the motor rotation
frequency.
• After making the motor rotate, a program is required to measure the
speed of the motor. The speed of the motor can be measured by the
pulses. The encoder records the amount of high to low pulses and using
the formulas below converts the pulses into speed:
• To know the speed of the motor from the pulses…
𝑆𝑒𝑛𝑠𝑜𝑟 𝑝𝑢𝑙𝑠𝑒𝑠
SpeedMotor = × 60 𝑠𝑒𝑐𝑜𝑛𝑑𝑠
16𝑐𝑜𝑢𝑛𝑡𝑠 × 131(𝑔𝑒𝑎𝑟 𝑟𝑎𝑡𝑖𝑜)

• To calculate the required speed as per PWM

𝑆𝑒𝑡𝑆𝑝𝑒𝑒𝑑
setPWM = ×1023
𝑀𝑎𝑥𝑖 𝑅𝑃𝑀
Codes:
//To set the speed as per user input and PWM calculation accordingly.
motor_speed =userinput/max_rpm;
motor_speed=motor_speed*1023;

// PWM Configurations
setup_timer_2(T2_DIV_BY_1,255,1); // Set PWM frequency
setup_ccp1(CCP_PWM); // Configure CCP1 to PWM mode
set_pwm1_duty(motor_speed); // full speed

-------------

//To measure the current speed from the pulses received.


x = 2096; // 16 * 131
y = 60; //seconds – 1 min
speed = sensor_pulses/x;
// total pulses divided by gear ratio and multi by 1 min to get RPM
speed = speed*y; // Gives you the current speed in rpm.
Some useful Hints!
• Connect encoder output pin to external interrupt to
count the pulses
• Count pulses only for definite time, say 1 sec.
• To get per minutes, multiply by 60! (so easy)
• Say for example DC motor 1:131 gear ratio, how to
convert speed in rpm?
speed = (sensor_pulses/16.0); // Total Pulses divided by revolution count
speed1 = speed/131.0; // Sensor Pulses per Count divided by Gear Ratio
(1:131)
speed2 = speed1*60.0; // Converting Speed to per minute (rpm)
• User input speed into PWM conversion…
//Conversion of Duty Cycle Value
rpm = userinput/80; // Userinput divide by 80 (the max speed)
a = rpm*100;
rpm1 = (a*1023); // Motor Ratio multiplication with Maximum Duty
b = rpm1/100;
rpm2 = (int16)b; // Make whole Number
So setting of PWM based on user input speed..
set_pwm2_duty(rpm2);
• Write a logic program to follow the line.
• May use interrupt inputs to detect the line as per cases
given
• Draw circuit interface.
//motor pins
#define motorA_1 pin_F7 //motor on left
#define motorA_2 pin_F6
#define motorB_1 pin_F0 //motor on right
#define motorB_2 pin_F1
//IR pins
#define IR1 pin_J4 //Right Infra Red sensor
#define IR2 pin_J5 //middle Infra Red sensor
#define IR3 pin_J6 //left Infra Red sensor

//Infra-Red Function
int IR_sensor(){
if(!input(IR1)){ //if only IR on Right is low
return(1);
}
else if(!input(IR2)){ //if only IR in centre is low
return(2);
}
else if(!input(IR3)){ //if only IR on left is low
return(3);
}
}
void main()
{
forward(); //Robot to move Forward at 78% PWM

---some codes for obstacle detection and take action as per distance from obst.
switch (IR_sensor()) // Call IR detection function and check status)
{
case 1:
right(); // Take right
break;

case 2:
forward(); // Go forward
break;

case 3:
left(); // Take left
break;

default:
forward(); // by default forward
break;
}
}
//forward function
void forward() {
set_pwm1_duty(800L); //PWM for Motor B(right) @ 78%
set_pwm2_duty(800L); //PWM for Motor A(left) @ 78%
output_low(motorA_1); output_high(motorA_2); //Motor on left
output_low(motorB_1); output_high(motorB_2); //motor on right
}
Think!!!!
//stop function
void stop() { How to
set_pwm1_duty(0L); //PWM for Motor B(right) @ 0% take motor
set_pwm2_duty(0L); //PWM for Motor A(left) @ 0%
output_low(motorA_1); output_low(motorA_2); //Motor on left
reverse!
output_low(motorB_1); output_low(motorB_2); //Motor on right
}

void left() {
set_pwm1_duty(900L); //PWM for Motor B(right) @ 88%
set_pwm2_duty(0L); //PWM for Motor A(left) @ 0%
output_low(motorA_1); output_high(motorA_2); //Motor on left
output_low(motorB_1); output_high(motorB_2); //Motor on right
}

void right() {
set_pwm1_duty(0L); //PWM for Motor B(right) @ 0%
set_pwm2_duty(850L); //PWM for Motor A(left) @ 83%
output_low(motorA_1); output_high(motorA_2); //Motor on left
output_low(motorB_1); output_high(motorB_2); //Motor on right
}
Think logic to work with FIVE sensors’ inputs

You might also like