This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:motors:stepper [2009/04/01 14:02] – raivo.sell | en:examples:motors:stepper [2010/02/04 12:30] (current) – removed mikk.leini | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Stepper motor ====== | ||
| - | Stepper motors can very generally be divided into unipolar and bipolar steppers. | ||
| - | Unipolar stepper motors are characterized by their centre-tapped windings, which | ||
| - | divide two coils into four. Stepper motors have neither built-in brushes nor internal | ||
| - | electronics, | ||
| - | common commutation type is the open-loop mode: the motor driver energizes the | ||
| - | coils following a certain pattern, but uses no feedback. Steps can be missed in case of | ||
| - | motor shaft torque overload. Missed steps cause inaccurate positioning. Bipolar | ||
| - | stepper motors usually have four wires and two separate coils inside; they have many | ||
| - | features similar to those of unipolar steppers. Unipolar stepper motors can be run as | ||
| - | bipolar stepper motors, but not vice versa. | ||
| - | |||
| - | ===== Electrical connections ===== | ||
| - | |||
| - | Table of stepper motor windings. | ||
| - | |||
| - | ^ Pin ^ Unipolar winding ^ UP PORT ^ Bipolar winding ^BP PORT ^ | ||
| - | | 1 | a | ||
| - | | 2 | b | ||
| - | | 3 | 1a | PE0/ | ||
| - | | 4 | 2a | PE1/ | ||
| - | | 5 | 1b | PE2/ | ||
| - | | 6 | 2b | PE3/ | ||
| - | |||
| - | |||
| - | - Make sure all power is off. | ||
| - | - Connect the actuator board and main board with a 26-pin cable. | ||
| - | - Connect the stepper to the actuator board, as shown in Figure. Note: The unipolar motor cable must be properly connected (wires a and b, according to figure 1, connects to pin 1 and 2 on connector UNI1 or UNI2). | ||
| - | - Connect the JTAG converter with the ATmega128 main board and the PC. | ||
| - | - Finally, connect the power to the main and actuator boards. | ||
| - | |||
| - | {{: | ||
| - | |||
| - | ===== Test programs ===== | ||
| - | |||
| - | {{: | ||
| - | |||
| - | ===== Example code ===== | ||
| - | |||
| - | <code c> | ||
| - | / | ||
| - | Title: | ||
| - | Date: | ||
| - | Ver.: 1.1 | ||
| - | Compiler: | ||
| - | Target: | ||
| - | Hardware: | ||
| - | Author: Maido Hiiemaa / Raivo Sell 2008 | ||
| - | |||
| - | Notes: | ||
| - | Description: | ||
| - | ---------------------------------------------------------------*/ | ||
| - | #define STEPDELAY (50) // one step delay | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | //global variables to store commutation patterns | ||
| - | static unsigned char bipolar_pattern; | ||
| - | |||
| - | //Function prototypes | ||
| - | void bipolar_clockwise(int number_of_steps); | ||
| - | void bipolar_counter_clockwise(int number_of_steps); | ||
| - | |||
| - | ///////////////// | ||
| - | void bipolar_clockwise(int number_of_steps){ | ||
| - | int i; | ||
| - | for (i=0; i< | ||
| - | bipolar_pattern = bipolar_pattern << 1; | ||
| - | //shift pattern to the left | ||
| - | if (bipolar_pattern> | ||
| - | // alter b' | ||
| - | PORTB &= 0xF0; //zero last output (low bits) | ||
| - | PORTB |= bipolar_pattern; | ||
| - | _delay_ms (STEPDELAY); | ||
| - | } | ||
| - | PORTB &= 0xF0; //turn off motor | ||
| - | } | ||
| - | |||
| - | void bipolar_counter_clockwise(int number_of_steps){ | ||
| - | int i; | ||
| - | for (i=0; i< | ||
| - | //shift pattern to the right | ||
| - | bipolar_pattern = bipolar_pattern >> 1; | ||
| - | if (bipolar_pattern==0) { bipolar_pattern=8; | ||
| - | //alter b' | ||
| - | PORTB &= 0xF0; //clear low bits | ||
| - | PORTB |= bipolar_pattern; | ||
| - | _delay_ms (STEPDELAY); | ||
| - | } | ||
| - | PORTB &= 0xF0;//turn off motor | ||
| - | } | ||
| - | ///////////////// | ||
| - | int main(void){ | ||
| - | //output ports initialization | ||
| - | DDRB=0xFF; //output port for bipolar stepper drive signals | ||
| - | PORTB=0; //initial PORTB output | ||
| - | bipolar_pattern=0x01; | ||
| - | |||
| - | while(1){ | ||
| - | bipolar_clockwise(100); | ||
| - | bipolar_counter_clockwise(100); | ||
| - | } | ||
| - | } | ||
| - | |||
| - | |||
| - | </ | ||