ramp.h
Go to the documentation of this file.00001
00049 #ifndef ALGO_RAMP_H
00050 #define ALGO_RAMP_H
00051
00052 #include "hw/hw_stepper.h"
00053
00054 #include <cfg/compiler.h>
00055
00064 #define RAMP_USE_FLOATING_POINT 0
00065
00066
00067 #if !RAMP_USE_FLOATING_POINT
00068
00083 #define RAMP_CLOCK_SHIFT_PRECISION 2
00084 #endif
00085
00086
00088 #define RAMP_PULSE_WIDTH 50
00089
00091 #define RAMP_DEF_TIME 6000000
00092 #define RAMP_DEF_MAXFREQ 5000
00093 #define RAMP_DEF_MINFREQ 200
00094 #define RAMP_DEF_POWERRUN 10
00095 #define RAMP_DEF_POWERIDLE 1
00096
00097
00101 #define TIME2CLOCKS(micros) ((uint32_t)(micros) * (STEPPER_CLOCK / 1000000))
00102
00106 #define CLOCKS2TIME(clocks) ((uint32_t)(clocks) / (STEPPER_CLOCK / 1000000))
00107
00111 #define MICROS2FREQ(micros) (1000000UL / ((uint32_t)(micros)))
00112
00116 #define FREQ2MICROS(hz) (1000000UL / ((uint32_t)(hz)))
00117
00121 #define FIX_MULT32(a,b) (((uint64_t)(a)*(uint32_t)(b)) >> 16)
00122
00131 struct RampPrecalc
00132 {
00133 #if RAMP_USE_FLOATING_POINT
00134 float beta;
00135 float alpha;
00136 float gamma;
00137 #else
00138 uint16_t max_div_min;
00139 uint32_t inv_total_time;
00140 #endif
00141 };
00142
00143
00147 struct Ramp
00148 {
00149 uint32_t clocksRamp;
00150 uint16_t clocksMinWL;
00151 uint16_t clocksMaxWL;
00152
00153 struct RampPrecalc precalc;
00154 };
00155
00156
00157
00158
00159
00160 void ramp_compute(
00161 struct Ramp * ramp,
00162 uint32_t clocksInRamp,
00163 uint16_t clocksInMinWavelength,
00164 uint16_t clocksInMaxWavelength);
00165
00166
00175 void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq);
00176
00177
00181 void ramp_default(struct Ramp *ramp);
00182
00183
00192 #if RAMP_USE_FLOATING_POINT
00193 float ramp_evaluate(const struct Ramp* ramp, float curClock);
00194 #else
00195 uint16_t ramp_evaluate(const struct Ramp* ramp, uint32_t curClock);
00196 #endif
00197
00198
00200 int ramp_testSetup(void);
00201 int ramp_testRun(void);
00202 int ramp_testTearDown(void);
00203
00204 #endif
00205