Arduino and Stepper Motor
Arduino and Stepper Motor
net/publication/334899187
CITATIONS READS
0 664
1 author:
SEE PROFILE
All content following this page was uploaded by Marwan Abdulkhaleq Al-Yoonus on 02 August 2019.
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.
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.
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.