|
StepperII
Dual Axis Stepper Controller
|
00001 00002 #pragma once 00003 00004 #include "CBitio.h" 00005 #include "CStepTimer.h" // Base class 00006 00007 //---------------------------------------------------------------------------- 00008 // 00009 //---------------------------------------------------------------------------- 00010 00011 #ifdef TIMSK3 // Check for processor support 00012 00013 class CTimer3: public CStepTimer 00014 { 00015 private: 00016 // Define Prescale Values 00017 static const char STOPPED = 0; 00018 static const char DIV1 = 1; 00019 static const char DIV8 = 2; 00020 static const char DIV64 = 3; 00021 static const char DIV256 = 4; 00022 static const char DIV1024 = 5; 00023 static const char EXT_FALLING = 6; 00024 static const char EXT_RISING = 7; 00025 00026 static const char prescaleMask = ~(_BV(CS12) | _BV(CS11) | _BV(CS10)); 00027 char prescale; // Save prescale here for on/off 00028 00029 public: 00030 // Legacy I/O 00031 // CBit(B, 1, WO) stepBit; // Define the ouput compare bit 00032 00033 // StepperII I/O DEBUG ONLY!!! Don't run on fully populated board. 00034 //CBit(B, 5, WO) oc1a; // Show OC1A activity 00035 //CBit(B, 6, WO) oc1b; // Show OC1B activity 00036 00037 void init(void); // Initialize for stepper app 00038 inline void on(void); 00039 inline void off(void); 00040 inline void outputEnable(void); 00041 inline void outputDisable(void); 00042 void load(int period); // Load timer interval register 00043 }; 00044 00045 //----------------------------------------------------------------------------- 00046 // on() 00047 // Start the timer 00048 //----------------------------------------------------------------------------- 00049 inline void CTimer3::on(void) 00050 { 00051 // The order of events is important here 00052 // Must call outputEnable() before enabling timer to get proper output 00053 00054 //TCNT3 = 1; // Reset counter 00055 TCNT3 = OCR3B + 5; // Set past OCB 00056 outputEnable(); // Clear and enable int 00057 TCCR3B = (TCCR3B & prescaleMask) | prescale; // Load prescale 00058 } 00059 00060 //----------------------------------------------------------------------------- 00061 // off() 00062 // Stop the timer 00063 //----------------------------------------------------------------------------- 00064 inline void CTimer3::off(void) 00065 { 00066 TCCR3B = (TCCR3B & prescaleMask) | STOPPED; // Stop the clock 00067 outputDisable(); 00068 } 00069 00070 //----------------------------------------------------------------------------- 00071 // outputEnable() 00072 // Enable the output compare B interrupt which generate stepper pulses 00073 //----------------------------------------------------------------------------- 00074 inline void CTimer3::outputEnable(void) 00075 { 00076 TIFR3 |= _BV(OCF3B); // Clear the interrupt request 00077 TIMSK3 |= _BV(OCIE3B); // Enable output compare B interrupt 00078 } 00079 00080 //----------------------------------------------------------------------------- 00081 // outputDisable() 00082 // Disable the output compare B interrupt resulting in no stepper pulses 00083 //----------------------------------------------------------------------------- 00084 inline void CTimer3::outputDisable(void) 00085 { 00086 TIMSK3 &= ~_BV(OCIE3B); // Disable output compare B interrupt 00087 } 00088 00089 #else 00090 #error Processor Not Supported! 00091 #endif 00092
1.7.3