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/13 09:30] – heikopikner | en:examples:motor:stepper [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 57: | Line 57: | ||
| <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 80: | 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 87: | 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 99: | Line 99: | ||
| <code c> | <code c> | ||
| - | // The test program for the stepper motor of the HomeLab. | + | // The test program for the stepper motor of the HomeLab |
| #include < | #include < | ||
| Line 105: | Line 105: | ||
| int main(void) | int main(void) | ||
| { | { | ||
| - | // Set up of the motor. | + | // Set up of the motor |
| unipolar_init(0); | unipolar_init(0); | ||
| - | // Endless loop. | + | // Endless loop |
| while (true) | while (true) | ||
| { | { | ||