You are on page 1of 2

DefaultBall

put servo motors into default position by setting default PWMs:


defaultLat and defaultPow to the two motors

LoadBall
put latch servo motor into LoadBall posiotn by setting the LoadPWMLat to
it

ChargeBall
put power servo motor to ChargeBall position by setting ChargePWMPow to
it

FireBall
put latch servo motor to FireBall position by setting FirePWM to it

ResetBall
put power servo motor to ResetBall position by setting ResetPWMPow to it

InitServo
PB4(M0PWM2) is used to generate PWM (up-down counting)
start by enabling the clock to the PWM Module (PWM0)

enable the clock to Port B

Select the PWM clock as System Clock/32

make sure that the PWM module clock has gotten going

disable the PWM while initializing

program generators to go to 1 at rising compare A/B, 0 on falling compare


A/B
GenA_Normal = (PWM_0_GENA_ACTCMPAU_ONE | PWM_0_GENA_ACTCMPAD_ZERO )
GenB_Normal = (PWM_0_GENB_ACTCMPBU_ONE | PWM_0_GENB_ACTCMPBD_ZERO )

Set the PWM period. Since we are counting both up & down, we initialize
the load register to 1/2 the desired total period. We will also program
the match compare registers to 1/2 the desired high time

Set the initial Duty cycle on A to 50% by programming the compare value
to 1/2 the period to count up (or down). Technically, the value to
program
should be Period/2 - DesiredHighTime/2, but since the desired high time
is 1/2
the period, we can skip the subtract
init servo to have 50% duty cycle, possibly need to tune

Set the initial Duty cycle on B to 0%

enable the PWM outputs

now configure the Port B pins to be PWM outputs


start by selecting the alternate function for PB4

now choose to map PWM to those pins, this is a mux value of 4 that we
want to use for specifying the function on bit4 and bit5

Enable pins 4 on Port B for digital I/O

make pins 4 on Port B into outputs

set the up/down count mode, enable the PWM generator and make
both generator updates locally synchronized to zero count
End of InitServo

You might also like