org 0H
stepper equ P1
main:
mov stepper, #0CH
acall delay
mov stepper, #06H
acall delay
mov stepper, #03H
acall delay
mov stepper, #09H
acall delay
sjmp main
delay:
mov r7,#4
wait2:
mov r6,#0FFH
wait1:
mov r5,#0FFH
wait:
djnz r5,wait
djnz r6,wait1
djnz r7,wait2
ret
end
Stepper Motor Interfacing in MASM?
Page 1 of 114 Replies - 1527 Views - Last Post: 08 May 2012 - 09:32 PM
#1
Stepper Motor Interfacing in MASM?
Posted 04 May 2012 - 01:37 PM
Replies To: Stepper Motor Interfacing in MASM?
#2
Re: Stepper Motor Interfacing in MASM?
Posted 04 May 2012 - 05:04 PM
How is this motor connected to your computer or whatever? Why do you want to use Assembly vs C or some other HLL? What do you want this motor to do?
"People always want to build a building without even knowing how to do it or where to start!"
#3
Re: Stepper Motor Interfacing in MASM?
Posted 05 May 2012 - 05:00 AM
I also found this one below. If someone can tell me in which Assembly it is written I would be glad. It uses a library from Microchip.
; LIST p=16F628 ; PIC16F628 is the target processor
Processor 16F628
Include "P16F628.inc"
; +---------------+
; | |
; STEP_MODE 1-| RA2 RA1 |-18 HALFSTEPOUT
; | |
; HALFSTEPIN 2-| RA3 RA0 |-17 RESET
; | |
; CHIP_ENABLE 3-| RA4 OCS |-16--+------------+ n/c
; | | | Oscillator |
; n/c 4-| ~MCLR OCS |-15--+------------+ n/c
; | |
; 0V 5-| Vss Vdd |-14 +5V
; | |
; MOVE 6-| RB0 RB7 |-13 LSTOP
; | |
; RX 7-| RB1 RB6 |-12 RSTOP
; | |
; TX 8-| RB2 RB5 |-11 DIROUT
; | |
; CLOCK 9-| RB3 RB4 |-10 DIRIN
; +---------------+
;====================================================================
; Configuration Bits:
; Code Protection = OFF
; WatchDog Timer = OFF
; Power-up Timer = ON
; Oscillator Type = INTERNAL
; Internal RC Oscillator = ON
; Low Voltage Program = OFF
; Master Clear = OFF
; Brown Out Detect = OFF
;====================================================================
__Config _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT & _LVP_OFF & _MCLRE_OFF & _BODEN_OFF
CBLOCK 0X20 ; start of internal memory
COUNTER0, COUNTER1 ; define delay counters
STEPCOUNT
ENDC
#define CHIP_ENABLE PORTA,4 ; define i/o pin labels
#define MOVE PORTB,0
#define RX PORTB,1
#define TX PORTB,2
#define CLOCK PORTB,3
#define DIRIN PORTB,4
#define DIROUT PORTB,5
#define LSTOP PORTB,7
#define RSTOP PORTB,6
#define STEP_MODE PORTA,2
#define HALFSTEPIN PORTA,3
#define HALFSTEPOUT PORTA,1
#define RESET PORTA,0
_ResetVector set 0x00 ; reset vector
org _ResetVector ; pic starts code execution from here
goto START
nop
nop
; *** Start of program code ***
START
movlw 0x07 ; turn comparators off and
movwf CMCON ; enable pins for i/o functions
bsf STATUS,RP0 ; select page 1
movlw B'00001101' ; i/o pin selection for port
movwf TRISA ; set port A
movlw B'11010011' ; i/o pin selection for port
movwf TRISB ; set port B
bcf OPTION_REG,7 ; switch on portB pull up resistors
bcf STATUS,RP0 ; return to page 0
clrf PORTA ; clear port A
clrf PORTB ; clear port B
MAIN CLRWDT ; clear watchdog timer in case of latchup
BTFSC RESET ; check reset pin
goto RESET_MODE ; if 1 go to reset mode
BTFSS MOVE ; check move pin
goto MAIN ; if 0 go back to main
BTFSC HALFSTEPIN ; check half step pin
goto HALFSTEPMODE ; if 1 goto half step mode
goto FULLSTEPMODE ; if 0 goto full step mode
HALFSTEPMODE
bsf HALFSTEPOUT ; if 1 set high for half step mode
goto STEPMODE ; goto step mode
FULLSTEPMODE
bcf HALFSTEPOUT ; if 0 set low for full step mode
goto STEPMODE ; goto step mode
STEPMODE
BTFSC STEP_MODE ; check step mode pin
goto FREERUN ; if 1 go to free running mode
goto ONE_STEP ; if 0 go to one step mode
RESET_MODE
BTFSS LSTOP ; if lstop high then skip next line
call LEFT ; call left routine
BTFSS LSTOP ; if lstop high then skip next line
goto RESET_MODE ; go back to reset mode
clrf STEPCOUNT ; clear stepcount counter register
call RIGHT ; call right routine
incf STEPCOUNT,f ; increment step counter
BTFSS RSTOP ; if rstop high then skip next line
goto $-3 ; go back 3 instructions
bcf STATUS,C ; clear complimentary bit
rrf STEPCOUNT,f ; move stepcount one bit right to divide by 2
call LEFT ; call left routine
decfsz STEPCOUNT,f ; decrement stepcount by one and skip next instruction on 0
goto $-2 ; go back 2 instructions
goto MAIN ; go back to main
FREERUN
BTFSC DIRIN ; if dirin pin low then skip next line
goto TRYRIGHT ; go to tryright routine
goto TRYLEFT ; go to tryleft routine
ONE_STEP
BTFSC DIRIN ; if dirin pin low then skip next line
goto STEPRIGHT ; go to stepright routine
goto STEPLEFT ; go to stepleft routine
STEPLEFT
BTFSS LSTOP ; if lstop high then skip next line
call LEFT ; call left routine
btfsc MOVE ; if move pin low then skip next line
goto $-1 ; go back to last instruction
goto MAIN ; go back to main
STEPRIGHT
BTFSS RSTOP ; if rstop high then skip next line
call RIGHT ; call right routine
btfsc MOVE ; if move pin low then skip next line
goto $-1 ; go back one instruction
goto MAIN ; go back to main
TRYRIGHT
BTFSS RSTOP ; if rstop high then skip next line
call RIGHT ; call right routine
goto MAIN ; go back to main
TRYLEFT
BTFSS LSTOP ; if lstop high then skip next line
call LEFT ; call left routine
goto MAIN ; go back to main
RIGHT
bcf CHIP_ENABLE ; set chip_enable pin low
bcf DIROUT ; set direction out pin low to go right
bsf CLOCK ; set clock pin high
call DELAY ; go to delay routine
bsf CHIP_ENABLE ; set chip enable pin high
bcf CLOCK ; set clock pin low
call DELAY ; call delay routine
return ; return
LEFT
bcf CHIP_ENABLE ; set chip_enable pin low
bsf DIROUT ; set direction out pin high to go left
bsf CLOCK ; set clock pin high
call DELAY ; go to delay routine
bsf CHIP_ENABLE ; set chip enable pin high
bcf CLOCK ; set clock pin low
call DELAY ; call delay routine
return ; return
DELAY
movlw .10 ; delay is equal to 10 milliseconds by moving .10 into w register
movwf COUNTER0 ; move w register into COUNTER0
FLOOP nop ; no operation
nop ; no operation
movlw .248 ; inner part of delay loop equal to 1 millisecond by moving .248 into w register
movwf COUNTER1 ; move w register into COUNTER1
FILOOP nop ; no operation
decfsz COUNTER1,f ; decrement counter1 by 1
goto FILOOP ; goto filoop
decfsz COUNTER0,F ; decrement counter 0 by 1
goto FLOOP ; goto floop
return ; return
END ; end of program
; *** End of program ***
This post has been edited by erkant: 05 May 2012 - 07:32 AM
#4
Re: Stepper Motor Interfacing in MASM?
Posted 05 May 2012 - 03:52 PM
#5
Re: Stepper Motor Interfacing in MASM?
Posted 05 May 2012 - 03:55 PM
Quote
First you must learn Assembly if you are going to write about it or create illustrations. Why don't you start with a simple calculator?
#7
Re: Stepper Motor Interfacing in MASM?
Posted 06 May 2012 - 02:49 AM
This post has been edited by erkant: 06 May 2012 - 03:44 AM
#8
Re: Stepper Motor Interfacing in MASM?
Posted 06 May 2012 - 08:52 AM
I see in your profile you list C, so you have experience with the Win32 API? x86 Windows Assembly is NOT much different than C. You also list Assembly, what dialect?
I have written quite a few MASM tutorials to get folks started, they are in our tutorial section
If you want to learn MASM, you could download the MASM32 SDK which contains MASM and its related tools, libs and includes for MANY Windows APIs, sample programs with source, a nice library of functions complete with source, and a few other goodies.
Quote
Let's see, I just googled "calculator MASM" and got back many pages with sample code and programs.
#9
Re: Stepper Motor Interfacing in MASM?
Posted 06 May 2012 - 09:15 AM
Quote
It has said that C is high level assembly.
#10
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 05:00 AM
Edit: I have knowledge in C, C++, parallel programming languages and extensions, and I just started with the Assembly. But I really need this stepper motor code until tomorrow or the day after tomorrow. If anyone can help I would be glad.
This post has been edited by erkant: 08 May 2012 - 05:05 AM
#11
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 05:20 AM
In the picture, it was connected to PIC's pins.
(At least I think the picture shows PIC-chip with the pins used as I/O and the code programmed inside - no external memory.)
That can't be done with x86, and if it's some x86-based microcontroller, the pins must be quite different.
Also the kind of motor is unknown.
#12
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 07:46 AM
I found this one, what's your opinion:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H
;
ORG 1000H
;
;
MOV AL, 10000000B
OUT PPIC_C, AL
;
MOV AL, 11111111B
OUT PPTA, AL
MOV AL, 00000000B
OUT PPIC, AL
L1: MOV SI, OFFSET ROT
L2: MOV AL, BYTE PRT CS:[SI]
CMP AL, 0FFH
JZ L1
OUT PPIB, AL
INC SI
CALL TIMER
JMP L2
;
TIMER: MOV CX, 1
TIMER2: PUSH CX
MOV CX, 0
TIMER1: NOP
NOP
NOP
NOP
LOOP TIMER1
POP CX
LOOP TIMER2
RET
ROT: DB 11101110B
DB 10111011B
DB 11011101B
DB 01110111B
DB 0FFH
;
CODE ENDS
END
This post has been edited by erkant: 08 May 2012 - 07:47 AM
#13
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 12:56 PM
I recall (vaguely) that 4 lines (port pins) are enough to drive a typical stepper motor.
I also recall that the lines are brought up and down in order (order defines the direction) and pinpairs (kinda differential) are driven with about 90 degree phase shift.
pinpairs are attached to the ends of a coil (at least you can think like that).
That's what I recall, but you better check.
If A and B are connected to one coil and B and C to the other:
Forward:
ABCD
1001
1010
0110
0101
backward:
ABCD
1001
0101
0110
1010
A bit like the mouse, but signal goes backwards.
This post has been edited by turboscrew: 08 May 2012 - 12:57 PM
#14
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 04:14 PM
You CANNOT write code for a motor you know nothing about (what model, what voltage, how is it connected to the computer - USB, COM, Serial, Parallel) What is the wiring diagram for the motor? You CANNOT write code to interface with this imaginary motor for an OS we don't know. The code above WILL NOT work in user land for anything higher and including VISTA.
I will teach you x86 to the best of my ability, but one thing I won't do is hand feed someone, that gets you no where and you learn nothing.
You should just write code for it in C or something that you know.
This post has been edited by GunnerInc: 08 May 2012 - 04:15 PM
#15
Re: Stepper Motor Interfacing in MASM?
Posted 08 May 2012 - 09:32 PM
Also, assembly doesn't let you off the hook with driver interface of windows or linux.
Which should you illustrate, asm or stepper motor driving?
|
|

New Topic/Question
Reply


MultiQuote







|