Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

sm_driver.h File Reference


Detailed Description

Header file for sm_driver.c.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
RELEASE_1_0
Revision
1.2
RCSfile
sm_driver.h,v
Date
2006/05/08 12:25:58

Definition in file sm_driver.h.

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define A1   PD7
 Stepper motor winding A positive pole.

#define A2   PD6
 Stepper motor winding A negative pole.

#define B1   PD5
 Stepper motor winding B positive pole.

#define B2   PD4
 Stepper motor winding B negative pole.

#define CCW   1
#define CW   0
#define HALFSTEPS
#define SM_DRIVE   DDRD
#define SM_PORT   PORTD

Functions

void sm_driver_Init_IO (void)
 Init of io-pins for stepper motor.

unsigned char sm_driver_StepCounter (signed char inc)
 Move the stepper motor one step.

void sm_driver_StepOutput (unsigned char pos)
 Convert the stepcounter value to signals for the stepper motor.


Variables

int stepPosition
 Position of stepper motor.


Define Documentation

#define A1   PD7
 

Stepper motor winding A positive pole.

Definition at line 43 of file sm_driver.h.

Referenced by sm_driver_Init_IO().

#define A2   PD6
 

Stepper motor winding A negative pole.

Definition at line 44 of file sm_driver.h.

Referenced by sm_driver_Init_IO().

#define B1   PD5
 

Stepper motor winding B positive pole.

Definition at line 45 of file sm_driver.h.

Referenced by sm_driver_Init_IO().

#define B2   PD4
 

Stepper motor winding B negative pole.

Definition at line 46 of file sm_driver.h.

Referenced by sm_driver_Init_IO().

#define CCW   1
 

Definition at line 26 of file sm_driver.h.

Referenced by sm_driver_StepCounter(), and speed_cntr_Move().

#define CW   0
 

Definition at line 25 of file sm_driver.h.

Referenced by speed_cntr_Move().

#define HALFSTEPS
 

Define stepping mode to use in stepper motor.

Either halfsteps (HALFSTEPS) or fullsteps (FULLSTEPS) are allowed.

Definition at line 33 of file sm_driver.h.

#define SM_DRIVE   DDRD
 

Definition at line 42 of file sm_driver.h.

Referenced by sm_driver_Init_IO().

#define SM_PORT   PORTD
 

Define IO port and pins

Set the desired drive port and pins to support your device

Definition at line 41 of file sm_driver.h.

Referenced by sm_driver_Init_IO(), and sm_driver_StepOutput().


Function Documentation

void sm_driver_Init_IO void   ) 
 

Init of io-pins for stepper motor.

Definition at line 49 of file sm_driver.c.

References A1, A2, B1, B2, SM_DRIVE, and SM_PORT.

Referenced by Init().

00050 { 00051 // Init of IO pins 00052 SM_PORT &= ~((1<<A1) | (1<<A2) | (1<<B1) | (1<<B2)); // Set output pin registers to zero 00053 SM_DRIVE |= ((1<<A1) | (1<<A2) | (1<<B1) | (1<<B2)); // Set output pin direction registers to output 00054 }

unsigned char sm_driver_StepCounter signed char  inc  ) 
 

Move the stepper motor one step.

Makes the stepcounter inc/dec one value and outputs this to the steppermotor. This function works like a stepper motor controller, a call to the function is the stepping pulse, and parameter 'inc' is the direction signal.

Parameters:
inc Direction to move.
Returns:
Stepcounter value.

Definition at line 66 of file sm_driver.c.

References CCW, sm_driver_StepOutput(), and stepPosition.

Referenced by speed_cntr_TIMER1_COMPA_interrupt().

00067 { 00068 // Counts 0-1-...-6-7 in halfstep, 0-2-4-6 in fullstep 00069 static unsigned char counter = 0; 00070 // Update 00071 if(inc == CCW){ 00072 stepPosition--; 00073 } 00074 else{ 00075 stepPosition++; 00076 } 00077 00078 #ifdef HALFSTEPS 00079 if(inc){ 00080 counter++; 00081 } 00082 else{ 00083 counter--; 00084 } 00085 #else 00086 if(inc){ 00087 counter += 2; 00088 } 00089 else{ 00090 counter -= 2; 00091 } 00092 #endif 00093 00094 // Stay within the steptab 00095 counter &= 0x07; 00096 sm_driver_StepOutput(counter); 00097 return(counter); 00098 }

Here is the call graph for this function:

void sm_driver_StepOutput unsigned char  pos  ) 
 

Convert the stepcounter value to signals for the stepper motor.

Uses the stepcounter value as index in steptab to get correct steppermotor control signals. Converts these signals to work with the stepper driver hardware.

Parameters:
pos Stepcounter value.

Definition at line 108 of file sm_driver.c.

References SM_PORT, and steptab.

Referenced by Init(), and sm_driver_StepCounter().

00109 { 00110 unsigned char temp = steptab[pos]; 00111 00112 /* 00113 // Output bit by bit 00114 if(temp&(1<<BIT_A1)) 00115 SM_PORT |= (1<<A1); 00116 else 00117 SM_PORT &= ~(1<<A1); 00118 00119 if(temp&(1<<BIT_A2)) 00120 SM_PORT |= (1<<A2); 00121 else 00122 SM_PORT &= ~(1<<A2); 00123 00124 if(temp&(1<<BIT_B1)) 00125 SM_PORT |= (1<<B1); 00126 else 00127 SM_PORT &= ~(1<<B1); 00128 00129 if(temp&(1<<BIT_B2)) 00130 SM_PORT |= (1<<B2); 00131 else 00132 SM_PORT &= ~(1<<B2); 00133 */ 00134 00135 // Output the fast way 00136 SM_PORT |= ((temp<<4)&0xF0); 00137 SM_PORT &= ((temp<<4)|0x0F); 00138 }


Variable Documentation

int stepPosition
 

Position of stepper motor.

Definition at line 53 of file sm_driver.h.

Referenced by main(), and sm_driver_StepCounter().


Generated on Mon May 8 15:05:04 2006 for AVR446 - Linear speed control of stepper motor by doxygen 1.3.7