ramp.h

Go to the documentation of this file.
00001 
00050 #ifndef ALGO_RAMP_H
00051 #define ALGO_RAMP_H
00052 
00053 #include "hw/hw_stepper.h"
00054 
00055 #include "cfg/cfg_ramp.h"
00056 
00057 #include <cfg/compiler.h>
00058 
00059 
00063 #define TIME2CLOCKS(micros) ((uint32_t)(micros) * (STEPPER_CLOCK / 1000000))
00064 
00068 #define CLOCKS2TIME(clocks) ((uint32_t)(clocks) / (STEPPER_CLOCK / 1000000))
00069 
00073 #define MICROS2FREQ(micros) (1000000UL / ((uint32_t)(micros)))
00074 
00078 #define FREQ2MICROS(hz) (1000000UL / ((uint32_t)(hz)))
00079 
00083 #define FIX_MULT32(a,b)  (((uint64_t)(a)*(uint32_t)(b)) >> 16)
00084 
00093 struct RampPrecalc
00094 {
00095 #if RAMP_USE_FLOATING_POINT
00096     float beta;
00097     float alpha;
00098     float gamma;
00099 #else
00100     uint16_t max_div_min;
00101     uint32_t inv_total_time;
00102 #endif
00103 };
00104 
00105 
00109 struct Ramp
00110 {
00111     uint32_t clocksRamp;
00112     uint16_t clocksMinWL;
00113     uint16_t clocksMaxWL;
00114 
00115     struct RampPrecalc precalc; 
00116 };
00117 
00118 
00119 /*
00120  * Function prototypes
00121  */
00122 void ramp_compute(
00123     struct Ramp * ramp,
00124     uint32_t clocksInRamp,
00125     uint16_t clocksInMinWavelength,
00126     uint16_t clocksInMaxWavelength);
00127 
00128 
00137 void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq);
00138 
00139 
00143 void ramp_default(struct Ramp *ramp);
00144 
00145 
00154 #if RAMP_USE_FLOATING_POINT
00155     float ramp_evaluate(const struct Ramp* ramp, float curClock);
00156 #else
00157     uint16_t ramp_evaluate(const struct Ramp* ramp, uint32_t curClock);
00158 #endif
00159 
00160 
00162 int ramp_testSetup(void);
00163 int ramp_testRun(void);
00164 int ramp_testTearDown(void);
00165 
00166 #endif /* ALGO_RAMP_H */
00167