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

Get all your technical information about electric bikes here.
nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by nieles » May 17 2018 6:15am

i moved to a new appartment last month so most of my hobby gear is still in boxes LOL.. so its taking longer than i hoped for.

i also remember i need to update my SDCC to version 3.7.0 right?
need to figure that out too as there is no installer.. (i am on windows)
(or just dualboot my PC so i can do this stuff on Ubuntu/linux)

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by casainho » May 17 2018 6:19am

nieles wrote:
May 17 2018 6:15am
i moved to a new appartment last month so most of my hobby gear is still in boxes LOL.. so its taking longer than i hoped for.

i also remember i need to update my SDCC to version 3.7.0 right?
need to figure that out too as there is no installer.. (i am on windows)
(or just dualboot my PC so i can do this stuff on Ubuntu/linux)
Use a virtual machine with Linux, that way is even faster to backup the linux installation/virtual machine. You only need access to the STLinkV2 and serial port on Linux over the virtual machine and it works really well.

Yes, SDCC 3.7.0. If you go with Linux, I can fast help you as I am also on Linux.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by nieles » May 17 2018 6:23am

right, sounds good about the virtual machine! any recommendations what to use? (freeware preferable)

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by casainho » May 17 2018 6:28am

nieles wrote:
May 17 2018 6:23am
right, sounds good about the virtual machine! any recommendations what to use? (freeware preferable)
I tested VirtualBox and VMWare player. I got different results depending on the computer I use. Right now I am using VMWare player but I also used before VirtualBox.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by nieles » May 17 2018 6:31am

thanks! will try tonight when i'm home from work.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by nieles » May 17 2018 3:05pm

maybe i'm dense but i cant figure out how to install all the required software (sdcc and binutils)

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by casainho » May 17 2018 3:08pm

nieles wrote:
May 17 2018 3:05pm
maybe i'm dense but i cant figure out how to install all the required software (sdcc and binutils)
The notes I wrote point to here: https://stm8-binutils-gdb.sourceforge.io

Go step by step...
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

Re: LCD3 firmware -- Flexible OpenSource firmware for Kunteng LCD3

Post by casainho » May 18 2018 4:27am

Almost there, implemented: lcd_print(number, ODOMETER)

Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
TheBeastie   1 MW

1 MW
Posts: 1828
Joined: Jul 28 2012 12:31am
Location: Melbourne Australia

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

Post by TheBeastie » May 18 2018 8:22am

Cool to see someone hacking the KT-LCD3.
The only thing I have found my self-wanting on it is more C5 mode current options, theres only like 5 or so current levels. It would be nice if there was a wider range of around 10 to 15 levels. Also, it seems pedal assist level-5 no matter what C5-level is you have is just full current.

I don't get why people would expect/want to see Ah on the LCD or even if its theoretically possible. The live watts works fine for me.
Ah/wattmeters can be attached on your battery plug cable or between the battery and the controller.
Ah/watt meters are practically given away for next to nothing on ebay.

Good luck hackin.
Speed Kills Range, 10mph = 46 miles range, 20mph = 20 miles, 30mph = 8 miles rangehttps://goo.gl/1JNL53
Over Charging Kills ur battery bit.ly/1hzWKl4
Consider PAS as your only throttle https://goo.gl/Kg1F8F
Fuel-Cell is the ultimate battery coupled with 4th-gen Nuclear
https://goo.gl/TcKtHs https://goo.gl/ZhFFot https://goo.gl/gfa215
10 Square Miles of solar panels = 0.12GW average power! https://goo.gl/Ub1S39

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 18 2018 10:10am

casainho wrote:
May 18 2018 4:29am
Almost there, implemented: lcd_print(number, ODOMETER)

Next step is to connect to TSDZ2 LCD cable, enable/disable the motor with LCD3 on/off button and show the TSDZ2 motor current!!
Although I was able to connect KT LCD3 to TSDZ2 and show the data sent in real time from the motor controller to the LCD, unfortunately I found that motor current is not sent to LCD :-( :-(

It is really strange, there is one byte sent that is always 0. There is another that has the pedal torque sensor value. And even other that has torque sensor value and the wheel speed... there is also a flag sent when motor is running.
Why pedal torque sensor value???? Why there is no current information when LCD symbol is available to show that?? -- I wonder if the torque sensor value was used for debug while development and the product was sent to market in a hurry...
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 19 2018 10:06am

allright! finally got SDCC to compile, by fiddeling around with all sort of packages/options and what not..
also installed binutils and stm8flash

now when compiling the FW i get the following

Code: Select all

make -f  Makefile_linux
make: *** No rule to make target 'StdPeriphLib/src/stm8s_iwdg.rel', needed by 'main'.  Stop.
any clue what i did wrong?

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 19 2018 10:10am

Image
nieles wrote:
May 19 2018 10:06am
allright! finally got SDCC to compile, by fiddeling around with all sort of packages/options and what not..
also installed binutils and stm8flash

now when compiling the FW i get the following

Code: Select all

make -f  Makefile_linux
make: *** No rule to make target 'StdPeriphLib/src/stm8s_iwdg.rel', needed by 'main'.  Stop.
any clue what i did wrong?
Most likely you are trying to use iwdg from STM8 sources lib but you need to also add to makefile, both c and h files.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 19 2018 10:32am

i just cloned the repository and tried to compile.. didnt change anything

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 19 2018 10:39am

okay, so maybe the problem is there is no src folder in the StdPeriphLib folder included in the project. do i need to copy that my self from somewhere?

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 19 2018 11:14am

allright, copied the src folder from the controller project and the compilation process gets a little further. still getting an error:

Code: Select all

niels@niels-VirtualBox:~/Documents/software/Kunteng_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  -ogpio.c gpio.c
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
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  -ouart.c uart.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 gpio.rel adc.rel timers.rel lcd.rel uart.rel
main.c:156: warning 126: unreachable code
main.c:110: warning 84: 'auto' variable 'ui32_number' may be used before initialization
main.c:110: warning 84: 'auto' variable 'ui32_number' may be used before initialization
main.c:156: warning 85: in function main unreferenced local variable : 'ui16_temp'
main.c:156: warning 85: in function main unreferenced local variable : 'ui8_button_up_state'
main.c:156: warning 85: in function main unreferenced local variable : 'ui8_button_down_state'
stm8-size main.elf -A
make: stm8-size: Command not found
Makefile_linux:60: recipe for target 'main' failed
make: *** [main] Error 127

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 19 2018 11:57am

Seems stm8-size is not on the path. As it is only to show size of the final file, you can as a workaround comment the use of it on the makefile.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 23 2018 3:35pm

allright i finally got everything build and can flash firmware!

i flashed the 'test symbols' branch to my display. i am getting a few characters, but not all. starts with 'cruise' then the big 7-segment then the ODO and Temperature segments. then nothing.

i also tried the 'enable all' function. all symbols light on.

now i am figuring out what all circuits look like, what is connected. (by measuring all Via's and drawing traces on a picture) this will take me a while LOL.. will post a schematic when done.

have you yet figured out how to turn off the display with the ON/OFF key? i think it has to do with T1/T2/T3. (from what traces i have connected)

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 23 2018 4:30pm

I can't even detect change on button on/off. Can you please give a look at pins.h on master branch and verify??

Also, you will see that I enable 2 pins at lcd_init() but I don't remember which one does what......

Look at ny latest code: odometer + assist level numbers + send to controller assist level + read motor current:
casainho wrote:
May 23 2018 12:22pm
Assist level now works. I wanted to show the brake symbol on LCD but turns out that TSDZ2 motor control don't send the brake state to LCD :-( -- yes, I am using brakes and I really can't live with brakes connected.

0 assist level is the same as motor turned off.

NOTE: the values shown on LCD are twice of the real value due to a small mistake I did on the code.

Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 24 2018 4:35am

Will have a look tonight at the gpio.h. and also once we have the schematic we can figure out how the ON/OFF button works. i think there is some sort of set/reset flipflop logic implemented with discrete components and an output pin from the processor

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 24 2018 4:57am

nieles wrote:
May 24 2018 4:35am
Will have a look tonight at the gpio.h. and also once we have the schematic we can figure out how the ON/OFF button works. i think there is some sort of set/reset flipflop logic implemented with discrete components and an output pin from the processor
I wounder if the STM8 can run even if we disable the system. Like, for counting the time between each trip and decide when to consider starting on a new trip.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 24 2018 6:33am

dont know. but we would need a RTC (low power clock) or an wake up interrupt to do it energy efficient.

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 24 2018 11:14pm

Nieles, can I give you access to github? I will need your user id.

I added support for saving the changed variables that need to be on EEPROM (I originally developed this code for our OpenSource firmware for KT motor controllers). Assist level is now saved on EEPROM every time we changed it.

For now, this are the variables that can be saved on EEPROM:

Code: Select all

typedef struct _configuration_variables
{
  uint8_t ui8_assist_level;
  uint8_t ui8_wheel_size;
  uint8_t ui8_max_speed;
} struct_configuration_variables;
nieles wrote:
May 24 2018 6:33am
dont know. but we would need a RTC (low power clock) or an wake up interrupt to do it energy efficient.
Seems the resources are available:
Time base common to auto-wakeup unit and beeper
This application note focuses on solutions using one of the following STM8S and STM8A peripherals: auto-wakeup unit or beeper. These peripherals share a common 128 kHz clock (LS clock) which can be driven either by a low speed internal RC oscillator (LSI) or by a high speed external crystal/ceramic resonator (HSE).

The LSI clock system guarantees a much lower power consumption (consumption of about 5 µA) but it has the disadvantage of being less accurate and highly temperature dependent (about ±12.5% within the whole temperature range).
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 25 2018 1:47am

my github username is the same as here: nieles

if you are going to save the assist level every time you change it, we might need to think about wear-leveling the EEPROM because you can only write to them only so many times. EDIT: never mind. the EEPROM has 300k cycle endurance.. more than enough. (write 50 times a day for 16 years LOL )


before starting implementation of the low-power function, wait for the schematic. last night i drawn part of the LDO power circuit, and it has resistors before the LDO to drop a certain voltage (this implies we need a minimum current not to damage the LDO) so maybe we cant do a low-power design because of this..
hopefully the schematic will be finished tomorrow, as i don't have time tonight.

casainho   1 GW

1 GW
Posts: 3369
Joined: Feb 14 2011 2:43pm

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

Post by casainho » May 26 2018 4:23am

Corrected the pin definition for ONOFF button, now it works.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

nieles   10 kW

10 kW
Posts: 672
Joined: Jul 14 2008 5:39pm
Location: The Netherlands

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

Post by nieles » May 26 2018 9:58am

The first part of the Schematic is done (the interesting bits LOL)
LCD3_display_V0_1.pdf
(93.51 KiB) Downloaded 228 times
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.

Post Reply