0% found this document useful (0 votes)
16 views

Arduino and Stepper Motor

Uploaded by

chandramahesh736
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Arduino and Stepper Motor

Uploaded by

chandramahesh736
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/334899187

Controlling the direction of a stepper motor using Arduino programmed in


assembly language.

Technical Report · August 2019

CITATIONS READS

0 664

1 author:

Marwan Abdulkhaleq Al-Yoonus


University of Mosul
32 PUBLICATIONS 16 CITATIONS

SEE PROFILE

All content following this page was uploaded by Marwan Abdulkhaleq Al-Yoonus on 02 August 2019.

The user has requested enhancement of the downloaded file.


University of Mosul Electrical Engineering Dept.
College of Engineering 4th E&C Lab.

Note: Most of the information mentioned in this lab sheet was written from ("The AVR
Microcontroller and Embedded Systems" by Muhammad Mazidi) and it is used for
educational purpose.

Microcontroller
Microcontroller is used in control systems, ranging from household appliances
and ending aircraft. A microcontroller contains on a single semiconductor chip
almost all digital electronics devices, from the logic elements to processor.
Each family of microcontrollers has its own Assembly language. Arduino
Mega 2560 as shown in figure 1 is high performance, low Power AVR 8-Bit
microcontroller. It has used advanced 135 powerful instructions; most of them
single clock cycle execution. Also it's consist of 32 x 8 general purpose
registers (GPR) and it's DC Current per I/O Pin is 40.0mA.

Figure 1: Arduino Mega 2560


Assembler directives
While instructions tell the CPU what to do, directives (also called pseudo-
instructions) give directions to the assembler. For example, the LDI and ADD
instructions are commands to the CPU, but (.EQU), (.ORG) are directives to
the assembler.
Data format representation
Hex: LDI R28,$75 ; R28=0x75
Binary: LDI R16,0b10011001 ; R16 = 10011001
ASCI: LDI R23,'2' ; R23 = 00110010 or 32 in Hex
Decimal: LDI R22,10 ; R22=10 decimal

I/O port pins and their functions:


The number of ports in AVR family varies depending on the number of pins on
the chip. Each port has three I/O registers associated with it, as shown in figure.
They are designated as PORTx, DDRx, and PINx. For example, for port B we
have PORTB, DDRB, and PINB.
Note that: DDR stands for Data Direction Register (For o/p, each bit set to 1).
PIN stands for Port INput pins.

1
(a)

(b)
Figure 2: Relations between the registers and Pins of AVR
(b) The input/output port in AVR
Photo micro-sensors
Slot-type Photo micro-sensor with connector (Non-modulated) as shown in
figure 3. The light source is GaAs infrared LED with a peak wavelength of 940
nm.

(a)

(b)
Figure 3: (a) NPN and PNP output circuit. (b) Sensor shape and terminal arrangement.
Stepper motor driver circuit
Stepper motors are available with either two coil bipolar or four coil unipolar
windings figure 4. Bipolar Winding - the stator flux is reversed by reversing the
current in the winding. It requires a push-pull bipolar drive as shown in figure
5. The operation of a step motor is dependent upon the pulse source and driver.
Arduino board digital output pins are used to feed pulses to the driver which
applies power to the appropriate motor windings.

2
(a) (b)
Figure 4: (a) Bipolar Winding stepper motor, (b) unipolar Winding stepper motor
Procedure:
The circuit shown in figure 5 used to drive one coil of bipolar stepper motor (see figure 4(a)).
1- Test the output of the photo sensor practically.
2- Run the Atmel studio 7 then open a new project and write the following program.

Figure 5: Bipolar stepper motor (push-pull bipolar) driver

.ORG 0x0000 ;.ORG directive is used to indicate the


beginning of the address. It can be used for
both code and data.
RJMP START
START:
LDI R16,0xff ;(LDI Rd,K)load Rd(destination)with immediate
value K, d must be between 16 and 31
OUT DDRB,R16 ; The OUT instruction tells the CPU to store
the GPR to the I/O register
LDI R16,0
OUT DDRC,R16
NEXT:
LDI R16,0
OUT PORTB,R16
IN R17,PORTC ; The IN instruction copies the contents of
PORTC to R17
SBIC PINC,2 ; Skip if bit '2' in register C =0 (i.e. skip
next instruction)
RJMP NEXT ; relative jump, the relative address rang is
(000-$FFF)
TEST: IN R17,PORTC
SBIS PINC,0 ; SWITCH- bit 0 test skip if '0' DOWN
SBIC PINC,1 ; PD- bit 1 test skip if '0' UP

3
RJMP DOWN
UP:
LDI R16,0X08
OUT PORTB,R16
RCALL DELAY_5 ; Relative CALL (the target address of the
subroutine must be within -2048 to +2047)
LDI R16,0X02
OUT PORTB,R16
RCALL DELAY_5
LDI R16,0X04
OUT PORTB,R16
RCALL DELAY_5
LDI R16,0X01
OUT PORTB,R16
RCALL DELAY_5
SBIS PINC,1 ; bit 1 test skip if '1' RJMP NEXT
RJMP UP
RJMP NEXT
DOWN: ; STPEER IS DOWN
LDI R16,0X01
OUT PORTB,R16
RCALL DELAY_5
LDI R16,0X04
OUT PORTB,R16
RCALL DELAY_5
LDI R16,0X02
OUT PORTB,R16
RCALL DELAY_5
LDI R16,0X08
OUT PORTB,R16
RCALL DELAY_5
SBIC PINC,0 ; bit 0 test skip if '0'RJMP NEXT
RJMP DOWN
RJMP NEXT
DELAY_5: LDI R18,0x01
OUTER_LOOP: LDI R24,LOW(0)
LDI R25,HIGH(0) ; R24 and R25 set as 16 bit register (word)
DELAY_LOOP: ADIW R24,04 ; Add immediate word (R25 high R24 low)+4
BRNE DELAY_LOOP ; BRanch if Not Equal (if Equal flag Z=1)
DEC R18 ; R18 = R18-1
BRNE OUTER_LOOP
RET

Questions:
1- Draw a block diagram that illustrates the experiment concept. Show the
following in your plot (Arduino board, stepper motor and the driver
circuit).
2- Explain the difference between (SBIS PINC,0) and (SBIC PINC,1).
3- Explain the following registers PORTD, DDRD, and PIND clearly.
4- Write a program to drive a unipolar Winding stepper motor also draw the circuit.

View publication stats

You might also like