Skip to content

Commit 237e738

Browse files
committed
rename old pmf/PMF to log2/LOG2 representation and define type log2_value_t
1 parent a3f3f66 commit 237e738

17 files changed

Lines changed: 112 additions & 109 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
pre-0.34.1:
2+
- add memory report script
3+
- rename old pmf/PMF to log2/LOG2 representation and define type `log2_value_t`
4+
15
0.34.0:
26
- Major internal refactoring: reorganize code into subdirectories
37
- `fas_queue/` - queue implementation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ FastAccelStepper offers the following features:
6767
* Direction pins can be shared between motors
6868
* Configurable delay between direction change and following step
6969
* External callback function can be used to drive the enable pins (e.g. connected to shift register) and, only esp32 derivates: the direction pins
70-
* No float calculation (poor man float: use log2 representation in range -64..64 with 16bit integer representation and 1/512th resolution)
70+
* No float calculation (log2 representation in range -64..64 with 16bit integer representation and 1/512th resolution)
7171
* Provide API to each steppers' command queue. Those commands are tied to timer ticks aka the CPU frequency!
7272
* Command queue can be filled with commands and then started. This allows near synchronous start of several steppers for multi axis applications.
7373

extras/gen_log2_const/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# generate pmf constants
1+
# generate log2 constants
22

33
Those constants are stored in Log2RepresentationConst.h and are autogenerated
44
by invoking make. This builds main from main.cpp.

extras/gen_log2_const/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33

44
#include <Log2Representation.h>
55

6-
void out(const char* name, float x, pmf_logarithmic value) {
6+
void out(const char* name, float x, log2_value_t value) {
77
float ld2 = log2(x);
8-
float pmf = ld2 * 512;
9-
int16_t pmf_int = (uint16_t)round(pmf);
8+
float log2_val = ld2 * 512;
9+
int16_t log2_int = (uint16_t)round(log2_val);
1010
puts("");
11-
printf("// %s = %f %d = 0x%04x\n", name, pmf, pmf_int, pmf_int);
12-
if (pmf_int != value) {
13-
printf("// %s should be 0x%04x\n", name, pmf_int);
11+
printf("// %s = %f %d = 0x%04x\n", name, log2_val, log2_int, log2_int);
12+
if (log2_int != value) {
13+
printf("// %s should be 0x%04x\n", name, log2_int);
1414
}
15-
printf("#define %s ((pmf_logarithmic)0x%04x)\n", name, value);
16-
float back = pow(2.0, float(pmf_int) / 512);
15+
printf("#define %s ((log2_value_t)0x%04x)\n", name, value);
16+
float back = pow(2.0, float(log2_int) / 512);
1717
printf("// => converted back => %.2f\n", back);
1818
}
1919

2020
int main() {
21-
puts("// Autogenerated by extras/gen_pmf_const/main");
21+
puts("// Autogenerated by extras/gen_log2_const/main");
2222
puts("// DO NOT EDIT");
2323
puts("#ifndef LOG2REPRESENTATIONCONST_H");
2424
puts("#define LOG2REPRESENTATIONCONST_H");
2525
puts("");
2626
puts("#include <Log2Representation.h>");
2727

28-
pmf_logarithmic x;
28+
log2_value_t x;
2929

3030
x = log2_from((uint8_t)1);
3131
out("LOG2_CONST_1", 1.0, x);

extras/tests/pc_based/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Tests;
66
- test_02
77
checks ramp timing
88

9-
- pmf_test
9+
- log2_test
1010
checks Log2Representation implementation
1111

1212
- test_04

extras/tests/pc_based/test_03.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct const_tab {
44
uint32_t val_nom;
55
uint32_t val_denom;
66
bool squared;
7-
pmf_logarithmic c;
7+
log2_value_t c;
88
};
99

1010
bool perform_test() {
@@ -26,7 +26,7 @@ bool perform_test() {
2626
{21000000, 2, true, LOG2_CONST_2205E11} // (21e6)^2 / 2
2727
};
2828
uint16_t l1;
29-
pmf_logarithmic p1;
29+
log2_value_t p1;
3030

3131
trace("Check leading_zeros()");
3232
for (int16_t x_8 = 0; x_8 <= 255; x_8++) {
@@ -132,7 +132,7 @@ bool perform_test() {
132132
limit >>= 1;
133133
trigger_16 >>= 1;
134134
}
135-
pmf_logarithmic p = log2_from((uint16_t)x_16);
135+
log2_value_t p = log2_from((uint16_t)x_16);
136136
uint16_t res_16 = log2_to_u16(p);
137137
uint16_t delta = x_16 - res_16;
138138
if (res_16 > x_16) {
@@ -188,7 +188,7 @@ bool perform_test() {
188188
delta_32 = 1;
189189
}
190190
}
191-
pmf_logarithmic px = log2_from((uint32_t)x_32);
191+
log2_value_t px = log2_from((uint32_t)x_32);
192192
uint32_t res_32 = log2_to_u32(px);
193193
uint32_t delta = x_32 - res_32;
194194
if (res_32 > x_32) {
@@ -207,13 +207,13 @@ bool perform_test() {
207207
for (uint32_t a_32 = 1; a_32 <= 0x1ff; a_32++) {
208208
for (uint32_t b_32 = 1; b_32 <= 0x1ff; b_32++) {
209209
p1 = log2_from(a_32);
210-
pmf_logarithmic p2 = log2_from(b_32);
210+
log2_value_t p2 = log2_from(b_32);
211211
if (sa > 0) {
212212
p1 = log2_shl(p1, sa);
213213
} else if (sa < 0) {
214214
p1 = log2_shr(p1, -sa);
215215
}
216-
pmf_logarithmic p = log2_multiply(p1, p2);
216+
log2_value_t p = log2_multiply(p1, p2);
217217
if (sa > 0) {
218218
p = log2_shr(p, sa);
219219
} else if (sa < 0) {
@@ -237,19 +237,19 @@ bool perform_test() {
237237
}
238238
#endif
239239

240-
trace("Check pmf constants");
240+
trace("Check log2 constants");
241241
bool error = false;
242242
for (uint8_t i = 0; i < NR_OF_CONSTANTS; i++) {
243243
const struct const_tab* dut = &constants[i];
244-
pmf_logarithmic val = log2_from(dut->val_nom);
244+
log2_value_t val = log2_from(dut->val_nom);
245245
if (dut->squared) {
246246
val += val;
247247
}
248248
if (dut->val_denom > 1) {
249-
pmf_logarithmic val_denom = log2_from(dut->val_denom);
249+
log2_value_t val_denom = log2_from(dut->val_denom);
250250
val -= val_denom;
251251
}
252-
pmf_logarithmic c = dut->c;
252+
log2_value_t c = dut->c;
253253
if (c != val) {
254254
xprintf("(%d/%d)^%d => %x != %x\n", dut->val_nom, dut->val_denom,
255255
dut->squared ? 2 : 1, val, c);
@@ -267,8 +267,8 @@ bool perform_test() {
267267
} else if (sa < 0) {
268268
p1 = log2_shr(p1, -sa);
269269
}
270-
pmf_logarithmic p = log2_rsqrt(p1);
271-
pmf_logarithmic pe =
270+
log2_value_t p = log2_rsqrt(p1);
271+
log2_value_t pe =
272272
log2_multiply(p1, log2_multiply(p, p)); // sqrt not yet tested
273273
// pe should be approximately 1
274274
uint32_t res = log2_to_u32(log2_shl(pe, 16));
@@ -292,8 +292,8 @@ bool perform_test() {
292292
} else if (sa < 0) {
293293
p1 = log2_shr(p1, -sa);
294294
}
295-
pmf_logarithmic p = log2_square(p1);
296-
pmf_logarithmic pe = log2_multiply(p1, p1);
295+
log2_value_t p = log2_square(p1);
296+
log2_value_t pe = log2_multiply(p1, p1);
297297
int32_t diff = (int32_t)p - (int32_t)pe;
298298
if (diff > 1) { // square has better precision than multiply
299299
xprintf("a=%d log2(x)=%x log2(square(x))=%x log2(x*x)=%x ", a_32, p1,
@@ -313,9 +313,9 @@ bool perform_test() {
313313
} else if (sa < 0) {
314314
p1 = log2_shr(p1, -sa);
315315
}
316-
pmf_logarithmic p = log2_rsquare(p1);
316+
log2_value_t p = log2_rsquare(p1);
317317

318-
pmf_logarithmic pe = log2_multiply(p, log2_square(p1));
318+
log2_value_t pe = log2_multiply(p, log2_square(p1));
319319
// pe should be approximately 1
320320
uint32_t res = log2_to_u32(log2_shl(pe, 16));
321321
int32_t diff = (int32_t)res - 0x10000;
@@ -338,9 +338,9 @@ bool perform_test() {
338338
} else if (sa < 0) {
339339
p1 = log2_shr(p1, -sa);
340340
}
341-
pmf_logarithmic p = log2_reciprocal(p1);
341+
log2_value_t p = log2_reciprocal(p1);
342342

343-
pmf_logarithmic pe = log2_multiply(p, p1);
343+
log2_value_t pe = log2_multiply(p, p1);
344344
// xe should be approximately 1
345345
uint32_t res = log2_to_u32(log2_shl(pe, 16));
346346
int32_t diff = (int32_t)res - 0x10000;
@@ -356,7 +356,7 @@ bool perform_test() {
356356
}
357357

358358
trace("Check specific use cases");
359-
pmf_logarithmic x, x1, x2;
359+
log2_value_t x, x1, x2;
360360
x1 = log2_from((uint32_t)0x0ffff);
361361
x2 = log2_from((uint32_t)0x10100);
362362
x = log2_multiply(x1, x2);
@@ -428,7 +428,7 @@ bool perform_test() {
428428
xprintf("log2_shr(log2_shl(%x/%x,20),20)=%x (%ld)\n", x1, x2, x, back);
429429
test(back == 0, "log2_divide/log2_shl");
430430

431-
x1 = pmf_logarithmic((uint32_t)1500);
431+
x1 = log2_value_t((uint32_t)1500);
432432
x = log2_pow_div_3(x1);
433433
xprintf("%d/3=%d\n", x1, x);
434434
// +1 is deviation
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)