Contiki 2.6
|
00001 #ifndef __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__ 00002 #define __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__ 00003 00004 #include <stepper.h> 00005 00006 /* Timer frequency */ 00007 #define TIMER_FREQ 748800 00008 00009 typedef struct _StepperContext StepperContext; 00010 typedef struct _StepperState StepperState; 00011 typedef struct _StepperTimerStep StepperTimerStep; 00012 00013 #define MAX_STEPS_PER_PERIOD 40 00014 #define NUM_STEPPERS 2 00015 00016 #define STEPPER_MAX_VELOCITY 4000 00017 #define STEPPER_MAX_ACCELRATION 4000 00018 00019 00020 #define TIMING_ERRORS 00021 00022 struct _StepperState 00023 { 00024 long step_count; 00025 uint32_t io_mask; 00026 const uint32_t *acc_steps; /* Stepping sequence when accelerating */ 00027 const uint32_t *run_steps; /* Stepping sequence when running */ 00028 const uint32_t *hold_steps; /* Stepping sequence when stationary */ 00029 uint8_t current_step; /* in stepping sequence */ 00030 uint8_t sequence_length; 00031 00032 long velocity; /* steps/second * PPS */ 00033 long acceleration; /* steps/second^2 */ 00034 long step_full; /* steps, same as step_count at period boundaries */ 00035 long step_frac; /* (steps * PPS^2 * 2) % steps * PPS^2 */ 00036 00037 long n_steps; /* full steps to move during this period */ 00038 00039 StepperAccSeq *acceleration_sequence; 00040 00041 #ifdef TIMING_ERRORS 00042 long err_max; 00043 long err_min; 00044 #endif 00045 }; 00046 00047 #define STEPPER_POWER_ACC 30 00048 #define STEPPER_POWER_RUN 20 00049 #define STEPPER_POWER_HOLD 10 00050 #define STEPPER_POWER_OFF 0 00051 00052 #define STEPPER_DIRECTION_NONE 0 00053 #define STEPPER_DIRECTION_FORWARD 1 00054 #define STEPPER_DIRECTION_BACKWARD 2 00055 00056 struct _StepperTimerStep 00057 { 00058 StepperTimerStep *next; 00059 StepperState *state; 00060 uint16_t time; 00061 uint8_t direction; 00062 uint8_t power; 00063 }; 00064 00065 00066 struct _StepperContext 00067 { 00068 unsigned int flags; 00069 unsigned long period_count; 00070 AT91PS_TC timer_channel; 00071 StepperState steppers[NUM_STEPPERS]; 00072 StepperTimerStep *steps; 00073 StepperTimerStep *current_step; 00074 StepperUserCallback user_callback; 00075 }; 00076 00077 extern StepperContext stepper_context; 00078 #endif /* __STEPPER3_INTERRUPT_H__2MHD6D6PQ1__ */ 00079 00080 void stepper_timer_interrupt(void);