;Stepper Motor control using the H-Bridge on Dragon12 ;Dragon12 board comes with TI's 754410 H-bridge driver which can be used to drive stepper motor and DC motor(Google for data sheet and study it) ;On Dragon12 , PORTB and PORTP are used to control BOTH 754410 chip and 7-seg LEDs ;WE CANNOT USE BOTH 7-SEG LEDs and 754410 AT THE SAME TIME. ;J24 (on left side of CPU) is used to provide power to 7-seg LEDs driver ;and J18 (at the bottom left side of the board by the buzzer) is used to provide power to H-bridge driver. ;ONLY ONE OF THEM SHOULD HAVE A JUMPER ;The Dragon12 is shipped with J24 (7-Seg LEDs) power enabled and nothing on J18. ;If you want to use H-Bridge you MUST move the jumper from J24 to J18. ONLY ONE OF THEM SHOULD HAVE A JUMPER ;Examine the outputs of the H-bridge at T4 Terminal block next to Reset button. They are M1,M2,M3 and M4 ;On Dragon12 the PP0 is connected to 12EN input pin of 754410. ;PB0 is connected to 1A and PB1 to 2A input pins of the 754410. That means M1 (1Y) and M2 (2Y) outputs are controlled by PB0,PB1 and PP0. ;Also the PP1 is connected to 34EN pin of 754410. ;PB2 is connected to 3A and PB3 to 4A input pins of the 754410. That means M3 (3Y) and M4 (4Y) outputs are controlled by PB2,PB3 and PP1. ;Steps to connect and run this program to control stepper motor ;1)Move jumper from J24 to J18 to power the 754410 chip ;2)Connect an external 5V-9V DC power to the COM leads of the stepper motor ;3)Connect Mx (M1,M2,M3, and M4 on T4 Terminal block) to the stepper motor leads as follow: ; M1 to blue, M2 to white, M3 to yellow, and M3 to red lead ;Now, power your Dragon12 board and ;Compile (F7), Download (F5) and run(F5), ;This program will rotate the stepper motor counter clockwise(CCW) continuously, ;Written and tested by M. Mazidi. ;for stepper motor control see chapter 15 of HCS12 book by Mazidi & Causey. ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dp256.inc' ;CPU used by Dragon12+ board ;----------------------USE $1000-$2FFF for Scratch Pad R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 ;code section ORG $4000 ;Flash ROM address for Dragon12+ Entry: LDS #$4000 ;Stack LDAA #$0F STAA DDRB ;Make PB0-PB3 output LDAA #$03 STAA DDRP ;Make PP0 and PP1 output STAA PTP ;Turn on both 12EN and 34EN pins of 754410 chip ; ;-------send bits to PORTB to turn stepper motor counter clockwise BACK LDAA #$03 STAA PORTB JSR DELAY LDAA #$06 STAA PORTB JSR DELAY LDAA #$0C STAA PORTB JSR DELAY LDAA #$09 STAA PORTB JSR DELAY BRA BACK ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #10 ;Change this value to see STAA R3 ;how fast stepper motor moves ;--10 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board ;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz). ;(1/24MHz) x 10 Clk x240x100=10 msec. Overheads are excluded in this calculation. L3 LDAA #100 STAA R2 L2 LDAA #240 STAA R1 L1 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R1 ;4 BNE L1 ;3 DEC R2 ;Total Instr.Clk=10 BNE L2 DEC R3 BNE L3 ;-------------- PULA ;Restore Reg A RTS ;------------------- ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000