The servo motor requires a PWM wave of 50Hz for proper operation. The speed and direction of rotation is controlled by the duty cycle of the PWM wave.
- Duty cycle of 1500us stops the motor
- Duty cycle of 1300us makes the motor rotate in one direction
- Duty cycle of 1700us makes the motor rotate in the other direction
The speed of rotation varies linearly as the duty cycle, i.e. a duty cycle of 1400us makes the motor rotate at half speed and so on. The speed remains constant if the duty cycle is reduced below 1300us or increased above 1700us.
We used the two outputs of EHRPWM0 (Enhanced High Resolution PWM) module to control the two servo motors of the bot. The PWM outputs are connected to pins 29 and 31 of header P9 on the Beaglebone. To interface the servo motor:
- Connect VCC, Ground and PWM output pin to appropriate leads of the motor
- Configure MUX settings, so that pin 29 outputs PWM wave
echo 1 > /sys/kernel/debug/omap_mux/mcasp0_aclkx
- Request EHRPWM0:0 from the OS
echo 1 > /sys/class/pwm/ehrpwm.0:0/request
- Set PWM frequency
echo 50 > /sys/class/pwm/ehrpwm.0:0/period_freq
- Set PWM duty cycle
echo 1300000 > /sys/class/pwm/ehrpwm.0:0/duty_ns
- Run
echo 1 > /sys/class/pwm/ehrpwm.0:0/run
These steps were followed to output PWM wave(period of 20ms and duty cycle of 1300us) from the terminal. The same was then converted into C program using file operations