ramp.h
Go to the documentation of this file.00001
00049 #ifndef ALGO_RAMP_H
00050 #define ALGO_RAMP_H
00051
00052 #include <cfg/compiler.h>
00053 #include "hw_stepper.h"
00054
00063 #define RAMP_USE_FLOATING_POINT 0
00064
00065
00066 #if !RAMP_USE_FLOATING_POINT
00067
00082 #define RAMP_CLOCK_SHIFT_PRECISION 2
00083 #endif
00084
00085
00087 #define RAMP_PULSE_WIDTH 50
00088
00090 #define RAMP_DEF_TIME 6000000
00091 #define RAMP_DEF_MAXFREQ 5000
00092 #define RAMP_DEF_MINFREQ 200
00093 #define RAMP_DEF_POWERRUN 10
00094 #define RAMP_DEF_POWERIDLE 1
00095
00096
00100 #define TIME2CLOCKS(micros) ((uint32_t)(micros) * (STEPPER_CLOCK / 1000000))
00101
00105 #define CLOCKS2TIME(clocks) ((uint32_t)(clocks) / (STEPPER_CLOCK / 1000000))
00106
00110 #define MICROS2FREQ(micros) (1000000UL / ((uint32_t)(micros)))
00111
00115 #define FREQ2MICROS(hz) (1000000UL / ((uint32_t)(hz)))
00116
00117
00118
00127 struct RampPrecalc
00128 {
00129 #if RAMP_USE_FLOATING_POINT
00130 float beta;
00131 float alpha;
00132 float gamma;
00133 #else
00134 uint16_t max_div_min;
00135 uint32_t inv_total_time;
00136 #endif
00137 };
00138
00139
00143 struct Ramp
00144 {
00145 uint32_t clocksRamp;
00146 uint16_t clocksMinWL;
00147 uint16_t clocksMaxWL;
00148
00149 struct RampPrecalc precalc;
00150 };
00151
00152
00153
00154
00155
00156 void ramp_compute(
00157 struct Ramp * ramp,
00158 uint32_t clocksInRamp,
00159 uint16_t clocksInMinWavelength,
00160 uint16_t clocksInMaxWavelength);
00161
00162
00171 void ramp_setup(struct Ramp* ramp, uint32_t length, uint32_t minFreq, uint32_t maxFreq);
00172
00173
00177 void ramp_default(struct Ramp *ramp);
00178
00179
00188 #if RAMP_USE_FLOATING_POINT
00189 float ramp_evaluate(const struct Ramp* ramp, float curClock);
00190 #else
00191 uint16_t ramp_evaluate(const struct Ramp* ramp, uint32_t curClock);
00192 #endif
00193
00194
00196 void ramp_test(void);
00197
00198 #endif
00199