StepperII
Dual Axis Stepper Controller

CTimer1.h

00001 
00002 #pragma once
00003 
00004 #include "CBitio.h"
00005 #include "CStepTimer.h"         // Base class
00006 
00007 //----------------------------------------------------------------------------
00008 //
00009 //----------------------------------------------------------------------------
00010 
00011 #ifdef TIMSK1   // Check for processor support
00012 
00013 class CTimer1: 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 CTimer1::on(void)
00050 {
00051         TCNT1 = 1;                                                      // Reset counter
00052         TCCR1B = (TCCR1B & prescaleMask) | prescale;    // Load prescale
00053 }
00054 
00055 //-----------------------------------------------------------------------------
00056 // off()
00057 //      Stop the timer
00058 //-----------------------------------------------------------------------------
00059 inline void CTimer1::off(void)
00060 {
00061         TCCR1B = (TCCR1B & prescaleMask) | STOPPED;             // Stop the clock
00062 }
00063 
00064 //-----------------------------------------------------------------------------
00065 // outputEnable()
00066 //      Enable the output compare B interrupt which generate stepper pulses
00067 //-----------------------------------------------------------------------------
00068 inline void CTimer1::outputEnable(void)
00069 {
00070         //TIFR1  |= _BV(OCF1B);                         // Clear the interrupt request
00071         //TIMSK1 |= _BV(OCIE1B);                                // Enable output compare B interrupt
00072 }
00073 
00074 //-----------------------------------------------------------------------------
00075 // outputDisable()
00076 //      Disable the output compare B interrupt resulting in no stepper pulses
00077 //-----------------------------------------------------------------------------
00078 inline void CTimer1::outputDisable(void)
00079 {
00080         //TIMSK1 &= ~_BV(OCIE1B);                               // Disable output compare B interrupt
00081 }
00082 
00083 #else 
00084 #error Processor Not Supported!
00085 #endif
00086 
 All Classes Files Functions Variables Defines