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

sm_driver.c File Reference


Detailed Description

Stepper motor driver.

Stepper motor driver, increment/decrement the position and outputs the correct signals to stepper motor.

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

Definition in file sm_driver.c.

#include <ioavr.h>
#include "global.h"
#include "sm_driver.h"

Include dependency graph for sm_driver.c:

Include dependency graph

Go to the source code of this file.

Defines

#define BIT_A1   3
#define BIT_A2   2
#define BIT_B1   1
#define BIT_B2   0

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 = 0
 Position of stepper motor.

__flash unsigned char steptab []
 Table with control signals for stepper motor.


Define Documentation

#define BIT_A1   3
 

Definition at line 29 of file sm_driver.c.

#define BIT_A2   2
 

Definition at line 30 of file sm_driver.c.

#define BIT_B1   1
 

Definition at line 31 of file sm_driver.c.

#define BIT_B2   0
 

Definition at line 32 of file sm_driver.c.


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 = 0
 

Position of stepper motor.

Definition at line 45 of file sm_driver.c.

Referenced by main(), and sm_driver_StepCounter().

__flash unsigned char steptab[]
 

Initial value:

{((1<<BIT_A1) | (0<<BIT_A2) | (0<<BIT_B1) | (0<<BIT_B2)), ((1<<BIT_A1) | (0<<BIT_A2) | (1<<BIT_B1) | (0<<BIT_B2)), ((0<<BIT_A1) | (0<<BIT_A2) | (1<<BIT_B1) | (0<<BIT_B2)), ((0<<BIT_A1) | (1<<BIT_A2) | (1<<BIT_B1) | (0<<BIT_B2)), ((0<<BIT_A1) | (1<<BIT_A2) | (0<<BIT_B1) | (0<<BIT_B2)), ((0<<BIT_A1) | (1<<BIT_A2) | (0<<BIT_B1) | (1<<BIT_B2)), ((0<<BIT_A1) | (0<<BIT_A2) | (0<<BIT_B1) | (1<<BIT_B2)), ((1<<BIT_A1) | (0<<BIT_A2) | (0<<BIT_B1) | (1<<BIT_B2))}
Table with control signals for stepper motor.

Definition at line 35 of file sm_driver.c.

Referenced by sm_driver_StepOutput().


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