PDA

View Full Version : PWM


rob
08-11-00, 06:33 PM
Here's some code I used to control eight robot limbs with the PWM output (4) and then PWM mode of the timer outputs (4). The only missing definition is : +BITS DUP &gt;R C@ OR R&gt; C! ;<p>( Actuator drivers for crabots Rob Chapman May 18, 1999 )<br>HEX<br>\ There are 8 actuators controlling 8 joints on four limbs. They are<br>\ referenced with respect to Front, Back, Left and Right, inner and<br>\ outer. For example, FRI would be the Front Right inner joint.<br>\ The four back joints are controlled by the four PWM outputs on<br>\ the 68HC12. The four front joints are controlled by four timer<br>\ outputs used with a fifth timer to create four PWM outputs.<br>\ The PWM outputs drive a darlington transistor which grounds the<br>\ actuator providing a path for current to flow through it.<br>\<br>\ Mapping of the joints to HC12 pins:<br>\ FLI - PT6<br>\ FRO - PT5<br>\ FRI - PT4<br>\ FLO - PT3<br>\ BLO - PP3<br>\ BLI - PP2<br>\ BRO - PP1<br>\ BRI - PP0<p>\ ==== Registers ====<br> 41 CONSTANT PWPOL \ PWM outputs<br> 42 CONSTANT PWEN \ PWN enables<br> 50 CONSTANT PWDTY0 \ duty cycle for channel 0<br> 51 CONSTANT PWDTY1 \ duty cycle for channel 1<br> 52 CONSTANT PWDTY2 \ duty cycle for channel 2<br> 53 CONSTANT PWDTY3 \ duty cycle for channel 3 <br> 56 CONSTANT PORTP \ port P outputs<br> 82 CONSTANT OC7M \ output compare 7 mask register<br> 83 CONSTANT OC7D \ output compare 7 data register<br> 96 CONSTANT TC3 \ timer 3 register<br> 98 CONSTANT TC4 \ timer 4 register<br> 9A CONSTANT TC5 \ timer 5 register<br> 9C CONSTANT TC6 \ timer 6 register<br> 9E CONSTANT TC7 \ timer 7 register<br> <br>\ PWM outputs<br>: BRI ( n -- ) PWDTY0 C! ; : BRO ( n -- ) PWDTY1 C! ;<br>: BLI ( n -- ) PWDTY2 C! ; : BLO ( n -- ) PWDTY3 C! ;<p>\ Timer PWM outputs<br>: FRI ( n -- ) TC4 C! ; : FRO ( n -- ) TC5 C! ;<br>: FLI ( n -- ) TC6 C! ; : FLO ( n -- ) TC3 C! ;<p>: INIT-ACTUATORS ( -- ) \ initialize timers and counters<br> \ PWM first<br> 0 PORTP C! \ set outputs to zero just in case they are used<br> F PWPOL C! \ set initial output as high<br> F PWEN C! \ enable the PWM outputs<br> \ timers next<br> F8 TIOS +BITS \ PT3-PT7 are output capture<br> FFFF TC7 ! \ set TC7 to just before zero<br> 78 OC7M C! \ control PT3-6 with output capture 7<br> 78 OC7D C! \ set to one when capture 7 matches<br> 2A TCTL1 C! 80 TCTL2 C! \ set to zero when capture 3-6 matches<br> 90 TSCR C! ; \ start the timer<p>: LB DUP BLI BLO ;<br>: RB DUP BRI BRO ;<br>: LF DUP FLI FLO ;<br>: RF DUP FRI FRO ;<br>: BK DUP LB RB ;<br>: FT DUP LF RF ;<br>: LT DUP LF LB ;<br>: RT DUP RF RB ;<br>: ALL DUP LT RT ;<p>: OFF 0 ALL ;<br>