The BeagleBone has 8 PWM outputs. These come from three EHRPWM modules (two output each) and two eCAP modules with one output each. To use the PWMs using BoneScriptUse analogWrite(pin,value,freq,callback) to set the PWM frequency and duty cycle. On the command line: - node -e "require('bonescript').analogWrite('P8_13', 0.870, 50, console.log);" or in Cloud9: - var b=require('bonescript'); - b.analogWrite('P8_13', 0.870, 50, console.log);" Works OOTB with pins: P8_13, P9_14, P9_21, P9_42 To use the PWMs from any other environmentThe first step is to enable the EHRPWM clocks. This can be done either by:
The first alternative is by far the easiest. Just do:
(I don't know how to enable the clocks for eCAP with this approach though, so you will only get 6 PWM outputs enabled) Controlling the PWM outputs can be done in user space, and is done the same way for both EHRPWM outputs and eCAP PWM outputs:
Wien you are done, release the port:
Note that the paired EHRPWMs share the frequency setting. I.e. ehrpwm.1:0 and ehrpwm.1:1 always have the same frequency. For one servo I have, I've measured the following min/max duty cycles for the given period frequency:
|
Using the BeagleBone >