KT LCD3 firmware -- Flexible OpenSource firmware for Kunteng KT-LCD3

nieles said:
The first part of the Schematic is done (the interesting bits LOL)

LCD3_display_V0_1.pdf

few intersting things i see:

PA2 needs to be logic HIGH to keep the LCD on. this works like a keep alive. write a low and the LDO loses power and turns off (i tested this behaviour)

with PE3 you can short part of the resistors before the LDO. i think this is to accomodate different input voltages.
we need to do some math to figure out what is possible here.
Would be great if you could put the schematic sources and PDf file on github, and use github as the main sources versioning and file repository.

I see on the market only 2 different versions: 24/36/48V and 72V versions. For my calcs, the version I use for the 48V, can read ADC battery voltage up to 68.5V (0.0672 volts per each ADC unit).
Also, when I put a battery voltage less than 26V, the LCD starts to fade out... so I would say I need to PE3 = 1 on this low voltage, as for 24V battery, the low voltage can go up to 20V.

Good work!!
 
I was starting implementing the battery SOC symbols by reading the battery voltage on ADC, until I figured out it would be a bad idea because it could give a different information to user that is considered by the motor controller itself. So, I will just use the information that comes from the motor controller and which I think it is not really good.
 
nieles said:
The first part of the Schematic is done (the interesting bits LOL)

LCD3_display_V0_1.pdf

few intersting things i see:

PA2 needs to be logic HIGH to keep the LCD on. this works like a keep alive. write a low and the LDO loses power and turns off (i tested this behaviour)

with PE3 you can short part of the resistors before the LDO. i think this is to accomodate different input voltages.
we need to do some math to figure out what is possible here.
This is a pretty weird design. But the idea of putting dropper resistors in front of the actual voltage regulator seems to be in line with other KT products.

There's also a 72V version of this LCD. Can we assume that they just added a bunch more resistors? I have one on the way to me right now, but I dread having to open it (they're weather sealed with some silicone gunk). If there's any way I can help figure this out, I'll be glad to be of help.
 
1N4001 said:
This is a pretty weird design. But the idea of putting dropper resistors in front of the actual voltage regulator seems to be in line with other KT products.

There's also a 72V version of this LCD. Can we assume that they just added a bunch more resistors? I have one on the way to me right now, but I dread having to open it (they're weather sealed with some silicone gunk). If there's any way I can help figure this out, I'll be glad to be of help.
I bet this is some optimization for price.

Thanks for the offer. I would say we don't need until some user wants to flash the firmware on that version and if firmware fails, we will figure out then.

For now, I am just doing the firmware thinking on TSDZ2 motor... I guess you are using the LCD3 for KT controllers. Would you change anything on the LCD firmware features?
 
Hi Casainho,

what is your idea for this firmware? ie what is the end goal? just to get it working with the TSDZ2 motor?

it would be nice if we could make the high level code generic enough we can use it for many different controllers.

then we could implement the low level code for each different controller as they send data in a different way or format

this way we can support any controller that ouputs data via the UART.
 
nieles said:
Hi Casainho,

what is your idea for this firmware? ie what is the end goal? just to get it working with the TSDZ2 motor?

it would be nice if we could make the high level code generic enough we can use it for many different controllers.

then we could implement the low level code for each different controller as they send data in a different way or format

this way we can support any controller that ouputs data via the UART.
Hi Nieles.

I am doing all this because I am also taking advantage by using this for myself. When I don't use, I can't develop. So yes, for TZDZ2 motor because I just discovered it and for now I prefer it over the hub motors I am being using for various reasons. Before I was deeply involved on the KT motor controller firmware and I was looking for some improvement on LCD behavior, like having it showing the motor power just in 10W steps to avoid the much oscillation on the value -- and I just did that on my implementation, but for TSDZ2.

As you may know, TSDZ2 is kind of popular and the original LCD really lacks behind KT LCD3 and motor controllers. So, It is very clear the added value and there are users saying that want to know how to install KT LCD3 for TSDZ2. I didn't saw such interest for KT users, maybe because original firmware is already good.

So, about structuring the code to be able to implement for others, there are some reasons I see why I will not do it:
1. I lack knowledge to do it, I am not so experienced
2. I don't see interest of others

About 1., sure I could improve myself but only if there was a need, which I think no because of 2.

So, I prefer to do it quickly and not much structure to take value out of it almost immediately and that is for TSDZ2. But if others are interested to make it working for other systems, I would be happy to see it grow!!! But I think I will be involved on the projects that I have and use the hardware/product.

And you?
 
i am thinking about doing the structured way. just as a 'fun' project. and if someone find it useful, well that would be nice but not necessary.
but like you i'm not very experienced so maybe i will fail.. we will see:)

i do have some very experienced firmware engineers as colleagues. so maybe they can help when i am in trouble:p
 
nieles said:
i am thinking about doing the structured way. just as a 'fun' project. and if someone find it useful, well that would be nice but not necessary.
but like you i'm not very experienced so maybe i will fail.. we will see:)

i do have some very experienced firmware engineers as colleagues. so maybe they can help when i am in trouble:p
I tried to make the firmware that at least Watts Hours and Watts works well, so I can take advantage of it for my next long rides and understand how far can I go.
I ended up doing some structure and it works well. What is needed now is some menu for configuration of wheel size and max speed and I mean, a menu just like original firmware does...

Do you think we can work together on this??
 
Current state of the firmware:

casainho said:
Now the we can click on power on/off button to cycle between showing battery voltage, motor current and trip total Watts/hour.

Long click on power on/off (2.5 seconds) will completely turn off the LCD power but will before save the configurations like current assist level, type information on odometer field and Watts/hour.

Watts/hour is reset if when LCD is powered on and battery voltage is almost complete charged (54.4V) other way, user can turn off the LCD that the Watts/hour value will keep counting next time. Basically, the way to reset Watts/hour is by charging the battery at max value.

KT LCD3 showing the following data from TSDZ2 motor:
- battery voltage
- motor power in watts
- motor current
- trip total Watts/hour
- bicycle wheel speed
- motor assist level
- brakes state
- battery state of charge

On the video I recorded driving with an hand only and that is why is shaky. Also had to click on power on/off button with the hand that was recording.
[youtube]leccM70jTMk[/youtube]
 
And now showing TSDZ2 pedal torque sensor value and cadence:

casainho said:
Good news!! Finally we got pedal cadence :)

The first part of the video shows torque value and on second part (after I click on LCD power button with the hand that is holding the camera) shows cadence (but the value seems to be half of the cadence).

Next step is to calc the human power and also the Watts Hour of human power. I wish we could implement the disable of some information, so user can decide which information prefer - like cycling only over battery voltage, trip battery discharged total Watts/hour, trip human Watts Hour. I think we need to think on a "design" for all this information.

KT LCD3 showing the following data from TSDZ2 motor:
- battery voltage
- motor power in watts
- motor current
- trip total Watts/hour
- pedal torque value
- pedal cadence
- bicycle wheel speed
- motor assist level
- brakes state
- battery state of charge

[youtube]KsarWeFCn5A[/youtube]
 
I implemented the configuration of wheel max speed, wheel size and units of Km/h or MPh:

[youtube]pQBaFCXBn1g[/youtube]

The KT LCD3 is running our own developed Flexible OpenSource firmware.
TongSheng TSDZ2 950W ebike mid drive motor controller is running our improved original firmware.
The motor pulls 18 amps and with my 48V charged, it pulls 950W at startup!! With a 52V battery, would pull over 1000W.

KT LCD3 showing the following data from TSDZ2 motor:
- battery voltage
- motor power in watts
- rider pedal power in watts
- motor current
- trip total Watts/hour
- pedal torque value
- pedal cadence
- bicycle wheel speed
- motor assist level
- brakes state
- battery state of charge

Read more here: https://opensourceebikefirmware.bitbucket.io/kunteng_lcd3
 
From LCD3 user manual:
Environment Temperature
After startup, the environment temperature for using meter will be displayed in environment temperature display column.

The temperature display value may be in deviation shortly after boot-up, and the display value will be gradually approaching the environment temperature within 10 minutes after boot-up.

Does anyone saw a temperature sensor on LCD3 board?? any ideas on how the temperature is measured?
 
Check the schematic I posted. I think it's a NTC. (With 20k pull up)
In order to calculate the slope of temperature change we need to measure the resistance of the NTC at different values. Or use generic values from internet.
 
nieles said:
Check the schematic I posted. I think it's a NTC. (With 20k pull up)
In order to calculate the slope of temperature change we need to measure the resistance of the NTC at different values. Or use generic values from internet.
Oh thanks!!

I am not interested in show temperature. I wish this STM8 has an internal ADC as seems other STM8 and STM32 does and that way the motor controller could measure indirectly the controller/power mosfets temperature. I tried to read the registers that supposed could have the ADC internal temperature but they are always zero -- you know, just like flash memory is the double value from the official value, it could have some extra functionalities also :)
 
nieles said:
allright i finally got everything build and can flash firmware!

how did you end up doing this? I was once able to compile on another machine (similar toolchain for KT-S controllers), but can't get past my block. I have the latest SDCC 3.7.0.0. (IIRC) and I think my paths are correct now, but I get the following error:

objcopy -O binary -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame main.elf main.bin
objcopy: Unable to recognise the format of the input file `main.elf'
Makefile_linux:64: recipe for target 'main' failed
make: *** [main] Error 1

what did you do to solve the problem? (I had the SRC problem, then the pathway problem as you did, but can't get further than this)
 
pawepie said:
nieles said:
what did you do to solve the problem? (I had the SRC problem, then the pathway problem as you did, but can't get further than this)
I think is wrong sdcc version. Do this:

sdcc --version
 
casainho said:
pawepie said:
nieles said:
what did you do to solve the problem? (I had the SRC problem, then the pathway problem as you did, but can't get further than this)
I think is wrong sdcc version. Do this:

sdcc --version

SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.7.0 #10231 (Linux)

so looks like 3.7.0 :(
 
did you install the stm binutils?

looks like you use the wrong OBJCOPY (you need to point to the specific STM8 binutils dir for it to work correctly)

the error is in the end of the posted terminal dump. the rest is all warnings as far as i see.
 
nieles said:
did you install the stm binutils?

looks like you use the wrong OBJCOPY (you need to point to the specific STM8 binutils dir for it to work correctly)

the error is in the end of the posted terminal dump. the rest is all warnings as far as i see.
I think the same, here is my output:

Code:
cas@ubuntu:~/OpenSource-EBike-firmware/LCD3_firmware$ make -f Makefile_linux 
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_iwdg.c StdPeriphLib/src/stm8s_iwdg.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_clk.c StdPeriphLib/src/stm8s_clk.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_gpio.c StdPeriphLib/src/stm8s_gpio.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_adc1.c StdPeriphLib/src/stm8s_adc1.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_tim1.c StdPeriphLib/src/stm8s_tim1.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_tim3.c StdPeriphLib/src/stm8s_tim3.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_uart2.c StdPeriphLib/src/stm8s_uart2.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp4. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_flash.c StdPeriphLib/src/stm8s_flash.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -ogpio.c gpio.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oht162.c ht162.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oadc.c adc.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -otimers.c timers.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -olcd.c lcd.c
lcd.c:523: warning 85: in function odometer unreferenced local variable : 'ui32_temp'
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
lcd.c:1046: warning 94: comparison is always true due to limited range of data type
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -ouart.c uart.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oeeprom.c eeprom.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -obutton.c button.c
sdcc -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  main.c StdPeriphLib/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphLib/src/stm8s_tim3.rel StdPeriphLib/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_flash.rel gpio.rel ht162.rel adc.rel timers.rel lcd.rel uart.rel eeprom.rel button.rel
main.c:101: warning 126: unreachable code
main.c:72: warning 84: 'auto' variable 'ui16_10ms_loop_counter' may be used before initialization
stm8-size main.elf -A
main.elf  :
section             size         addr
DATA                 127            1
INITIALIZED           69          128
SSEG                   1   4294967295
HOME                  99        32768
GSINIT                26        32867
GSFINAL                3        32893
CODE               16531        32896
INITIALIZER           69        49427
.debug_line        21057            0
.debug_loc         21254            0
.debug_abbrev       2227            0
.debug_info        31241            0
.debug_pubnames     8262            0
.debug_frame       21616            0
Total             122582


stm8-objcopy -O binary -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame main.elf main.bin
cas@ubuntu:~/OpenSource-EBike-firmware/LCD3_firmware$
 
Thanks for all your help: found my error (clearly due to my limited knowledge of linux)
when installing https://stm8-binutils-gdb.sourceforge.io/, my mistake was below:

./patch_binutils.sh
./configure_binutils.sh
cd binutils-2.30
***don't do ./configure again!!! - this caused my error****
make
make install
 
I have four TSDZ 2 and I am trying to preprogram one that it will work with LCD 3. I delete original firmware from LCD 3 and try to upload "LCD3_TSDZ2_firmware_v3.bin" but screen when you power on shows all simbols and backlight. When I press something nothing change. What is wrong?
Thank you very much for answer.
 
jernejtech said:
I have four TSDZ 2 and I am trying to preprogram one that it will work with LCD 3. I delete original firmware from LCD 3 and try to upload "LCD3_TSDZ2_firmware_v3.bin" but screen when you power on shows all simbols and backlight. When I press something nothing change. What is wrong?
Thank you very much for answer.
Probably because wrong TX and RX pins, please see if is correct and give feedback later:

6 pin controller (without throttle wire):
• green | P+ | battery voltage!!
• black | GND | ground
• white | Vin | ground when LCD disabled and P+ (battery voltage) when LCD is enabled
• brown | UART TX motor controller |
• orange | UART RX motor controller |
• purple | brake | this signal is active low, meaning that when brakes are not active, this wire has 5V and with brakes active this wire has 0 volts.

8 pin controller (with throttle wire):
• blue | P+ | battery voltage
• black | GND | ground
• red | Vin | ground when LCD disabled and P+ (battery voltage) when LCD is enabled
• brown | UART TX motor controller |
• yellow | UART RX motor controller |
• green | brake | this signal is active low, meaning that when brakes are not active, this wire has 5V and with brakes active this wire has 0 volts. Wired with the 5V wire and black GND wire for 3 pin throttle
• white | 5V |
• orange | throttle | wired with the 5V wire and black ground wire for 3 pin throttle
 
Hi, I follow your project and it is amazing. I was buying TSDZ2, LCD3 and ST programer. Now I like to upload code and can' t. First problem is when I try to compile alway return error. I used stancecoke instructions for Windows. What can I do.
Error message:
new log session
date: 06/30/18
time: 23:10:23
----------------------------------------------------------
STVP_CmdLine version 1.6

Verbose ON
Log activity ON
Display Progress OFF
Message box warning if protect option byte ON
Loop mode OFF
Erase device OFF
Blank check device OFF
Verify device ON

Configuration:
BoardName=ST-LINK ST-LINK_ID=0 Device=STM8S105x6 Port=USB ProgMode=SWIM

>>> Filling PROGRAM MEMORY image in computer with Blank Value
<<< Filling PROGRAM MEMORY image in computer succeeds

>>> Loading file main.ihx in PROGRAM MEMORY image in computer
No such file or directory

I upload LCD_TSDZ firmware on LCD3 and display shows all characters and you can not turn off it. What can be wrong, because I use stlink and your instruction?
It will be so good if you make video tutorials how to install files for WIndows debug and upload it on LCD3.
 
Back
Top