This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| et:examples:motors:stepper [2009/06/16 23:18] – raivo.sell | et:examples:motors:stepper [2009/11/04 15:27] (current) – eemaldatud mikk.leini | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Samm-mootorid ====== | ||
| - | ===== Unipolaar samm-mootor ===== | ||
| - | <code c> | ||
| - | |||
| - | </ | ||
| - | |||
| - | ===== Bipolaar samm-mootor ===== | ||
| - | |||
| - | <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); | ||
| - | } | ||
| - | } | ||
| - | </ | ||