Saturday, March 23, 2013

PWM on Beaglebone- Interfacing of Servo Motor

The parallax boe bot comes with a continuous servo motor. To drive the motor, we required PWM output from the Beaglebone. The Beaglebone has three PWM modules, each with 2 outputs. Accessing the PWM modules is very easy. The tutorial found here gave us detailed step by step instructions on how to configure the PWM module.

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.

  1. Duty cycle of 1500us stops the motor
  2. Duty cycle of 1300us makes the motor rotate in one direction
  3. 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:
  1. Connect VCC, Ground and PWM output pin to appropriate leads of the motor
  2. Configure MUX settings, so that pin 29 outputs PWM wave
     echo 1 > /sys/kernel/debug/omap_mux/mcasp0_aclkx  
  3. Request EHRPWM0:0 from the OS
     echo 1 > /sys/class/pwm/ehrpwm.0:0/request  
  4. Set PWM frequency
     echo 50 > /sys/class/pwm/ehrpwm.0:0/period_freq  
  5. Set PWM duty cycle
     echo 1300000 > /sys/class/pwm/ehrpwm.0:0/duty_ns  
  6. 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

No comments:

Post a Comment