Lishui "Open Source Firmware" project / KingMeter 5S

Hi. This controller https://pl.aliexpress.com/item/1005002711701202.html
can only work from the throttle stick without a torque sensor ?
Is it suitable for the project https://github.com/stancecoke/LishuiFOC ?
 
miklelv said:
can only work from the throttle stick without a torque sensor ?
Yes, if you solder in an additional wire to the pad "SP" on the PCB. But it is configured for legal use in Europe, you have to pedal to activate the throttle.

we have discussed that controller in detail in the german forum:
https://www.pedelecforum.de/forum/index.php?threads/12fet-lishui-controller-f%C3%BCr-tretsensor.89037/post-1721115

The controller is from the new generation of Lishui, so the open firmware will not work at the moment. Perhaps I will try to port the firmware to the new hardware during the winter month ;)

regards
stancecoke

index.php
 
So, then what kind of suitable controller can be purchased on the market for a
project https://github.com/stancecoke/LishuiFOC with a maximum current of about 25-30 A ?
 
miklelv said:
what kind of suitable controller can be purchased on the market

there is a page with some links in the wiki:
https://github.com/EBiCS/EBiCS_Firmware/wiki/Where-to-buy-a-suitable-controller

The 12FET can handle 25amps, I guess. I don't know, if you will find a cheaper offer at ali or ebay...

regards
stancecoke
 
Does anyone have any good suggestions on how to tune the PPL P and I factor for using position PPL in the Ebics software?

I have tuned many PI-controllers in my life and I do understand how they work etc, but this one does not seem to follow the normal way of doing it. So my question is if someone has a proven way of tuning it in an efficient way?
 
karstensson said:
but this one does not seem to follow the normal way of doing it
:) You have to know, that the factors do not work as multipliers but as shiftfactors (deviders).


From my experience, for DirectDrives 10/10 is a good starting point, for geared motors 7/11
https://github.com/EBiCS/EBiCS_Firmware/blob/20a4b03f2dab8e3b3954c8fdc1a56cea27337c02/Src/main.c#L2284
Code:
    q31_p=(soll - ist)>>(P_FACTOR_PLL-speedadapt);   				//7 for Shengyi middrive, 10 for BionX IGH3
    q31_d_i+=(soll - ist)>>(I_FACTOR_PLL-speedadapt);				//11 for Shengyi middrive, 10 for BionX IGH3

I know of one user only, who didn't get the PLL run properly over the whole speedrange with his big scooter motor....

regards
stancecoke
 
stancecoke said:
karstensson said:
but this one does not seem to follow the normal way of doing it
:) You have to know, that the factors do not work as multipliers but as shiftfactors (deviders).


From my experience, for DirectDrives 10/10 is a good starting point, for geared motors 7/11
https://github.com/EBiCS/EBiCS_Firmware/blob/20a4b03f2dab8e3b3954c8fdc1a56cea27337c02/Src/main.c#L2284
Code:
    q31_p=(soll - ist)>>(P_FACTOR_PLL-speedadapt);   				//7 for Shengyi middrive, 10 for BionX IGH3
    q31_d_i+=(soll - ist)>>(I_FACTOR_PLL-speedadapt);				//11 for Shengyi middrive, 10 for BionX IGH3

I know of one user only, who didn't get the PLL run properly over the whole speedrange with his big scooter motor....

regards
stancecoke

Thanks for the answer! Mine is a geared motor I assume(Spintech F1, from an ecoride bike), but which strategy do you suggest?

I start with 7/11, if that is jerky I change to 8/11, how high/low should I go on P part until I should start to change the I part? Or is it just random testing that is needed? If it's random, what is the max value for each value that should be sufficient(to limit the possible combinations to test)?

Can you suggest any good variables to plot to tune this, so that I can use the step response mindset?
 
karstensson said:
Or is it just random testing
Yes, I would call it "Trial and Error"
But perhaps you will not find a working setting, as the algorithm is very simple and the shift factors does not allow a very fine tuning. Be aware, the factors are are exponents to base 2. That means:

Code:
Delta/(2^factor)

Why do you want to use the PLL? Is your motor too noisy with disabled PLL????

regards
stancecoke
 
Thanks for the help! It is a bit noisy but that is not the main problem. I can even feel the vibrations in the steering-handles without PPL. Its fully smooth with PPL, but very jerky due to the bad tuning.
 
karstensson said:
Its fully smooth with PPL
Perhaps we should spend some work to improve the PLL algorithm :wink:
You can try the branch M365 improvements, it has a plausibility check for the PLL. But you have to run the autodetect again, as it uses a different angle logic.

regards
stancecoke
 
I will check it out. I don't have full understanding of motor controllers yet, but its never too late to learn :)
 
Hallo @stancecoke

I like your work on
https://github.com/stancecoke/LishuiFOC

I have two controllers, the LSW913-52f and the LSW 943

I will try out your firmware on both of them.

What i am missing of info, are the pin AIO on the STM32 where the throttle control are located. on the 913 it is not working now with the PAS, so i will make it work with a throttle control instead, but need to find the correct location (i don't mind to solder directly on the IC).
 
Jsper said:
the pin AIO on the STM32 where the throttle control are located

See the Wiki at GitHub:
https://github.com/EBiCS/EBiCS_Firmware/wiki/Differences-between-new-and-old-generation-of-Lishui-FOC-controllers

regards
stancecoke
 
stancecoke said:
Jsper said:
the pin AIO on the STM32 where the throttle control are located

See the Wiki at GitHub:
https://github.com/EBiCS/EBiCS_Firmware/wiki/Differences-between-new-and-old-generation-of-Lishui-FOC-controllers

regards
stancecoke

Big time thank you... The eyes are the first place i got blind at.. ;)
 
I've purchased a controller in this thread, removed the grey compound and getting ready to reflash it with OSS firmware.
I intent to use it with a geared motor. It's a a geared motor with a smaller stator, so I'd like to retrofit temperature sensor into hub motor.

If I understand correctly, I can solder NTC 10k thermistor between the white wire of separate speed sensor and ground (-) wire in the motor.
Do I need to add any kind of pull-up resistor on controller side to make it work, or is it just a header file change?
 
Another question - does UART bootloader work with the clone chip on controller, or do I need to resolder the original STM32F103C8 in place of clone to get bootloader to work?
 
dls said:
ready to reflash it with OSS firmware

Welcome, I'm happy to see that the firmware got another user :thumb:

dls said:
I can solder NTC 10k thermistor
We have to check the PCB of the 12FET. The NTC implementation was done for the controllers of EBS Heidelberg. Maybe they are different. And of course, you have to resolder the white wire, as it is not connected to the MotorTemp pin by default but to the speedsensor input.... (as far as I remember :wink: )

dls said:
does UART bootloader work with the clone chip on controller,
It worked in principle on my 12FET with clone processor, but the upload aborted each time I tried to flash via the display connector.
I don't know if this is a general issue with the clones, or just a problem of my controller or the board layout. The Lishui update tool starts normally with uploading the firmware but aborts after a random percentage of transmission... :-(
And of course you have to install the bootloader via STLink again, if you already have disabled the read out protection once.

regards
stancecoke
 
I am planning to keep the clone MCUs with original firmware as spares in case I want to revert back - I have two controllers and will be updating both. I don't see a good reason for it since I need throttle in addition to torque/cadence, but don't want to regret overwriting it without a backup.

I've looked into using https://github.com/doegox/stm32f1-firmware-extractor as a way to potentially backup original firmware, but it leaves gaps in random places, so the backup would not be usable. There's also a startup timing attack which could fill the missing areas, but it is terribly slow and it's probably easier to just desolder the MCU and replace it with blank (which should come with a bootloader afaik - will check soon).

As for the speed/temperature sensing, it is still not very clear to me. Right now it is connected to SS1 (PB5 ?). Moving it to MOTOR_TEMP (PB 0?) connects it to ADC12_IN8 according to datasheet. Will I still retain external speed sensor functionality on the same wire? I am using geared motor with freewheel, so having speed sensor is necessary. Can the firmware still recognize hall sensor events separately from multiplexed temperature voltage on the same wire, like how Grin controllers do that?
 
If such sampling is not implemented in software, I wondering if I could use something like CD74HC4067 and have it split the hall/temp combined signal into two separate signals. My motor has Z9 connector with a wire for speed signal and no spare wires I could use for motor temp
 
Forgive me for the monologue. Looking at the code, it does not look like multiplexing is something that the current code supports.
I am not an expert in electronics and new to programming MCUs.
I guess my specific question is if it is possible to only set temperature when external speed sensor hall is high? With NTC 10k pulling down from hall, the voltage during high phase would be inversely proportional to thermistor resistance, but it can only be measured when hall signal is high. Of course the highest supported temperature has to be low enough for the digital logic to detect high, otherwise if NTC pulldown resistance is high enough, speed hall will never register.

If I am reading code correctly, looks like hall sensor events are counted (?) on fall of digital pin transition to low using interrupt handler and there is a built in pullup enabled on digital pin.

Would this be a good place to read temperature instead of this location to only measure when hall is high?

Another question I have is about mapping of adcData array to individual MCU pins and signal names. This header file maps pins to signals. Is it universal across Lishui boards? . Looking at the second picture here it looks like Motor_Temp is on PB0, but looking at code it reads it from adcData[6], which is described as PB1 here, so is it PB0 or PB1?

(edit) Confirmed Motor_Temp is on PB0 on LSW12G board
Looking further at datasheets, driven by 5V STM32 has to register >2.71V on digital pin to reliably register High
Built-in pullup is at about 40k
NTC 10k (Ametherm DG103395) resistance at 125C is about 359 Ohms, so if the additional external pull-up is 220 Ohm, we are getting logical high voltage from 4.99V at -20C to 3.11V at +125C, which should be high enough.
If ADC Vref is 3.3v, this provides ADC raw values from 6192 at -20C to 3854 at +125C, which is good enough resolution for the purpose of protecting the motor. 3.11v is also enough to register logical high.

This is what I have in mind. I suspect I am missing a voltage divider that's between TEMP_SENSOR pin and PB0. Does this look like something that may work?

NTC10k 220pullup.jpg

I should try it when I get my motor back together - I am expecting some replacement bearings.
 
dls said:
If ADC Vref is 3.3v, this provides ADC raw values from 6192 at -20C to 3854 at +125C,

Be careful. The STM32 ADC is 12bit. 3.3V on the ADC pin is read as 4095, you can't get a reading higher than 4095. For digital reading more than 1.88 V is interpreted as "high". So you would have to build a resistor network that keeps the temperature signal between 1.88V and 3.3V if you want to read the PAS state by simple digital I/O. In the recent code, the PAS signal causes an interrupt, that sets a flag and in the main loop the PAS algorithm is triggered by this flag.
I suppose to do the PAS trigger by an ADC threshold, if you want to put PAS and Temperature information on one wire.... Then you can define the threshold for PAS High / PAS Low by yourself.

regards
stancecoke
 
Thanks. I suppose there must already be some resistor network voltage divider on the board since speed signal is at 5v, but analog IO maxes out at 3v3.
I was thinking about the option of getting speed from analog pin, but it seems to be more work in code and I can't say I have enough experience to do that right.
The other option is picking pull-up resistor value to get the highest possible temperature over logical high threshold on digital pin while having enough remaining resolution on analog pin. I'll probably need to trace the analog temperature signal back to the MCU to identify and measure SMD resistors so that I can have an accurate formula. I don't really need very precise resolution for temperature - all I need is avoiding overheating the motor.


Unrelated question. Do you know if it is possible to do PWM output on brake light pin? I guess that depends if the timer for pin is used for something else in code. What I had in mind was having brake light at partial duty rate - say 50% when headlight is on, and have it go 100% on brake signal.
 
dls said:
Do you know if it is possible to do PWM output on brake light pin?
In principle yes. The brake light is on Pin PB10, that can be remapped as Timer2 Channel 3. But timer 2 is not configured as a PWM timer at the moment. It's used for regular ADC triggering and various counters.
https://github.com/EBiCS/EBiCS_Firmware/blob/master/Src/main.c#L1377

But of course you can do Arduino like software bit banging for different dutycycles on the brake light pin.

regards
stancecoke
 
dls said:
I don't really need very precise resolution for temperature - all I need is avoiding overheating the motor.

A drive by comment from the peanut gallery, if willing to handle overheat purely in electronics, using NTC in similar fashion as LDR (for light detection circuit) can achieve an indication/buzzer/cutoff.
 
Back
Top