Page 1 of 1
Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 7:51 am
by johu
So this weekend I worked with Damien and Zero EV on a strange problem: when stepping on the accelerator at high motor speed you would get an INCREASING amount of regen until you sort of "punched through" and got acceleration again. Apparently this happened to a degree where the car would be dangerous to others.
The culprit was in the quadrature encoder code. Basically, the timer hardware handles that by itself, you only have to tell it how many pulses to expect per turn and it will wrap around correctly when one turn is completed. Now, a nominal n-step quadrature encoder actually generates 4 usable edges: rising and falling on each channel. So you'd program the counter to wrap at 4*n.
But would you really? Doing that would mean 360° != 0°. So you introduce one extra step per turn and that throws off position and frequency tracking. So what you really want to do is wrap at 4*n-1.
For the Tesla encoder with its 36 steps per turn this means we interpreted 145 edges as one turn instead of 144. So at 144Hz you are 1Hz off. So 1Hz of slip becomes 0Hz, together with various rounding errors it actually becomes negative slip. And that is regen. Obviously this becomes worse at higher speed.
I will draft a new release asap. For those who can't wait, the source code is on
github.
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 8:26 am
by arber333
I noticed like a year back i couldnt shift anymore if i just set my BMS regen reduction to -1 like before. Now i have to actually set to 0 so that motor would release torque. Is that also the consequence of this error?
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 12:16 pm
by jon volk
Awesome! Ive learned to drive around this quirk but glad to hear theres a solution.
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 3:36 pm
by Jack Bauer
Not only a solution but the E31 feels like it has a rocket engine in the back after this update:)
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 3:39 pm
by yaroslav
Good evening, I do that when skatyvaetsya ago, with the included front transmission starts to spontaneously accelerate backwards, the leg is not even in the gas pedal, not whether problems?
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 4:39 pm
by johu
yaroslav wrote: ↑Tue Sep 24, 2019 3:39 pm
Good evening, I do that when skatyvaetsya ago, with the included front transmission starts to spontaneously accelerate backwards, the leg is not even in the gas pedal, not whether problems?
Not sure if I unterstand your question correctly, but spontaneous reversal would not be related to this problem
Jack Bauer wrote: ↑Tue Sep 24, 2019 3:36 pm
Not only a solution but the E31 feels like it has a rocket engine in the back after this update:)
Yes with the actual configured slip on tap I'd expect that
arber333 wrote: ↑Tue Sep 24, 2019 8:26 am
I noticed like a year back i couldnt shift anymore if i just set my BMS regen reduction to -1 like before. Now i have to actually set to 0 so that motor would release torque. Is that also the consequence of this error?
Possibly yes, if it happened after you switched from single channel to quadrature encoder?
Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 4:56 pm
by arber333
Er... Johannes. Can you compile for us non software minded

Re: Problem found (and solved) in quadrature encoder code
Posted: Tue Sep 24, 2019 7:21 pm
by johu
Sure

It also contains another change that I'm not 100% sure about: throtramp now applies to every throttle operation. 0-100, 100 back to 50, 50 to -40 etc. Throttle is just always ramped. With a slow ramp that car feels a bit weird as it doesn't stop accelerating at the instance you come off throttle.
Please try it.
Re: Problem found (and solved) in quadrature encoder code
Posted: Wed Sep 25, 2019 8:46 am
by arber333
johu wrote: ↑Tue Sep 24, 2019 7:21 pm
Sure

It also contains another change that I'm not 100% sure about: throtramp now applies to every throttle operation. 0-100, 100 back to 50, 50 to -40 etc. Throttle is just always ramped. With a slow ramp that car feels a bit weird as it doesn't stop accelerating at the instance you come off throttle.
Please try it.
Thanks, i will try it today on Mazda!

Re: Problem found (and solved) in quadrature encoder code [SOLVED]
Posted: Thu Sep 26, 2019 2:40 pm
by johu
New release:
viewtopic.php?f=7&t=288
I've changed ramping a bit:
1. Throttle positive going is ALWAYS ramped with "throtramp"
2. Throttle negative going is NEVER ramped as long as above 0
3. Negative going, including brake pedal, below 0 is ramped with "regenramp"
I find throtramp=4 and regenramp=1 quite comfy.
Re: Problem found (and solved) in quadrature encoder code
Posted: Thu Sep 26, 2019 4:57 pm
by arber333
Well... i find it much better! Throttle is finer control and it is not thrashing so much.
But i think cruise control is not working. Can you verify it is not on my side?
tnx
Re: Problem found (and solved) in quadrature encoder code
Posted: Thu Sep 26, 2019 5:04 pm
by johu
Still works for me