This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:motor:stepper [2015/11/12 08:35] – heikopikner | en:examples:motor:stepper [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Stepper motor ====== | ====== Stepper motor ====== | ||
| - | //Necessary knowledge: [HW] [[en: | + | //Necessary knowledge: |
| + | [HW] [[en: | ||
| + | [AVR] [[en: | ||
| + | [LIB] [[en: | ||
| + | [LIB] [[en: | ||
| ===== Theory ===== | ===== Theory ===== | ||
| Line 48: | Line 52: | ||
| ===== Practice ===== | ===== Practice ===== | ||
| + | The Combo Module has a H-bridges to control bipolar stepper motors and the transistor matrix for unipolar stepper motor. | ||
| - | The goal of this exercise is to start a bipolar stepper motor, which can be replaced by unipolar stepper motor using the above described method. | + | There are functions // |
| - | + | ||
| - | There is function | + | |
| <code c> | <code c> | ||
| - | // | + | // Preparing for controlling the bipolar stepper motor |
| - | // Preparing for controlling the bipolar stepper motor. | + | |
| - | // | + | |
| void bipolar_init(void) | void bipolar_init(void) | ||
| { | { | ||
| Line 64: | Line 64: | ||
| } | } | ||
| - | // | + | // Moving the bipolar stepper motor by half steps |
| - | // Moving the bipolar stepper motor by half steps. | + | |
| - | // | + | |
| void bipolar_halfstep(signed char dir, | void bipolar_halfstep(signed char dir, | ||
| unsigned short num_steps, unsigned char speed) | unsigned short num_steps, unsigned char speed) | ||
| Line 82: | Line 80: | ||
| state2 += dir; | state2 += dir; | ||
| - | // Creating the pattern. | + | // Creating the pattern |
| pattern = (1 << ( (state1 % 8) >> 1) ) | | pattern = (1 << ( (state1 % 8) >> 1) ) | | ||
| (1 << ( (state2 % 8) >> 1) ); | (1 << ( (state2 % 8) >> 1) ); | ||
| Line 89: | Line 87: | ||
| PORTB = (PORTB & 0xF0) | (pattern & 0x0F); | PORTB = (PORTB & 0xF0) | (pattern & 0x0F); | ||
| - | // Taking a break to wait for executing the step. | + | // Taking a break to wait for executing the step |
| sw_delay_ms(speed); | sw_delay_ms(speed); | ||
| } | } | ||
| - | // Stopping the motor. | + | // Stopping the motor |
| PORTB &= 0xF0; | PORTB &= 0xF0; | ||
| } | } | ||
| Line 101: | Line 99: | ||
| <code c> | <code c> | ||
| - | // | + | // The test program for the stepper motor of the HomeLab |
| - | // The test program for the bipolar | + | |
| - | // | + | |
| - | // | + | |
| #include < | #include < | ||
| Line 110: | Line 105: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | // Set up of the motor. | + | // Set up of the motor |
| - | bipolar_init(); | + | unipolar_init(0); |
| - | // Endless loop. | + | // Endless loop |
| while (true) | while (true) | ||
| { | { | ||
| // Turning the rotor 200 half steps to one direction | // Turning the rotor 200 half steps to one direction | ||
| // at speed of 30 ms/step. | // at speed of 30 ms/step. | ||
| - | bipolar_halfstep(+1, 200, 30); | + | unipolar_halfstep(0,+1, 2000, 30); |
| // Turning 200 half steps to the other direction | // Turning 200 half steps to the other direction | ||
| // at speed 30 ms/step. | // at speed 30 ms/step. | ||
| - | bipolar_halfstep(-1, 200, 30); | + | unipolar_halfstep(0,-1, 2000, 30); |
| } | } | ||
| } | } | ||
| </ | </ | ||