|
StepperII
Dual Axis Stepper Controller
|
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00023 #pragma once 00024 00030 // Timer/Counter 1 running on 3,686MHz / 8 = 460,75kHz (2,17uS). (T1-FREQ 460750) 00031 //#define T1_FREQ 460750 00032 // Timer1 16MHz / 8 00033 #define T1_FREQ (2000000L) 00034 00036 #define FSPR 200 // 1.8 deg/step motor 00037 #define SPR (FSPR * 2) // 2x microstepping 00038 00039 // Maths constants. To simplify maths when calculating in speed_cntr_Move(). 00040 #define ALPHA (1.0 / SPR) // 1 rev/spr 00041 #define A_T_x100 ((long)(ALPHA * T1_FREQ * 100)) // (ALPHA / T1_FREQ)*100 00042 #define T1_FREQ_148 ((int)((T1_FREQ *0.676) / 100)) // divided by 100 and scaled by 0.676 00043 #define A_SQ (long)(ALPHA * 2 * 100000000) // ALPHA*2*10000000000 00044 #define A_x20000 ((int)(ALPHA * 20000)) // ALPHA*20000 00045 00052 class CAvrStepper 00053 { 00054 #if 0 00055 public: // Should be private! KJD 00056 // Speed ramp states 00057 static const char STOP = 0; 00058 static const char ACCEL = 1; 00059 static const char DECEL = 2; 00060 static const char RUN = 3; 00061 static const char NEED_INIT = 4; 00062 static const char STOPPING = 5; 00063 #endif 00064 // Direction of stepper motor movement 00065 private: 00066 volatile unsigned char runState; 00067 unsigned int stepDelay; // Period of next timer delay 00068 unsigned char continuousFlag; // Set flag for continuous run 00069 // At start this value set the accelration rate. 00070 unsigned int decelStart; // What step_pos to start decelaration 00071 int decelVal; // Sets deceleration rate. 00072 unsigned int minDelay; // Minimum time delay (max speed) 00073 int accelCount; // Counter used when accel/decel 00074 // to calculate step_delay. 00075 unsigned int stepCount; // Counting steps in accel/decel modes 00076 unsigned int runCount; // Counting steps in run mode 00077 int lastStepCount; // When I want to know how many steps took place 00078 int lastRunCount; // For debug right now. 00079 unsigned int maxSpeedLimit; // Number of steps before max speed. 00080 unsigned int remainder; // Remainder from nextPeriod() to incrase accurancy 00081 private: 00082 CProfile *profile; // Reference to axis profile 00083 void nextPeriod(void); // Calculates stepDelay for next step 00084 unsigned long squareRoot(unsigned long x); // Calculates long square root 00085 public: 00086 void setProfile(CProfile *profile); 00087 void move(int step); 00088 void doStep(void); 00089 void changeSpeed(CProfile &profile); 00090 void setContinuous(unsigned int x); 00091 char readRunState(void); 00092 }; 00093 00094 inline void CAvrStepper::setProfile(CProfile *profile) 00095 { 00096 this->profile = profile; 00097 } 00098 00099 inline char CAvrStepper::readRunState(void) 00100 { 00101 return runState; 00102 } 00103 00104 inline int CAvrStepper::readLastStepCount(void) 00105 { 00106 return lastStepCount; 00107 } 00108 00109 inline int CAvrStepper::readLastRunCount(void) 00110 { 00111 return lastRunCount; 00112 } 00113
1.7.3