;Controlling Servo Motor with PWM (pulse width modulation) on Dragon12 Plus Trainer Board ;On Dragon12 board we have connections for four servo motors. They are located at the top middle of the board ;They are designated as PP4, PP5, PP6, and PP7. Next to them is the blue terminal block (T7) for external power connection for servo motors ;Next to the blue terminal block (T7) is the jumper to select power source for servo motor (SERVO_PWR J35) ;We can use on-board power or bring in an external power source for the servo motor. ;Depending on the size of the servo motor you might have to connect the blue T7 terminal block to external power (5-6V) . ;and set the SERVO_PWR jumper J35 to right (EXT). If you use on-board power set the jumper J35 to left. ;The servo motros have 3 leads. They are Black (ground), Red(power) and White for PWM control pulse. ;See http://www.parallax.com/Store/Robots/AllRobots/tabid/755/CategoryID/2/List/0/SortField/0/Level/a/ProductID/488/Default.aspx ;On Dragon12 board the PP4 has 3 pins. The left one is for PWM motor control, the middle one is the power, and the right one is for ground. ;The same is true for the other three servo motro connections of PP5,PP6 and PP7 ;So when you connect a servo motor to PP4 (or PP5, or PP6,..) make sure the white lead of the servo motor is on the left connection. ;This program uses the PWM of chan 4 (PP4) to control servo motor. ;Modified from Example 17-13 Mazidi & Causey HCS12 book. See Chapter 17 for PWM discussion ;Written and tested by M. Mazidi ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dp256.inc' ;CPU used by Dragon12+ board ;code section ORG $4000 ;Flash ROM address for Dragon12+ Entry: LDS #$4000 ;Stack MOVB #$04, PWMPRCLK ;ClockA=Fbus/2**4=24MHz/16=1.5MHz MOVB #125, PWMSCLA ;ClockSA=1.5MHz/2x125=1.5Mhz/250=6000Hz MOVB #$10, PWMCLK ;Use clockSA for chan 4 PWM MOVB #$10,PWMPOL ;High then low for polarity MOVB #$0,PWMCAE ;Left aligned MOVB #$0, PWMCTL ;8-bit chan,PWM during feeze and wait MOVB #100, PWMPER4 ;PWM_Freq=ClockSA/100=6000Hz/100=60 Hz. CHANGE THIS MOVB #50, PWMDTY4 ;50% duty cycle AND THIS TO SEE THE EFFECT ON SERVO MOTOR (TRY LESS THAN 10%) MOVB #0,PWMCNT4 ;Start the counter with zero (optional) BSET PWME,%00010000 ;Enable chan 4 PWM BRA $ ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000