-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QUAD_TYPE borked #44
Comments
default QUAD_TYPE is 2, this means that the ppr are exactly as indicated on the encoders. the plugin does exactly what it is supposed to do and can also be checked in the test-bench, a QUAD_TYPE=2 divides all pulses by 4, so that in principle you only count one edge of a signal in order to use the highest resolution cleanly, the pulses should also come cleanly and symmetrically from encoder, what i can well imagine at the moment is that your esp32-test-encoder-tool does not output symmetrical pulses and therefore produces strange side effects |
haha, it isn't my shitty AI addled code! I had QUAD_ENC set to 0, but It only sent a value when count was 32. This is why RPS would drop to 0 without the smoothing/averaging even with a pulse every 1000 microseconds. When I removed that bitshift delta counts ( via hal scope) would be 15..18 with variation at 10RPS pulse generation. With the bit shift it was 32, 0,0,32 and with RPS of 1 it was more like 32, 0,0,0,0,0,32 |
ok ok, but i don't see the error here, i have add 2 additional position outputs to the quadencoder .v position: with shift 0
|
position is accurate, it is the interval a value get sent that is hte problem. I will send some screenshots, recreating the halscope setup |
This is using the bitshift and QUAD_TYPE=0, signal emulation is 1RPS for PPR of 500. Pulse duration should be 1ms. Scope measures frequency of single channel 125hz Green trace is duration, range +/- ~20 microsecond Blue is RPS, unfiltered. 433 or zero Red is delta counts (raw_value - last_raw_value) My setup from yesterday is gone so I'm haveing a bit of trouble reproducing the results and i'm very confused by them. New signals, RPS 1, PPR 500, pulse delay 5ms, scope measurs 25HZ. Notice the delta counts is still ~26. Last setup: RPS 1, PPR 1000, pulse delay 500us, scope measures single chan frequency of 250hz, why are counts 26 or 52? Weirder is that yesterday everything was 32 or zero. |
i removed the 3rd stepdir plugin, recompiled, reflashed, re-added my delta_counts pin and deltacounts seem to be behaving. Really hard to test this. |
pulling the timestamp header bug and retesting join following errors, maybe related to this tho? |
puhhh, yes, maybe, i think so, the frame size was to short and cut the last bits from the encoder value. that's why i couldn't see the error, because my configuration was such that i didn't notice the bug. i have also modified my test setup and now have a stepper with generator to generate 1rps. without the filter i get +-0.2 rps fluctuations with avg8 ~ 0.04 rps i'll try calculating the rps every 10 ms again, then the rounding errors should be less. |
we should set lower bound on RPS, like 1RPM or .016 RPS. Also as per the DM the alpha beta filter I am using makes really nice results. May want to have it as a general purpose function and add to a "filter library" |
So, to sniff out the bug a bit further I added a pin to show the delta counts for every run of the rps calculation. It showed that delta counts was always 32 no matter what the actual speed was of the pulses. This didn't match up with the UDP latency and would basically only calculate the velocity every (pulse_duration * 32), this means that for slow updates the data was sparser and sparser thus requiring filtering. I did a bunch of digging and couldn't find anything obvious so as a last resort (and not to bug you olli) i asked gemini. Amazingly it was correct. Removing the QUAD_TYPE bitshift gave the expected updates for every udp packet!
simple change
I asked gemini "why would <quadencoderz.v> only send counts when the counts diff was 32?"
it said:
The issue lies in the line:
You're using a right arithmetic shift (
>>>
) with the parameterQUAD_TYPE
. This is intended to divide the count by 2 raised to the power ofQUAD_TYPE
.If
QUAD_TYPE
is set to 5 (2^5 = 32), then theposition
output will only change when thecount
changes by 32. Let's break down why:count>>>QUAD_TYPE
: This performs an arithmetic right shift. It shifts the bits ofcount
to the right byQUAD_TYPE
positions. For each shift, the leftmost bit (the sign bit) is replicated, preserving the sign of the number.QUAD_TYPE
is 5, the shift effectively dividescount
by 32. So:count
is 0,position
is 0.count
is 1,position
is 0 (1 >>> 5 = 0).count
is 31,position
is 0 (31 >>> 5 = 0).count
is 32,position
is 1 (32 >>> 5 = 1).count
is 63,position
is 1 (63 >>> 5 = 1).count
is 64,position
is 2 (64 >>> 5 = 2).As you can see,
position
only increments whencount
has increased by a multiple of 32. The same applies to decrements.How to Fix It:
If you want
position
to reflect the raw encoder count, you should remove the shift entirely:If you intend to divide the count by a fixed value (e.g., to implement quadrature decoding where you get 4 counts per encoder cycle), you should use a division or a right shift by a constant value, not a parameter that can be easily misinterpreted:
Example demonstrating the shift:
Let's say
count
is a 6-bit number andQUAD_TYPE
is 2:This table clearly shows how the right shift with
QUAD_TYPE = 2
effectively divides the count by 4.By making the appropriate change (either removing the shift or using a constant value), you'll get the desired behavior from your quad encoder module. If you intended to divide by 32 based on some external configuration, consider using a separate signal and a conditional assignment instead of relying on a parameter that affects the core counting logic.
The text was updated successfully, but these errors were encountered: