Mini Project- Stepper Motor Control
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
Uploaded on

The following resources come from the 2009/10 BEng in Digital Systems and Computer Engineering (course number 2ELE0065) from the University of Hertfordshire. All the mini projects are designed as......

The following resources come from the 2009/10 BEng in Digital Systems and Computer Engineering (course number 2ELE0065) from the University of Hertfordshire. All the mini projects are designed as level two modules of the undergraduate programmes.

The objectives of this project are to design, develop and test software for an embedded system that will smoothly control the rotation of a stepper motor, taking into account the physical constraints on the maximum operating speed of the motor.
Each student will be required to design a ‘C’ program can rotate a stepper motor to a number of user-defined positions as quickly as possible. This will include sensing of the marker pulse, the implementation of an appropriate speed profile and the use of timer-generated interrupts.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,428
On Slideshare
7,403
From Embeds
25
Number of Embeds
3

Actions

Shares
Downloads
278
Comments
0
Likes
2

Embeds 25

http://www.slideshare.net 20
http://translate.googleusercontent.com 3
http://www.slashdocs.com 2

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mini Project - Stepper Motor Control Author: University of Hertfordshire Date created: Date revised: 2009 Abstract The following resources come from the 2009/10 BEng in Digital Systems and Computer Engineering (course number 2ELE0065) from the University of Hertfordshire. All the mini projects are designed as level two modules of the undergraduate programmes. The objectives of this project are to design, develop and test software for an embedded system that will smoothly control the rotation of a stepper motor, taking into account the physical constraints on the maximum operating speed of the motor. Each student will be required to design a ‘C’ program can rotate a stepper motor to a number of user-defined positions as quickly as possible. This will include sensing of the marker pulse, the implementation of an appropriate speed profile and the use of timer-generated interrupts. In addition to the resources found below there are supporting documents which should be used in combination with this resource. Please see: Mini Projects - Introductory presentation. Mini Projects - E-Log. Mini Projects - Staff & Student Guide. Mini Projects - Standard Grading Criteria. Mini Projects - Reflection. You will also need the ‘Mini Project- Stepper Motor Control’ text document. This work is licensed under a Creative Commons Attribution 2.0 License .
  • 2. Contents
    • Overall Aim 3
    • The Hardware You Will Use 5
    • Signals 6
    • Timing Diagram 7
    • Timing of Index Pulses 8
    • Setting a Bit 9
    • Bitwise Boolean Functions 10
    • Setting a Single Bit (OR) 11
    • Setting Multiple Bits 12
    • Clearing Bits (AND) 13
    • Toggling Bits (XOR) 14
    • Testing if a Bit is Set 15
    • Testing if a Bit is Clear 16
    • Waiting for a Bit to Clear 17
    • Waiting for a Bit to Set 18
    • Using #define 19
    • Structure Charts with Functions 20
    • Preparation 21
    • Credits 22
  • 3. Overall Aim
    • To use the 68000 microprocessor to generate signals to drive a stepper motor.
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 4. BH Mar 09 DSCE Miniproject - Stepper Motors Stepper motors are motors which are designed to produce a defined angle of rotation for each input pulse applied. Thus, the speed of rotation is proportional to the frequency of the input signal (unlike, for example, a dc motor where the speed is approximately proportional to the input voltage). They are very useful in open loop control situations, particularly for controlling output position. They are also used in closed loop position control applications where an approximate output position can be attained very quickly.
  • 5. The Hardware You Will Use BH Mar 09 DSCE Miniproject - Stepper Motors
  • 6. Signals
    • Inputs :
      • Step: One step movement is generated for each negative edge of the step signal.
      • Direction: Logic ‘1’ for anticlockwise movement. Logic ‘0’ for clockwise.
      • Half Step Mode: Logic ‘1’ for full step and logic ‘0’ for half step mode.
      • 4 LEDs show the step sequence driving the motor.
      • Inhibit: Logic ‘1’ to Inhibit driver IC and logic ‘0’ to enable driver IC / module.
    • Outputs:
      • Segment pulse : Optical sensors detect each segment / number and produce a logic ‘1’ pulse accordingly.
      • Index Pulse : Logic ‘1’ output when disc rotates to alignment with number 1 as shown above.
      • LEDs indicate the pulse outputs.
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 7. Timing Diagram BH Mar 09 DSCE Miniproject - Stepper Motors
  • 8. Timing of Index Pulses BH Mar 09 DSCE Miniproject - Stepper Motors
  • 9. Setting a Bit
    • Assume the port is declared as a “char” variable named “portA”
    • What ‘C’ instruction would set bit 0?
    • Try:
      • portA = 0x01;
    • What happens to the rest of the bits?
    • We need to be able to change bit 0 only
    • We need boolean functions
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 10. Bitwise Boolean Functions BH Mar 09 DSCE Miniproject - Stepper Motors OR (x|y) x bit 0 0 1 1 y bit 0 1 0 1 result 0 1 1 1 AND (x&y) x bit 0 0 1 1 y bit 0 1 0 1 result 0 0 0 1 XOR (x^y) x bit 0 0 1 1 y bit 0 1 0 1 result 0 1 1 0
  • 11. Setting a Single Bit (OR)
    • Which boolean function can we use?
    • To set bit 0, we could use: portA = portA | 0x01;
    • or
    • portA |= 0x01;
    • The constant “0x01” is known as a “bit mask”
    • What bit mask would you use to set bit 6 of portA?
    BH Mar 09 DSCE Miniproject - Stepper Motors x indicates “any value” portA x x x x x x x x 0x01 0 0 0 0 0 0 0 1 result x x x x x x x 1
  • 12. Setting Multiple Bits
    • Bit masks can also be used to set more than one bit in a single instruction
    • For example
    • portA |= 0x82;
    • sets bits 7 and 1
    • How would you set bits 7,5 and 3?
    BH Mar 09 DSCE Miniproject - Stepper Motors portA x x x x x x x x 0x82 1 0 0 0 0 0 1 0 result 1 x x x x x 1 x
  • 13. Clearing Bits (AND)
    • To clear bit 4, use:
    • portA = portA & 0xEF;
    • or
    • portA &= 0xEF;
    • The bit mask should have all bits set except the bit(s) you want to clear
    • How would you clear bits 5,3 and 2?
    BH Mar 09 DSCE Miniproject - Stepper Motors portA x x x x x x x x 0xEF 1 1 1 0 1 1 1 1 result x x x 0 x x x x
  • 14. Toggling Bits (XOR)
    • To change the value of bit 7, use
    • portA = portA ^ 0x80;
    • or
    • portA ^= 0x80;
    BH Mar 09 DSCE Miniproject - Stepper Motors or portA 1 x x x x x x x 0x80 1 0 0 0 0 0 0 0 result 0 x x x x x x x portA 0 x x X x x x x 0x80 1 0 0 0 0 0 0 0 result 1 x x x x x x x
  • 15. Testing if a Bit is Set
    • Use a bit mask to look at a single bit
    • For example, portA & 0x02 gives a value of:
      • 0x02 if bit 1 of portA is set
      • 0x00 if bit 1 of portA is clear
    • So we can say:
    • if ((portA & 0x02)!=0) /* bit 1 set */
    • printf(“bit 1 is set ”);
    • Take care over the brackets
    • Could also say:
    • if(portA & 0x02) /* bit 1 set */
    • printf(“bit 1 is set”);
    • because ‘C’ treats all non-zero values as ‘true’ (and zero values as false)
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 16. Testing if a Bit is Clear
    • As before, we’d use a bit mask to select a single bit, but negate the condition.
    • To check if bit 4 is clear:
    • if((portA&0x10)==0) /* bit 4 clear */
    • printf(“bit 4 clear”);
    • or
    • if(!(portA&0x10)) /* bit 4 clear */
    • printf(“bit 4 clear”);
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 17. Waiting for a Bit to Clear
    • Sometimes we need to set a bit and then wait until an external device clears the bit.
    • For example:
    • /* set bit 6 */
    • portA |= 0x40;
    • /* wait for bit 6 to clear */
    • while ((portA &0x40)!=0);
    • Note the use of a while statement that does nothing but wait
    • The ‘while’ statement could be shortened to:
    • while(portA&0x40);
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 18. Waiting for a Bit to Set
    • To clear a bit and wait until it is set:
    • /* clear bit 7 */
    • portA &= 0x7F;
    • /* wait for bit 7 to be set */
    • while ((portA & 0x80)==0);
    • The “while” statement could be shortened to:
    • while(!(portA&0x80));
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 19. Using #define
    • Easier to read (and modify) if you use #define for bitmasks
    • #define SETBIT3 0x04
    • portA |= SETBIT3;
    • /* wait for bit 3 to clear */
    • while (portA &SETBIT3);
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 20. Structure Charts with Functions BH Mar 09 DSCE Miniproject - Stepper Motors main celsius_to_fahrenheit output_temp fahrenheit get_celsius celsius celsius fahrenheit use the variable names from the calling functions shows that a parameter has been passed to a function shows that a value has been returned from a function
  • 21. Preparation
    • Define Resource Map for the stepper motor
    • Design, implement and test ‘C’ functions to read or write all of the signals that you will be using to control the stepper motor.
    BH Mar 09 DSCE Miniproject - Stepper Motors
  • 22. This resource was created by the University of Hertfordshire and released as an open educational resource through the Open Engineering Resources project of the HE Academy Engineering Subject Centre. The Open Engineering Resources project was funded by HEFCE and part of the JISC/HE Academy UKOER programme. © University of Hertfordshire 2009                  This work is licensed under a Creative Commons Attribution 2.0 License . The name of the University of Hertfordshire, UH and the UH logo are the name and registered marks of the University of Hertfordshire. To the fullest extent permitted by law the University of Hertfordshire reserves all its rights in its name and marks which may not be used except with its written permission. The JISC logo is licensed under the terms of the Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales Licence.  All reproductions must comply with the terms of that licence. The HEA logo is owned by the Higher Education Academy Limited may be freely distributed and copied for educational purposes only, provided that appropriate acknowledgement is given to the Higher Education Academy as the copyright holder and original publisher.