Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Fundamentals of Microcontrollers: Stepper Motor Control with Sequential Access to Memory -, Study notes of Mechanical Engineering

The use and control of stepper motors, discussing stepper motor energizing patterns, creating quasi-continuous motion, and sequential accessing of stored patterns. It also illustrates loading a single-precision variable into a double precision register and automatic incrementation/decrementation of the addressing pointer. An example from a microcontrollers course.

Typology: Study notes

Pre 2010

Uploaded on 10/01/2009

koofers-user-mea-1
koofers-user-mea-1 🇺🇸

4

(1)

10 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EMCH 367 Fundamentals of Microcontrollers Example STEP
EXAMPLE STEP
OBJECTIVE
This example has the following objectives:
Review the use and control of stepper motors.
Discuss the stepper motor energizing patterns, 1- and 2-phase energizing types, full- and half-
step motion.
Introduce the concept of creating quasi-continuous motion through a sequence of steps
Introduce the concept of sequential accessing a finite set of stored patterns through index
addressing with a continuously updating pointer.
Illustrate a method to ‘load’ a single-precision (2-hex) variable into a double precision (4-hex)
register.
Introduce the concept of automatic incrementation/decrementation of the addressing pointer
with a programmable step size
Discuss the reset actions to be taken when the pointer hits the ‘ceiling’ or ‘floor’.
8-pin input
connector
Controller board
Stepper motor
Figure 1 Stepper motor and its controller board. Control signals to the controller board are sent
through the 8-pin input connector.
PROGRAM EX_STEP
This program is to be used for stepper motor control (Figure 1). A stepper motor is controlled by
sending a binary pattern to its controller board. Eight distinct binary patterns are recognized by the
stepper motor controller board in your lab. They are given in Table 1 as sequences S0 S7. The
Dr. Victor Giurgiutiu Page 112/1/2020
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Fundamentals of Microcontrollers: Stepper Motor Control with Sequential Access to Memory - and more Study notes Mechanical Engineering in PDF only on Docsity!

EXAMPLE STEP

OBJECTIVE

This example has the following objectives:  Review the use and control of stepper motors.  Discuss the stepper motor energizing patterns, 1- and 2-phase energizing types, full- and half- step motion.  Introduce the concept of creating quasi-continuous motion through a sequence of steps  Introduce the concept of sequential accessing a finite set of stored patterns through index addressing with a continuously updating pointer.  Illustrate a method to ‘load’ a single-precision (2-hex) variable into a double precision (4-hex) register.  Introduce the concept of automatic incrementation/decrementation of the addressing pointer with a programmable step size  Discuss the reset actions to be taken when the pointer hits the ‘ceiling’ or ‘floor’. 8 - pin input connector Controller board Stepper motor Figure 1 Stepper motor and its controller board. Control signals to the controller board are sent through the 8-pin input connector.

PROGRAM EX_STEP

This program is to be used for stepper motor control (Figure 1). A stepper motor is controlled by sending a binary pattern to its controller board. Eight distinct binary patterns are recognized by the stepper motor controller board in your lab. They are given in Table 1 as sequences S0 – S7. The

stepper motor has four distinct coils, and a 1 in the energizing pattern signifies that the corresponding coil is energized. Note that in the even sequences (S0, S2, S4, S6) only one bit in the energizing pattern is set. This indicates that only one out of the four stepper-motor coils (1 phase) is energized. On the other hand, in the odd sequences (S1, S3, S5, S7), two bit are set, i.e., two coils (2 phases) are energized. The sequences with two coils energized are labeled full step , while those with only one coil energized are labeled half step. Table 1 Stepper motor energizing patterns and their 2-hex equivalent value Sequence Energizing pattern 8-bit 2-hex equivalence Phase energizing type Step type S0 1000 $08 1 phase Half step S1 1001 $09 2 phase Full step S2 0001 $01 1 phase Half step S3 0101 $05 2 phase Full step S4 0100 $04 1 phase Half step S5 0110 $06 2 phase Full step S6 0010 $02 1 phase Half step S7 1010 $0A 2 phase Full step When these patterns are hit in increasing order, one after the other, the motion is called ‘half speed forward’. If only the odd sequences are hit, i.e., every second pattern is hit, the motion is ‘full speed forward’. If the patterns are hit in decreasing order, the motion is, respectively, ‘half-speed backward’ and ‘full speed backward’ (Table 2). Table 2 Stepper motor speed definitions Step Start Full speed forward +2 Even pattern Half speed forward +1 Anywhere Half-speed backward -1 Anywhere Full speed backward -2 Even pattern To control a stepper motor, a parallel port is used to send 8-bit pattern to the stepper-motor control board. Note the pin assignment: MSB LSB N/A N/A N/A N/A

I

(white)

I

(green)

I

(gray)

I

(yellow) The program illustrates the sequentially access to memory locations using a memory pointer:

Define variables START  Load POINTER to accB  Add STEP SWI  Load $0000 into Y  Add accB to Y (acc B contains the value of POINTER)  S0 1 byte  S1 1 byte  S2 1 byte  S3 1 byte  S4 1 byte  S5 1 byte  S6 1 byte  S7 1 byte  STEP 1 byte  POINTER 1 byte Big-picture Flowchart (^) Flowchart Details Initialize Below ceiling? Reset to floor Y N Reset to ceiling Y N LABEL0^ Call S/R STEP_SR RTS STEP_SR BRA LABEL LABEL Above floor? Store new value of POINTER  Load new sequence code into accA using Y  Send sequeuce code from accA to Port B Put POINTER into Y POINTER  7? 0 POINTER? POINTER= POINTER=  X=REGBAS  S0=$  S1=$  S2=$  S3=$  S4=$  S5=$  S6=$  S7=$0a  STEP=$  POINTER=$ Code

  • Define program variables ORG DATA S0 RMB 1 S1 RMB 1 S2 RMB 1 S3 RMB 1 S4 RMB 1 S5 RMB 1 S6 RMB 1 S7 RMB 1 STEP RMB 1 POINTERRMB 1 *Main program ORG PROGRAM START LDX #REGBAS LDAA #$ STAA S LDAA #$ STAA S LDAA #$ STAA S LDAA #$ STAA S LDAA #$ STAA S LDAA #$ STAA S LDAA #$ STAA S LDAA #$0A STAA S
  • Initialize controls LDAA # STAA STEP LDAA #$ STAA POINTER
  • Start looping LABEL0 JSR STEP_SR BRA LABEL SWI
  • Step subroutine STEP_SR LDAB POINTER ADDB STEP CMPB # BLE LABEL LDAB # LABEL3 CMPB # BGE LABEL LDAB # LABEL4 STAB POINTER LDY #$ ABY LDAA $00,Y STAA PORTB,X RTS

EXECUTION

Open THRSim11. Close the Commands window. View CPU registers AND memory list. Open and assemble Ex_Step.asm. Set breakpoint at SWI. Reset registers. Press the RESET button. Set standard labels (Label/Set Standard Labels). Set breakpoint at LABEL0 and at SWI. Arrange windows for maximum benefit: Your screen should look like this:

CASE ‘SLOW-FORWARD’ (STEP=$01)

a) Put STEP=$01. This should make the program go forward in increments of one (half-speed forward). Your screen should look like this:

b) Step through the program. Notice that the program goes directly to the subroutine STEP_SR. The following events happen:  The current value of the variable POINTER (POINTER=$00) is loaded into accB.  The value of variable STEP (STEP=$01) is added to accB. The result is accB = $  The value in accB is compared with the ceiling (i.e., perform accB-$07). The result of the comparison is a negative number. Hence, the condition code bit N is set (observe N=1 on the simulator status bar, and bit 3 = 1 in CC register). Your screen looks like this:

 At branch BGE LABEL4, the branch condition is met (since N=0) and the program branches to LABEL4.  The value of accB is stored as the new value of POINTER (observe POINTER at memory location $0009 having the value $01)  At this stage, the value of POINTER must be loaded into index register Y. To achieve this, the value $0000 is loaded in index register Y. Then, the index register Y and the accB (containing the current value of POINTER) are added. (This convoluted way of doing things was needed because there is no simple way to load the single precision variable, POINTER, into the double precision register Y.) Your screen looks like this:

 The value of the memory where the POINTER points to is now loaded into accA. This is achieved using index addressing with Y as the index register and $00 as the offset (i.e., LDAA $00,Y). In our case, POINTER=$01, hence the memory location $0001 is loaded. This is the step S1, which has the value S1=$09. Hence, you should see the value $09 in accA (i.e., A $09 in CPU registers). Finally, the pattern S1, which was loaded in accA, is sent to Port B. This will make the stepper motor go to the position corresponding to pattern S1. Your program looks like this: c) Let your program perform another loop and observe that the POINTER and the value in Port B have reached the next sequence pattern, S2=$01. Your screen should look like this:

e) In the next loop, the program should hit the ceiling and return to the floor. Perform this loop manually, to verify the logic. At the end of the loop, observe that the POINTER and the value in Port B have come back to the first sequence pattern, S0=$08. Your screen should look like this:

CASE ‘FULL-FORWARD’ (STEP=$02)

Press RESET button. Run initialization. Put the value $02 into the variable STEP and $07 into variable POINTER. Repeat the pattern of observations covered before. You will see that only the odd patterns (S1, S3, S5, S7) are being hit. According to Table 1, these patterns correspond to 2- phase energizing of the stepper motor (full steps). Satisfy yourself that you fully understand the logic of the program and that you have fully observed how the program is generating a full-speed forward motion.

CASE ‘HALF-BACKWARD’ (STEP=$FF)

Put the value $ff into the variable STEP and repeat the pattern of observations covered before. You will see all the patterns (S0--S7) being hit, but in reverse order (S1, S0, S7, S6, S5, S4, S3, S2, S1 …). Satisfy yourself that you fully understand the logic of the program and that you have fully observed how the program is generating a half-speed backward motion.

CASE ‘FULL-BACKWARD (STEP=$FE)

Put the value $fe into the variable STEP and repeat the pattern of observations covered before. You will see that only the odd patterns are being hit, and that they are hit in reverse order (S1, S7, S5, S3, S1, …). Satisfy yourself that you fully understand the logic of the program and that you have fully observed how the program is generating a full-speed backward motion.

(This page is left intentionally blank)