AT90S2313-StepperMotorControl
This is a project, which specifies the application of AVR AT90S2313 as stepper
motor control. Here we can control the speed of the stepper motor by reducing
the delay of each sequence. Since the speed of the stepper motor is directly
proportional to the pulse width, by controlling the pulse width, the speed can
be controlled.
This project database uses one AT90S2313 Microcontroller, 2 displays for
displaying the sequence & 2 display drivers for driving display units.
The program is as shown:
_SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.text
.global main
.type main, @function
;-------------STEPPER MOTOR CONTROL USING AT90S2313----------
;-----------MAIN ROUTINE-----------------------------------
main:
LDI R17,0XFF ; Setting up the PORTB in the output mode
OUT 0X17,R17
LDI R26,0X09 ;Loading the values for controlling the speed of stepper
motor
LDI R27,0X0C
LDI R28,0X06
LDI R29,0X03
LDI R20,0X00 ; Initializing the PORTB
OUT 0X18,R20
LDI R30,0X1A ; Loading the starting address value
LDI R31,0X00
LD R21,Z+ ; Incrementing the address after storing its data in R21
OUT 0X18,R21
/*Setting up Counter*/
COUNTER:
LDI R21,0X00 ; Setting up the Timer 1
OUT 0X2C,R21 ; Initializing the values in 16 bit Timer 1
OUT 0X2D,R21
LDI R22,0X22
OUT 0X2A,R2 ; Setting up the output ‘COMPARE’ register & loading the
values.
OUT 0X2B,R21
LDI R23,0X40
OUT 0X39,R23 ; Enabling the ‘COMPARE’ match interrupt
SEI
LDI R22,0X01
OUT 0X2E,R22 ; Starting the Timer with 1 count = CLK
LOOP1:
RJMP LOOP1
;-------------------------------------------------------------------
;interrupt service routine for OUTPUT COMPARE USING THE 16BIT TIMER1
;-------------------------------------------------------------------
.size main, .-main
.global __vector_4
.type __vector_4, @function
__vector_4:
LD R20,Z+ ; Incrementing the address
OUT 0X18,R20 ; Outputting the data through Port
CPI R20,0X03 ; Comparing with last value
BRNE COUNTER ; Timer Jmp
LDI R30,0X1A ; Loading The Initial Address
LDI R31,0X00
RJMP COUNTER ; Timer Jmp