Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
et:examples:motors:stepper [2009/06/16 23:26] raivo.sellet:examples:motors:stepper [2009/11/04 15:27] (current) – eemaldatud mikk.leini
Line 1: Line 1:
-====== Samm-mootorid ====== 
  
-{{:examples:actuator:stepper.jpg?500|}} 
- 
-===== Ühendustabelid ===== 
-{{:examples:actuator:stepper_table1.jpg|}} 
-{{:examples:actuator:stepper_table_connectionports.jpg|}} 
- 
-===== Unipolaar samm-mootor ===== 
-<code c> 
- 
-</code> 
- 
-===== Bipolaar samm-mootor ===== 
- 
-<code c> 
-/*------------------------------------------------------------- 
-Title: Bipolar stepper motor with Actuator Board 
-Date: 080328 
-Ver.: 1.1 
-Compiler: AVR-GCC 
-Target: ATmega128 
-Hardware: Actuator board, bipolar stepper 
-Author: Maido Hiiemaa / Raivo Sell 2008 
- 
-Notes: Optimization -02 
-Description: Drives stepper in both directions by 100 steps 
----------------------------------------------------------------*/ 
-#define STEPDELAY (50) // one step delay 
-#include <avr/io.h> 
-#include <util/delay.h> 
- 
-//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); 
- 
-///////////////// Functions ////////////////////////////////// 
-void bipolar_clockwise(int number_of_steps){ 
- int i; 
- for (i=0; i<number_of_steps; i++){ //repeat for each step 
- bipolar_pattern = bipolar_pattern << 1; 
- //shift pattern to the left 
- if (bipolar_pattern>8){ bipolar_pattern=1; } 
- // alter b'10000' to b'0001' if needed 
- PORTB &= 0xF0; //zero last output (low bits) 
- PORTB |= bipolar_pattern; //apply new pattern 
- _delay_ms (STEPDELAY); //wait for the motor to complete the step 
- } 
- PORTB &= 0xF0; //turn off motor 
-} 
- 
-void bipolar_counter_clockwise(int number_of_steps){ 
- int i; 
- for (i=0; i<number_of_steps; i++){//repeat for each stepbipolar_pattern = bipolar_pattern >> 1; 
- //shift pattern to the right 
- bipolar_pattern = bipolar_pattern >> 1; 
- if (bipolar_pattern==0) { bipolar_pattern=8; } 
- //alter b'0000' to b'1000' if needed 
- PORTB &= 0xF0; //clear low bits 
- PORTB |= bipolar_pattern; //apply pattern to output 
- _delay_ms (STEPDELAY); //wait for the motor to complete the step 
- } 
- PORTB &= 0xF0;//turn off motor 
-} 
-///////////////// Main function ////////////////////////////////// 
-int main(void){ 
-//output ports initialization 
- DDRB=0xFF; //output port for bipolar stepper drive signals 
- PORTB=0; //initial PORTB output 
- bipolar_pattern=0x01; //initial pattern for bipolar stepper 
- 
- while(1){ 
- bipolar_clockwise(100); 
- bipolar_counter_clockwise(100); 
- } 
-} 
-</code> 
et/examples/motors/stepper.1245183984.txt.gz · Last modified: (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0