Page 1 of 1

Potnom not completely float

Posted: Wed Aug 13, 2025 4:55 pm
by manny
While driving my Saxo at low speed/power I sometimes feel the small surge or dip in power.
When looking on the web interface at the Iq current I can see a corresponding rise or fall in current.
After adding potnom to the chart they matched perfectly.

Potnom was changing with discrete steps. To verify this I tested this on my test setup.
potnom_5.32.M-foc.PNG
After tracing through the code I found this:

Code: Select all

float Throttle::DigitsToPercent(int potval, int potidx)
{
   if (potidx > 1) return 0;
   if (potmax[potidx] == potmin[potidx]) return 100.0f;

   return (100 * (potval - potmin[potidx])) / (potmax[potidx] - potmin[potidx]);
}
the 100 should be 100.0f I think. After this I took a look at the Zombie code:

Code: Select all

float Throttle::NormalizeThrottle(int potval, int potIdx)
{
    if(potIdx < 0 || potIdx > 1)
        return 0.0f;

    if(potmin[potIdx] == potmax[potIdx])
        return 0.0f;


    return 100.0f * ((float)(potval - potmin[potIdx]) / (float)(potmax[potIdx] - potmin[potIdx]));
}
When I changed the code I got this
potnom_mod.PNG
Second point.
The second "if" returns the opposite value 0 VS 100. 0 seems logical to me but maybe there is a reason?

Re: Potnom not completely float

Posted: Wed Aug 13, 2025 5:13 pm
by tom91
You want to raise a push request or shall I?
manny wrote: Wed Aug 13, 2025 4:55 pm econd point.
The second "if" returns the opposite value 0 VS 100. 0 seems logical to me but maybe there is a reason?
What do you mean? The second if returns 0 if potmin is equal to potmax.

Re: Potnom not completely float

Posted: Wed Aug 13, 2025 5:17 pm
by manny
on the OI code

Code: Select all

   if (potmax[potidx] == potmin[potidx]) return 100.0f;
so if potmin and potmax are equal the potnom is 100%

0% seems safer.

Re: Potnom not completely float

Posted: Wed Aug 13, 2025 5:21 pm
by tom91
wait all of this is already in the Zombie, doh.

https://github.com/damienmaguire/Stm32- ... e.cpp#L116

I got confused, so you are on about the SMT32_Sine/FOC specfics.

Re: Potnom not completely float

Posted: Wed Aug 13, 2025 5:24 pm
by manny
Yes. The Zombie implementation seems correct to me.