Reply by Mike Elphick March 30, 20042004-03-30
Jackie,

Looks to me like you had two or more programs that worked separately and you
have stuck them together without realising that there are now three
instances of 'org CODE'. The assembler will have overwritten previous
'ORGed' sections of program and has left you with only the stepper motor
bit - hence the motor runs continuously. Even if you removed the duplicated
ORGs, it's not clear how the ADC value is being used to drive the motor.

Mike.
----- Original Message -----
From: Jackie Johnson
To:
Cc:
Sent: Thursday, March 25, 2004 9:38 PM
Subject: [68HC12] FW: Stepper Motors using the 68HC12 I have added a program that I a working on and am trying to get this
program to work properly. My motor is not stopping. Example: If I
want my motor to stop at 90 degrees with a 1.2498 voltage applied via
the POT (potentiometer). My motor is continually running and not
stopping based on my POT adjustments. Any ideas would be greatly
appreciated from a frustrated student, who is on Spring break and NOT in
Mexico!

I have added my program for your perusal. I want to operate in the
half-step mode.

THANKS,
Jackie

THANKS to the individual who brought to my attention that I can not
attach documents.
********************************************************
* This is a program showing the use
* of the A/D converter.
* The program will convert the voltage from
* the kit's potentiometer that is connected to
* the ADC's AN07 input pin.*
* The program stores the result at adr07h*
* The default for ATDCTL5: left justified data, unsigned,*
* single conversion sequence, one channel sample, channel AN0*
********************************************************
* Constant Equates
*A/D control and status registers
ATDCTL2 EQU $82
ATDCTL3 EQU $83
ATDCTL4 EQU $84
ATDCTL5 EQU $85

ATDSTAT0 EQU $86 ; A/D status register (SCF)
ATDSTAT1 EQU $87 ; A/D status register (CCF)
***************************************************************
*ADC Results Registers*

ADR0H EQU $90 ; 10 bit values take
ADR0L EQU $91 ; 2 bytes of storage
ADR1H EQU $92 ; Left justified have MSB
ADR1L EQU $93 ; in high byte, bits 1,0 are
ADR2H EQU $94 ; stored in b7,6 of low byte
ADR2L EQU $95 ;
ADR3H EQU $96 ; Right justified have LSB
ADR3L EQU $97 ; stored in low byte, bits 9,8
ADR4H EQU $98 ; stored in b1,0 of high byte.
ADR4L EQU $99 ;
ADR5H EQU $9A ; 8 bit values
ADR5L EQU $9B ; Left justified
ADR6H EQU $9C ; stored in high bytes.
ADR6L EQU $9D ; Right justified
ADR7H EQU $9E ; stored in low bytes
ADR7L EQU $9F ; of result registers.
***************************************************************
*ATDCL2 Register Control Bits*
*All bits are clear on reset*

ADPU EQU %10000000 ; A/D power up bit, Set to power
up
AFFC EQU %01000000 ; Set to Fast Clear all CCF
flags
AWAI EQU %00100000 ; Set to power down A/D in wait
mode
ETRIGE EQU %00000100 ; Set to Enable external trigger
ETRIGLE EQU %00010000 ; Set to Level Triggered (Clear
for Edge)
ETRIGP EQU %00001000 ; Set for Rising Edge or High
Level
ASCIE EQU %00000010 ; Set to enable ATD interrupt
ASCIF EQU %00000001 ; Set by ATD when interrupt
conversion complete
*If AFFC is cleared then the CCF flag is reset only when*
*ATDSTAT1 and the A/D results register(s) are read.*
*If AFFC is set then the SCF flag is reset only when*
*conversion sequence has completed and results read*
*ASCIF is read only
***************************************************************
*ATDCTL3 Register Control Bits

*SC EQU %0xxxx 000 ; # of conversions in sequence,
1 to 8 (4 bits)
FIFOATD EQU %00000100 ; Set to wrap around conversion
results
SC EQU %00001000 ; one conversion
***************************************************************
*ATDCL4 Register Control Bits
*Reset value is$05 (prescalar bits)*

SRES8 EQU %10000000 ; Resolution, Set = 8 bit
SMP EQU %01100000 ; SMP1 and SMP0 Sample Time Bits
*PRS EQU %000xxxxx ; PRS Clock Prescalar Bits
PRS EQU %00010111 ; PRS bits for this program

*default resolution is 10 bits*
***************************************************************
*ATDCL5 Register Control Bits*
*All bits are clear on reset*

JUSTIFY EQU %10000000 ; Set for right justification
SIGN EQU %01000000 ; Set for signed number
representation
SCAN EQU %00100000 ; Set for continuous conversions
MULT EQU %00010000 ; Set to sample multiple
channels
*AN EQU %00000xxx ; ATD Input Channel Number 0 to
7 (3 bit number)
AN EQU %00000111 ; Using channel 7 for this
program
***************************************************************
*ATD Status Register 0 (ATDSTAT0)*
*All bits are clear on reset*
*The values of these constants are AND'd with ATDSTAT0. If the
*result is non-zero, then the flag is set. If the result is zero then
*the flag was not set by the ATD*

SCF EQU %10000000 ; Sequence conversion Complete
Flag
ETORF EQU %00100000 ; Ext Trigger Overrun Flag
FIFOR EQU %00010000 ; FIFO Overrun Flag
*CC EQU %00000xxx ; 3 bit Conversion Counter (R
only)

*Writing a 1 to the SCF clears it*
*FIFO indicates a register has been overwritten before*
*it has been read.*
*CC points to the next register to be used by the ATD*
***************************************************************

*ATD Status Register 1 (ATDSTAT1)*
*All bits are clear on reset*
*CCF is used in a similar manner to the flags of ATDSTAT0

CCF EQU %11111111 ; Set by ATD for each results
register
*after it receives a value, if AFFC=0 reading ATDSTA1 and then*
*a results register clears a CCF flag for each individual results
register*
*All cleared by a write to ATDCTL5*
*If AFFC=1 a zero in a CCF bit indicates conversion number x has*
*not completed.*
***************************************************************
* Memory Map Equates
***************************************************************
;CODE EQU $1000
;DATA EQU $1050
;STACK EQU $3000 ; Remember that debug uses
memory.
;DDRB EQU $0003
;PORTB EQU $0001
*************************************************************** org CODE
lds #STACK
ldab #$FF ; Load B with %11111111
stab DDRB ; Makes portb an output port.
clrb ; Clears acc. B

; Power up the A/D

bset ATDCTL2 ADPU ; OR function, wakes up ADC.

; Generate a "short" delay > ? microsec to let ADC settle.

ldaa #$FF ; FF loops for.
short: nop ; 2 times FF loops
dbne a,short ; Decriment acc. A and branch to
delay.

; Now set up the A/D.
; Normal flag clearing, run in WAIT mode, no interrupts.

bclr ATDCTL2 AFFC|AWAI|ASCIE|ETRIGE ; Clrears all
the positions stated
; on the
ATDCLT2.
; Mask bits are inverted and AND'd with ATDCTL2.
; Any mask bit that is a '1' clears the corresponding bit in ATDCTL2.
Here we clear four bits.

bclr ATDCTL3 #$FF ; Clear all bits
bset ATDCTL3 SC ; 1 conversion needed for an7 ; The bus speed is 24 MHz. To obtain the slowest conversion time select
the longest sample time
; and an ATD conversion clock frequency of 500kHz. Sample time:
SMP1:SMP2 = 1:1
; PRS = 10111, gives ATD ccf of 500kHz Conversion time = 32uS.

bclr ATDCTL4 #$FF ; Clears ATDCLT4 and makes it
ready for bit setting.
bset ATDCTL4 #$60 ; Select 16 X sample time.
bset ATDCTL4 PRS ; Set PRS, Divide 24 MHz by 48.
bset ATDCTL4 SRES8 ; Use 8-bit conversion mode.

; Start the conversion by writing the scan select information to
ATDCTL5.
; First change the ATD mode.

top: bset ADMODE JUSTIFY ; Set %10000000 in ADMODE.
bset ADMODE AN ; Set %00000111 in ADMODE.
ldaa ADMODE ; Load acc. A with ADMODE.
bclr ATDCTL5 #$FF ; Clear ATDCLT5 with the
inverted valve of #$FF.
staa ATDCTL5 ; Starts conversion.

; And wait until conversion done.

spin: brclr ATDSTAT0 SCF, spin ; A bitwise AND.

; So that as long as SCF = 0, the branch to 'spin' is taken.
; When the SCF flag in ATDSTAT = 1 the branch is not taken!

clrb ; Clear acc. B
ldab ADR0L ; Load acc. B with the voltage
value that is on the
; board that is stored in ADR0L.
stab PORTB ; Show the voltage value with
the LED'S.
bsr longdelay
bra top
swi ; Stop the program and look at
the values.

org code

ADMODE db $0

longdelay
ldx #$ffff
ldy #$0188
time: dbne x, time
dbne y, time
rts ;Stepper Motor Controller

; The Diodes on Port B Represent Stepper Motor Control Transistors

PORTB equ $0001 ;Port B register
DDRB equ $0003 ;Port B Data Direction Register

PORTP equ $0258 ;Port P register
DDRP equ $025A ;Port P Data Direction Register
RDRP equ $025B ;Port P Reduced Drive Register

DELAY equ $0002 ;$ffff ;Delay for software timing loops
COUNTNUM equ 48 ;number of times to repeat CW direction
CODE equ $1000
STACK equ $2000 ;STACK org CODE

lds #STACK
movb #$ff,DDRB ;make Port B all outputs
movb #$00,PORTB ;clear Port B movb #$0f,DDRP ;make lower 4 bits Port P outputs
movb #$00,PORTP ;clear Port P ldaa #COUNTNUM ;# of times to repeat CW direction
staa count ;save count

loop_CW jsr DelayM

jsr Step_CW ;Step once CW (increment)

ldaa Output_pattern ;load output pattern, setup by Step_CW
staa PORTB ;output the pattern to diodes
anda #$0F
staa PORTP ;output the pattern to motor

dec count
bne loop_CW ;continue CW direction

ldaa #COUNTNUM ;# of times to repeat CCW direction
staa count

loop_CCW
jsr DelayM
jsr Step_CCW ;Step once CCW (decrement)

ldaa Output_pattern ;load output pattern, setup by Step_CCW
staa PORTB ;output the pattern to diodes
anda #$0F ;mask out upper 4 bits
staa PORTP ;output the pattern to motor

dec count
bne loop_CCW ;continue CCW direction

swi ;stop
;loop bra loop

***************************************************
*
* Step Clockwise Subroutine
*
* This subroutine controls clockwise rotation of the motors.
*
* Inputs: None
*
* Outputs: Ouput_pattern Modifies output pattern
* Sequence_ptr Pointer to table of stepper
commands
*
* Invokes: Nothing
*
***************************************************
Step_CW ldab Sequence_ptr ;Load Sequence pointer
incb ;Increment to point to next
* ;sequence value
andb #$07 ;Restrict table addresses to
lower 3 bits
stab Sequence_ptr ;Save Sequence pointer
clra ;Clear acc A
addd #Step_Table ;Add address of Step Table
xgdy ;Exchange D with Y so that
* ;indirect addressing can be
* ;performed again.
ldab 0,y ;Load value from table
stab Output_pattern ;Save output pattern
rts ;Return

***************************************************
*
* Step Counter-Clockwise Subroutine
*
* This subroutine controls counter-clockwise rotation of the motors.
*
* Inputs: None
*
* Outputs: Output_pattern Modifies output pattern
* Sequence_ptr Pointer to table of stepper
commands
*
* Invokes: Nothing
*
***************************************************
Step_CCW ldab Sequence_ptr ;Load Sequence pointer
decb ;Decrement to point to next
* ;sequence value
andb #$07 ;Keep lowest two bits
stab Sequence_ptr ;Save Sequence pointer
clra ;Clear acc A
addd #Step_Table ;Add address of Step Table
xgdy ;Exchange D with Y so that
* ;indirect addressing can be
* ;performed again.
ldab 0,y ;Load value from table
stab Output_pattern ;Save output pattern
rts ;Return

***************************************************
DelayM
ldx #8 ;Have to delay so that mechanical motors
ldy #$FFFF
L1 dey
bne L1 ;can keep up.
dex
bne L1
rts
***************************************************
*
* Step Table:
*
* This table contains the sequence to be output to cause the stepper
* motors to turn. If followed from top to bottom, restarting the
* sequence at the top when necessary, will cause the steppers to turn
* clockwise. Following the sequence from bottom to top, restarting
* the sequence at the bottom when necessary, the motors will turn
* counter-clockwise.
*
***************************************************

org $1400 Step_Table
* Full Step One Phase On
dc.b $11 ;R
dc.b $44 ;R
dc.b $22 ;L
dc.b $88 ;L

;*Full Step Two Phases On

;* dc.b $66 ;
* dc.b $AA ;
* dc.b $99 ;
* dc.b $55 ; HalfStep

dc.b $11
dc.b $55
dc.b $44
dc.b $66
dc.b $22
dc.b $AA
dc.b $88
dc.b $99 count dc.b $00 ;Counts # of iterations

Sequence_ptr dc.b $00 ;pointer to sequence to control motor
Output_pattern dc.b $00 ;Pattern to output to port which
;controls the stepper motor board -----Original Message-----
From: Jackie Johnson [mailto:]
Sent: Thursday, March 25, 2004 8:52 AM
To: '
Subject: Stepper Motors using the 68HC12

I have enclosed a program that I a working on and am trying to get this
program to work properly. My motor is not stopping. Example: If I
want my motor to stop at 90 degrees with a 1.2498 voltage applied via
the POT (potentiometer). My motor is continually running and not
stopping based on my POT adjustments. Any ideas would be greatly
appreciated from a frustrated student, who is on Spring break and NOT in
Mexico!

I have enclosed my program (MINIIDE) for your perusal. I want to
operate in the half-step mode.

THANKS,
Jackie --------------------To learn more
about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu

----
--
Yahoo! Groups Links

a.. To


Reply by Gary Olmstead March 26, 20042004-03-26
At 08:46 AM 3/26/04, you wrote:
>Gary,
>Good morning from Alaska..I believe the version is M68HC12.

Well, there are 10 versions of the 68HC12, and 19 of the MC9S12. What does
it say on the top of the chip?
>The program
>that I included works fine EXCEPT it continues to "half-step".

Is it half stepping before this point, or does it switch over to half step
from something else?

> I am
>trying to figure out how to program this so that if I set the
>potentiometer (manually do this on the board) to 1.24 volts that the
>motor that it will step to it's 90 degrees and stay there until I adjust
>the POT again. Of course the LED's need to read the correct binary
>number for 1.24 volts.

You've got two separate problems.
What do the LEDs read when the input is at 0V?
What do the LEDs read when the input is 1.24V?
What do they read at 5V? >
>I am thinking that I will have to do a comparison, maybe a branch????
First things first.

Gary Olmstead
Toucan Technology
Ventura CA


Reply by Jackie Johnson March 26, 20042004-03-26
Gary,
Good morning from Alaska..I believe the version is M68HC12. The program
that I included works fine EXCEPT it continues to "half-step". I am
trying to figure out how to program this so that if I set the
potentiometer (manually do this on the board) to 1.24 volts that the
motor that it will step to it's 90 degrees and stay there until I adjust
the POT again. Of course the LED's need to read the correct binary
number for 1.24 volts.

I am thinking that I will have to do a comparison, maybe a branch????

Thanks for your help.
Jackie

-----Original Message-----
From: Gary Olmstead [mailto:]
Sent: Friday, March 26, 2004 6:42 AM
To:
Subject: Re: [68HC12] FW: Stepper Motors using the 68HC12

Jackie --

Which version of the HC12 are you using?

One thing that jumps out is that you are using bset and bclr for
registers. This isn't a good idea, since they are read/modify/write
instructions, and have bad consequences under certain conditions. The
safe
thing is to get rid of all of them, and avoid them in the future for
register manipulation. (They are fine for regular RAM.)

Gary Olmstead
Toucan Technology
Ventura CA At 12:38 PM 3/25/04, you wrote:
>I have added a program that I a working on and am trying to get this
>program to work properly. My motor is not stopping. Example: If I
>want my motor to stop at 90 degrees with a 1.2498 voltage applied via
>the POT (potentiometer). My motor is continually running and not
>stopping based on my POT adjustments. Any ideas would be greatly
>appreciated from a frustrated student, who is on Spring break and NOT
in
>Mexico!
>
>I have added my program for your perusal. I want to operate in the
>; Power up the A/D
>
> bset ATDCTL2 ADPU ; OR function, wakes up ADC.
>
>; Generate a "short" delay > ? microsec to let ADC settle.
>
> ldaa #$FF ; FF loops for.
> short: nop ; 2 times FF loops
> dbne a,short ; Decriment acc. A and branch
to
>
> bclr ATDCTL2 AFFC|AWAI|ASCIE|ETRIGE ; Clrears all
> bclr ATDCTL3 #$FF ; Clear all bits
> bset ATDCTL3 SC ; 1 conversion needed for an7


> bclr ATDCTL4 #$FF ; Clears ATDCLT4 and makes it
>ready for bit setting.
> bset ATDCTL4 #$60 ; Select 16 X sample time.
> bset ATDCTL4 PRS ; Set PRS, Divide 24 MHz by
48.
> bset ATDCTL4 SRES8 ; Use 8-bit conversion mode.
>
>; Start the conversion by writing the scan select information to
>ATDCTL5.
>; First change the ATD mode.
>
> top: bset ADMODE JUSTIFY ; Set %10000000 in ADMODE.
> bset ADMODE AN ; Set %00000111 in ADMODE.
> ldaa ADMODE ; Load acc. A with ADMODE.
> bclr ATDCTL5 #$FF ; Clear ATDCLT5 with the
>inverted valve of #$FF.
> staa ATDCTL5 ; Starts conversion.

--------------------To learn more
about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu

_____

> Service.





Reply by Gary Olmstead March 26, 20042004-03-26
Jackie --

Which version of the HC12 are you using?

One thing that jumps out is that you are using bset and bclr for
registers. This isn't a good idea, since they are read/modify/write
instructions, and have bad consequences under certain conditions. The safe
thing is to get rid of all of them, and avoid them in the future for
register manipulation. (They are fine for regular RAM.)

Gary Olmstead
Toucan Technology
Ventura CA At 12:38 PM 3/25/04, you wrote:
>I have added a program that I a working on and am trying to get this
>program to work properly. My motor is not stopping. Example: If I
>want my motor to stop at 90 degrees with a 1.2498 voltage applied via
>the POT (potentiometer). My motor is continually running and not
>stopping based on my POT adjustments. Any ideas would be greatly
>appreciated from a frustrated student, who is on Spring break and NOT in
>Mexico!
>
>I have added my program for your perusal. I want to operate in the
>; Power up the A/D
>
> bset ATDCTL2 ADPU ; OR function, wakes up ADC.
>
>; Generate a "short" delay > ? microsec to let ADC settle.
>
> ldaa #$FF ; FF loops for.
> short: nop ; 2 times FF loops
> dbne a,short ; Decriment acc. A and branch to
>
> bclr ATDCTL2 AFFC|AWAI|ASCIE|ETRIGE ; Clrears all
> bclr ATDCTL3 #$FF ; Clear all bits
> bset ATDCTL3 SC ; 1 conversion needed for an7


> bclr ATDCTL4 #$FF ; Clears ATDCLT4 and makes it
>ready for bit setting.
> bset ATDCTL4 #$60 ; Select 16 X sample time.
> bset ATDCTL4 PRS ; Set PRS, Divide 24 MHz by 48.
> bset ATDCTL4 SRES8 ; Use 8-bit conversion mode.
>
>; Start the conversion by writing the scan select information to
>ATDCTL5.
>; First change the ATD mode.
>
> top: bset ADMODE JUSTIFY ; Set %10000000 in ADMODE.
> bset ADMODE AN ; Set %00000111 in ADMODE.
> ldaa ADMODE ; Load acc. A with ADMODE.
> bclr ATDCTL5 #$FF ; Clear ATDCLT5 with the
>inverted valve of #$FF.
> staa ATDCTL5 ; Starts conversion.



Reply by Jackie Johnson March 25, 20042004-03-25
I have added a program that I a working on and am trying to get this
program to work properly. My motor is not stopping. Example: If I
want my motor to stop at 90 degrees with a 1.2498 voltage applied via
the POT (potentiometer). My motor is continually running and not
stopping based on my POT adjustments. Any ideas would be greatly
appreciated from a frustrated student, who is on Spring break and NOT in
Mexico!

I have added my program for your perusal. I want to operate in the
half-step mode.

THANKS,
Jackie

THANKS to the individual who brought to my attention that I can not
attach documents.
********************************************************
* This is a program showing the use
* of the A/D converter.
* The program will convert the voltage from
* the kit's potentiometer that is connected to
* the ADC's AN07 input pin.*
* The program stores the result at adr07h*
* The default for ATDCTL5: left justified data, unsigned,*
* single conversion sequence, one channel sample, channel AN0*
********************************************************
* Constant Equates
*A/D control and status registers
ATDCTL2 EQU $82
ATDCTL3 EQU $83
ATDCTL4 EQU $84
ATDCTL5 EQU $85

ATDSTAT0 EQU $86 ; A/D status register (SCF)
ATDSTAT1 EQU $87 ; A/D status register (CCF)
***************************************************************
*ADC Results Registers*

ADR0H EQU $90 ; 10 bit values take
ADR0L EQU $91 ; 2 bytes of storage
ADR1H EQU $92 ; Left justified have MSB
ADR1L EQU $93 ; in high byte, bits 1,0 are
ADR2H EQU $94 ; stored in b7,6 of low byte
ADR2L EQU $95 ;
ADR3H EQU $96 ; Right justified have LSB
ADR3L EQU $97 ; stored in low byte, bits 9,8
ADR4H EQU $98 ; stored in b1,0 of high byte.
ADR4L EQU $99 ;
ADR5H EQU $9A ; 8 bit values
ADR5L EQU $9B ; Left justified
ADR6H EQU $9C ; stored in high bytes.
ADR6L EQU $9D ; Right justified
ADR7H EQU $9E ; stored in low bytes
ADR7L EQU $9F ; of result registers.
***************************************************************
*ATDCL2 Register Control Bits*
*All bits are clear on reset*

ADPU EQU %10000000 ; A/D power up bit, Set to power
up
AFFC EQU %01000000 ; Set to Fast Clear all CCF
flags
AWAI EQU %00100000 ; Set to power down A/D in wait
mode
ETRIGE EQU %00000100 ; Set to Enable external trigger
ETRIGLE EQU %00010000 ; Set to Level Triggered (Clear
for Edge)
ETRIGP EQU %00001000 ; Set for Rising Edge or High
Level
ASCIE EQU %00000010 ; Set to enable ATD interrupt
ASCIF EQU %00000001 ; Set by ATD when interrupt
conversion complete
*If AFFC is cleared then the CCF flag is reset only when*
*ATDSTAT1 and the A/D results register(s) are read.*
*If AFFC is set then the SCF flag is reset only when*
*conversion sequence has completed and results read*
*ASCIF is read only
***************************************************************
*ATDCTL3 Register Control Bits

*SC EQU %0xxxx 000 ; # of conversions in sequence,
1 to 8 (4 bits)
FIFOATD EQU %00000100 ; Set to wrap around conversion
results
SC EQU %00001000 ; one conversion
***************************************************************
*ATDCL4 Register Control Bits
*Reset value is$05 (prescalar bits)*

SRES8 EQU %10000000 ; Resolution, Set = 8 bit
SMP EQU %01100000 ; SMP1 and SMP0 Sample Time Bits
*PRS EQU %000xxxxx ; PRS Clock Prescalar Bits
PRS EQU %00010111 ; PRS bits for this program

*default resolution is 10 bits*
***************************************************************
*ATDCL5 Register Control Bits*
*All bits are clear on reset*

JUSTIFY EQU %10000000 ; Set for right justification
SIGN EQU %01000000 ; Set for signed number
representation
SCAN EQU %00100000 ; Set for continuous conversions
MULT EQU %00010000 ; Set to sample multiple
channels
*AN EQU %00000xxx ; ATD Input Channel Number 0 to
7 (3 bit number)
AN EQU %00000111 ; Using channel 7 for this
program
***************************************************************
*ATD Status Register 0 (ATDSTAT0)*
*All bits are clear on reset*
*The values of these constants are AND'd with ATDSTAT0. If the
*result is non-zero, then the flag is set. If the result is zero then
*the flag was not set by the ATD*

SCF EQU %10000000 ; Sequence conversion Complete
Flag
ETORF EQU %00100000 ; Ext Trigger Overrun Flag
FIFOR EQU %00010000 ; FIFO Overrun Flag
*CC EQU %00000xxx ; 3 bit Conversion Counter (R
only)

*Writing a 1 to the SCF clears it*
*FIFO indicates a register has been overwritten before*
*it has been read.*
*CC points to the next register to be used by the ATD*
***************************************************************

*ATD Status Register 1 (ATDSTAT1)*
*All bits are clear on reset*
*CCF is used in a similar manner to the flags of ATDSTAT0

CCF EQU %11111111 ; Set by ATD for each results
register
*after it receives a value, if AFFC=0 reading ATDSTA1 and then*
*a results register clears a CCF flag for each individual results
register*
*All cleared by a write to ATDCTL5*
*If AFFC=1 a zero in a CCF bit indicates conversion number x has*
*not completed.*
***************************************************************
* Memory Map Equates
***************************************************************
;CODE EQU $1000
;DATA EQU $1050
;STACK EQU $3000 ; Remember that debug uses
memory.
;DDRB EQU $0003
;PORTB EQU $0001
*************************************************************** org CODE
lds #STACK
ldab #$FF ; Load B with %11111111
stab DDRB ; Makes portb an output port.
clrb ; Clears acc. B

; Power up the A/D

bset ATDCTL2 ADPU ; OR function, wakes up ADC.

; Generate a "short" delay > ? microsec to let ADC settle.

ldaa #$FF ; FF loops for.
short: nop ; 2 times FF loops
dbne a,short ; Decriment acc. A and branch to
delay.

; Now set up the A/D.
; Normal flag clearing, run in WAIT mode, no interrupts.

bclr ATDCTL2 AFFC|AWAI|ASCIE|ETRIGE ; Clrears all
the positions stated
; on the
ATDCLT2.
; Mask bits are inverted and AND'd with ATDCTL2.
; Any mask bit that is a '1' clears the corresponding bit in ATDCTL2.
Here we clear four bits.

bclr ATDCTL3 #$FF ; Clear all bits
bset ATDCTL3 SC ; 1 conversion needed for an7 ; The bus speed is 24 MHz. To obtain the slowest conversion time select
the longest sample time
; and an ATD conversion clock frequency of 500kHz. Sample time:
SMP1:SMP2 = 1:1
; PRS = 10111, gives ATD ccf of 500kHz Conversion time = 32uS.

bclr ATDCTL4 #$FF ; Clears ATDCLT4 and makes it
ready for bit setting.
bset ATDCTL4 #$60 ; Select 16 X sample time.
bset ATDCTL4 PRS ; Set PRS, Divide 24 MHz by 48.
bset ATDCTL4 SRES8 ; Use 8-bit conversion mode.

; Start the conversion by writing the scan select information to
ATDCTL5.
; First change the ATD mode.

top: bset ADMODE JUSTIFY ; Set %10000000 in ADMODE.
bset ADMODE AN ; Set %00000111 in ADMODE.
ldaa ADMODE ; Load acc. A with ADMODE.
bclr ATDCTL5 #$FF ; Clear ATDCLT5 with the
inverted valve of #$FF.
staa ATDCTL5 ; Starts conversion.

; And wait until conversion done.

spin: brclr ATDSTAT0 SCF, spin ; A bitwise AND.

; So that as long as SCF = 0, the branch to 'spin' is taken.
; When the SCF flag in ATDSTAT = 1 the branch is not taken!

clrb ; Clear acc. B
ldab ADR0L ; Load acc. B with the voltage
value that is on the
; board that is stored in ADR0L.
stab PORTB ; Show the voltage value with
the LED'S.
bsr longdelay
bra top
swi ; Stop the program and look at
the values.

org code

ADMODE db $0

longdelay
ldx #$ffff
ldy #$0188
time: dbne x, time
dbne y, time
rts ;Stepper Motor Controller

; The Diodes on Port B Represent Stepper Motor Control Transistors

PORTB equ $0001 ;Port B register
DDRB equ $0003 ;Port B Data Direction Register

PORTP equ $0258 ;Port P register
DDRP equ $025A ;Port P Data Direction Register
RDRP equ $025B ;Port P Reduced Drive Register

DELAY equ $0002 ;$ffff ;Delay for software timing loops
COUNTNUM equ 48 ;number of times to repeat CW direction
CODE equ $1000
STACK equ $2000 ;STACK org CODE

lds #STACK
movb #$ff,DDRB ;make Port B all outputs
movb #$00,PORTB ;clear Port B movb #$0f,DDRP ;make lower 4 bits Port P outputs
movb #$00,PORTP ;clear Port P ldaa #COUNTNUM ;# of times to repeat CW direction
staa count ;save count

loop_CW jsr DelayM

jsr Step_CW ;Step once CW (increment)

ldaa Output_pattern ;load output pattern, setup by Step_CW
staa PORTB ;output the pattern to diodes
anda #$0F
staa PORTP ;output the pattern to motor

dec count
bne loop_CW ;continue CW direction

ldaa #COUNTNUM ;# of times to repeat CCW direction
staa count

loop_CCW
jsr DelayM
jsr Step_CCW ;Step once CCW (decrement)

ldaa Output_pattern ;load output pattern, setup by Step_CCW
staa PORTB ;output the pattern to diodes
anda #$0F ;mask out upper 4 bits
staa PORTP ;output the pattern to motor

dec count
bne loop_CCW ;continue CCW direction

swi ;stop
;loop bra loop

***************************************************
*
* Step Clockwise Subroutine
*
* This subroutine controls clockwise rotation of the motors.
*
* Inputs: None
*
* Outputs: Ouput_pattern Modifies output pattern
* Sequence_ptr Pointer to table of stepper
commands
*
* Invokes: Nothing
*
***************************************************
Step_CW ldab Sequence_ptr ;Load Sequence pointer
incb ;Increment to point to next
* ;sequence value
andb #$07 ;Restrict table addresses to
lower 3 bits
stab Sequence_ptr ;Save Sequence pointer
clra ;Clear acc A
addd #Step_Table ;Add address of Step Table
xgdy ;Exchange D with Y so that
* ;indirect addressing can be
* ;performed again.
ldab 0,y ;Load value from table
stab Output_pattern ;Save output pattern
rts ;Return

***************************************************
*
* Step Counter-Clockwise Subroutine
*
* This subroutine controls counter-clockwise rotation of the motors.
*
* Inputs: None
*
* Outputs: Output_pattern Modifies output pattern
* Sequence_ptr Pointer to table of stepper
commands
*
* Invokes: Nothing
*
***************************************************
Step_CCW ldab Sequence_ptr ;Load Sequence pointer
decb ;Decrement to point to next
* ;sequence value
andb #$07 ;Keep lowest two bits
stab Sequence_ptr ;Save Sequence pointer
clra ;Clear acc A
addd #Step_Table ;Add address of Step Table
xgdy ;Exchange D with Y so that
* ;indirect addressing can be
* ;performed again.
ldab 0,y ;Load value from table
stab Output_pattern ;Save output pattern
rts ;Return

***************************************************
DelayM
ldx #8 ;Have to delay so that mechanical motors
ldy #$FFFF
L1 dey
bne L1 ;can keep up.
dex
bne L1
rts
***************************************************
*
* Step Table:
*
* This table contains the sequence to be output to cause the stepper
* motors to turn. If followed from top to bottom, restarting the
* sequence at the top when necessary, will cause the steppers to turn
* clockwise. Following the sequence from bottom to top, restarting
* the sequence at the bottom when necessary, the motors will turn
* counter-clockwise.
*
***************************************************

org $1400 Step_Table
* Full Step One Phase On
dc.b $11 ;R
dc.b $44 ;R
dc.b $22 ;L
dc.b $88 ;L

;*Full Step Two Phases On

;* dc.b $66 ;
* dc.b $AA ;
* dc.b $99 ;
* dc.b $55 ; HalfStep

dc.b $11
dc.b $55
dc.b $44
dc.b $66
dc.b $22
dc.b $AA
dc.b $88
dc.b $99 count dc.b $00 ;Counts # of iterations

Sequence_ptr dc.b $00 ;pointer to sequence to control motor
Output_pattern dc.b $00 ;Pattern to output to port which
;controls the stepper motor board -----Original Message-----
From: Jackie Johnson [mailto:]
Sent: Thursday, March 25, 2004 8:52 AM
To: '
Subject: Stepper Motors using the 68HC12

I have enclosed a program that I a working on and am trying to get this
program to work properly. My motor is not stopping. Example: If I
want my motor to stop at 90 degrees with a 1.2498 voltage applied via
the POT (potentiometer). My motor is continually running and not
stopping based on my POT adjustments. Any ideas would be greatly
appreciated from a frustrated student, who is on Spring break and NOT in
Mexico!

I have enclosed my program (MINIIDE) for your perusal. I want to
operate in the half-step mode.

THANKS,
Jackie




Reply by Jackie Johnson March 25, 20042004-03-25
I have enclosed a program that I a working on and am trying to get this
program to work properly. My motor is not stopping. Example: If I
want my motor to stop at 90 degrees with a 1.2498 voltage applied via
the POT (potentiometer). My motor is continually running and not
stopping based on my POT adjustments. Any ideas would be greatly
appreciated from a frustrated student, who is on Spring break and NOT in
Mexico!

I have enclosed my program (MINIIDE) for your perusal. I want to
operate in the half-step mode.

THANKS,
Jackie