Giter Site home page Giter Site logo

ebics / ebics_firmware Goto Github PK

View Code? Open in Web Editor NEW
131.0 20.0 231.0 24.04 MB

Free FOC firmware for Lishui E-Bike-Controllers

Home Page: https://www.pedelecforum.de/forum/index.php?threads/open-source-firmware-fuer-lishui-controller.61113/

C 96.18% Assembly 0.28% Batchfile 0.03% Makefile 0.44% Java 3.07%
foc bldc ebike

ebics_firmware's Introduction

Caution, the Bafang Display protocol is recently not running in the master branch!

This project has now reached a certain maturity, use is always at your own risk. The authors do not accept any liability for damage to property or personal injury!
The Master-branch supports sensored motors and Bafang-, Kunteng- and Kingmeter-Displays and debugging.

User specific settings can be done in a user-friendly gui.

throttle, "torque-simulation" and torquesensor-modes are available.

The sensorless_VESC-branch has adapted the sensorless control of the VESC. Recently optimized for a Fischer ETH 1606 bike. If will work with other motors also, of course.

A short tutorial can be found in the wiki.

Helpful links:

vector-control-for-dummies

space-vector-pwm-intro

UM1052 - STM32F PMSM single/dual FOC SDK v4.3

RM0008 Reference Manual STM32F103xx

System Workbench for STM32

Sensorless approach VESC

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ebics_firmware's People

Contributors

arozhkov2001 avatar erik-smit avatar stancecoke avatar tecnologic avatar tomsen61 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebics_firmware's Issues

Shengyi CMT03 Motor and LD-LS11-F Controller?

Hello,

I have a SCO e-Trekking Premium (Danish brand) and It has a Shengyi CMT03 motor installed. I believe it has a LD-LS11-F controller in it, but I am not totally sure. I cannot find any info on this controller inside the motor.

I noticed the official USB Stick FPS2 connects via TX and RX pins which I have via the display cable. I assume this is for use with Lishui tools like SJW32 and their flasher.

This project's instruction connect via the SWDIO and SWCLK using an STlink for a connection to the STM32 chip on the controller. Is there a difference between these two? I cannot really find a SWDIO and SWCLK connector for my bike. Do I need to open up the motor and make connections via the pins there? Or can I buy a USB Stick FPS2 for connection via TX/RX

I have made a post on Endless Sphere if you care to have a look.

Thanks for the project and the help ๐Ÿ‘

EDIT: I took the motor apart and there is no sign of the mentioned controller. I am pretty sure this is not a Lishui controller on this motor, my mistake. Feel free to close this issue if you feel it's no relevant.

EDIT2: I found the controller, it was much smaller than I expected, I depotted it and got to the PCB. The model number is LSW06-SY3CFSB. It uses the same STM32 chip and has debug ports on the top of the PCB.
IMG_1265
IMG_1266
IMG_1268

What do "Battery Voltage" and "FOC Voltage" in advanced tab of the parameter configurator really mean?

It seems like the macro CAL_BAT_V in generated config.h corresponding to the parameter "Battery Voltage" is only used for battery capacity level calculation for Bafang display module, it is likely a factor to get battery voltage in 0.1 mV from ADC value (probably not mV, as described in https://github.com/EBiCS/EBiCS_Firmware/wiki/The-Lishui-Parameter-Configuator#basic-settings);

Macro CAL_V ("FOC Voltage") is used as a factor to get battery voltage in mV for EBiCS display option, I wonder how it is involved in FOC calculation. The default value 15LL<<8 makes battery voltage measuring incredibly sensitive; besides, the displayed voltage is stucked at 78 V in my installed EBiCS App, while it's not so in raw data received through Bluetooth.

Please tell me if I'm wrong. Thanks.

Project compilcation descriptions will not work with provided gdb on x86_64 linux

Just a heads up for others, nothing the project can do anything about:

If you follow the "windows" installation on linux and make it to compile it's going to stop working once you try to use the stm32 open workbench for debugging as the provided/included arm-none-eabi-gdb is an ancient 32bit version. Since almost no system supports this these days my recommendation will be to download one from e.g. https://gitlab.com/alelec/arm-none-eabi-gcc-deb/-/releases or compile one yourself from the arm sources.

Can be closed but at least it's searchable then (or maybe add to docs).

Also: All uarts must be made extern (except for one of course), otherwise the compiler will treat them as statics and mess up the uart and the program will stall on a HAL_BUSY signal. This does not happen on the windows version for some reason.

R_TEMP_PULLUP question

Do I need to add 10k pullup resistor to 12FET controller for R_TEMP_PULLUP functionality? I have 10k NTC thermistor pulling down in the motor.

Compiling fails with undefined reference to `HAL_IWDG_Refresh'

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -L../Drivers/CMSIS -specs=nosys.specs -specs=nano.specs -T"../STM32F103C6Tx_FLASH.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "LishuiFOC_01.elf" @"objects.list"  -larm_cortexM3l_math -lm
Src/main.o: In function `autodetect':
C:\Users\erikl\OneDrive\Documenten\GitHub\EBiCS_Firmware2\Debug/../Src/main.c:2235: undefined reference to `HAL_IWDG_Refresh'
Src/main.o: In function `MX_IWDG_Init':
C:\Users\erikl\OneDrive\Documenten\GitHub\EBiCS_Firmware2\Debug/../Src/main.c:2521: undefined reference to `HAL_IWDG_Init'
Src/main.o: In function `main':
C:\Users\erikl\OneDrive\Documenten\GitHub\EBiCS_Firmware2\Debug/../Src/main.c:625: undefined reference to `HAL_IWDG_Refresh'
collect2.exe: error: ld returned 1 exit status
makefile:36: recipe for target 'LishuiFOC_01.elf' failed
make: *** [LishuiFOC_01.elf] Error 1

stm32f1xx_hal_iwdg was added to objects.list in 37202aa but seems to be missing from make/objects.list.
Adding it there, makes it complain that it doesn't find the file, so missing from the build. Tried adding it to some files, but haven't had success yet.

Dangerous error produced in speed calculation for EBiCS display method

In case of 2.2 m of wheel circumference, single magnet in the spokes:

#define WHEEL_CIRCUMFERENCE 2200
#define PULSES_PER_REVOLUTION 1

When the speed reaches 4r/s (4 * 2.2 * 3.6 = 31.68 km/h), the interval measured by TIM3 is (1/f)/[1/(64M/7814)] = 8190/f = 8190/4 = 2048; the value in EBiCS is [(int)2200 / ((int)2048 >> 3)] * 36 / 10 = 28.8, nearly 2 km/h error produced.

you can draw two functions in the calculator

y = 2.2*3.6*x
y = 3.6*floor(2200/floor(8190/x/8))

to see the maximum error 4.3 km/h. 29 km/h will be shown as 25 km/h!

I have extracted related code from your project (with many unindented code):

int main(void)
{
	...
	while (1)
	{
		...
		// SPEED signal processing
		if (ui8_SPEED_flag) {
			if(uint32_SPEED_counter > 200) { //debounce
				MS.Speed = uint32_SPEED_counter;
				uint32_SPEED_counter = 0;
				ui8_SPEED_flag = 0;
			}
		}
		...
		if (ui32_tim3_counter > 500) {
			if(uint32_SPEED_counter > 127999)
				MS.Speed = 128000;
			...
			ui8_slowloop_counter++;
			if (ui8_slowloop_counter > 3) {
				ui8_slowloop_counter = 0;
				send_ant_page(0, &MS, &MP);
			}
			ui32_tim3_counter = 0;
		}
		...
	}
}

// elapse frequency of TIM3 is 64M/7814 (Hz), interval is about 122.1 us
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if (htim == &htim3) {
		if(ui32_tim3_counter < 32000)
			ui32_tim3_counter++;
		...
		if (uint32_SPEED_counter < 128000)
			uint32_SPEED_counter++; //counter for external Speed sensor
	}
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	...
	//Speed processing
	if(GPIO_Pin == Speed_EXTI5_Pin)
		ui8_SPEED_flag = 1; //with debounce

}

void send_ant_page(uint8_t page, MotorState_t* MS, MotorParams_t* MP)
{
	...
	// *3,6 for km/h then *10 for LEV standard definition.
	uint16_t speedx10 = MP->wheel_cirumference / ((MS->Speed*MP->pulses_per_revolution) >> 3) * 36;
	
	ui8_tx_buffer[9] = speedx10 & 0xFF; //low byte of speed
	ui8_tx_buffer[10] = speedx10>>8 & 0x07; //lower 3 Bytes(needs correction) of high byte
	...
	HAL_UART_Transmit_DMA(&huart1, (uint8_t *)&ui8_tx_buffer, 12);
}

Thanks.

not compiling with Flash configurator

Hi @stancecoke, on the EBiCS branch, I changed following files to be able to compile :

  • make/objects.list (line 21)
    "Src/eeprom.o"

  • make/subdir_src.mk
    line 12
    ../Src/eeprom.c \
    line 24
    ./Src/eeprom.o \
    line 36
    ./Src/eeprom.d \

Also the configurator seems to remove some config.h lines like the EBICs display.

Error compile

Hello,

when compile generate error:

Building target: LishuiFOC_01.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -L ../Drivers/CMSIS -
specs=nosys.specs -specs=nano.specs -T"../STM32F103C6Tx_FLASH.ld" -Wl,-Map=outpu
t.map -Wl,--gc-sections -o "LishuiFOC_01.elf" @"objects.list" -larm_cortexM3l_m
ath -lm
c:/stm32/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../.
./../../arm-none-eabi/bin/ld.exe: Src/display_kunteng.o:C:\Users\g\Desktop\ok pe
r luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/display_kunteng.
c:33: multiple definition of huart1'; Src/display_ebics.o:C:\Users\g\Desktop\ok per luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/display_ebics .c:13: first defined here c:/stm32/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../. ./../../arm-none-eabi/bin/ld.exe: Src/display_kunteng.o:C:\Users\g\Desktop\ok pe r luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/display_kunteng. c:21: multiple definition of ui8_rx_buffer'; Src/display_ebics.o:C:\Users\g\Des
ktop\ok per luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/displa
y_ebics.c:14: first defined here
c:/stm32/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../.
./../../arm-none-eabi/bin/ld.exe: Src/display_kunteng.o:C:\Users\g\Desktop\ok pe
r luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/display_kunteng.
c:13: multiple definition of ui8_tx_buffer'; Src/display_ebics.o:C:\Users\g\Des ktop\ok per luca\EBiCS_Firmware-master\EBiCS_Firmware-master\Debug/../Src/displa y_ebics.c:15: first defined here c:/stm32/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../. ./../../arm-none-eabi/bin/ld.exe: Src/main.o:C:\Users\g\Desktop\ok per luca\EBiC S_Firmware-master\EBiCS_Firmware-master\Debug/../Src/main.c:89: multiple definit ion of huart1'; Src/display_ebics.o:C:\Users\g\Desktop\ok per luca\EBiCS_Firmwa
re-master\EBiCS_Firmware-master\Debug/../Src/display_ebics.c:13: first defined h
ere
c:/stm32/gcc-arm-none-eabi-10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../.
./../../arm-none-eabi/bin/ld.exe: Src/main.o:C:\Users\g\Desktop\ok per luca\EBiC
S_Firmware-master\EBiCS_Firmware-master\Debug/../Src/main.c:84: multiple definit
ion of `htim1'; Src/FOC.o:C:\Users\g\Desktop\ok per luca\EBiCS_Firmware-master\E
BiCS_Firmware-master\Debug/../Src/FOC.c:42: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [LishuiFOC_01.elf] Error 1

Status of branches

Hello,
we are working on a new opensource firmware for Xiaomi escooter controller.
it has 3 shunts, external AOPS and a STM32F103C8T6.
It seems very close from your project and Lishui controller.
We would like to know the current status of your different branches ;)
Do you have a Telegram account ?
Regards and happy holidays ;)

Dangerous error produced in speed calculation for EBiCS display method

In case of 2.2 m of wheel circumference, single magnet in the spokes:

#define WHEEL_CIRCUMFERENCE 2200
#define PULSES_PER_REVOLUTION 1

When the speed reaches 4r/s (4 * 2.2 * 3.6 = 31.68 km/h), the interval measured by TIM3 is (1/f)/[1/(64M/7814)] = 8190/f = 8190/4 = 2048; the value in EBiCS is [(int)2200 / ((int)2048 >> 3)] * 36 / 10 = 28.8, nearly 2 km/h error produced.

you can draw two functions in the calculator

y = 2.2*3.6*x
y = 3.6*floor(2200/floor(8190/x/8))

to see the maximum error 4.3 km/h. 29 km/h will be shown as 25 km/h!

I have extracted related code from your project (with many unindented code):

int main(void)
{
	...
	while (1)
	{
		...
		// SPEED signal processing
		if (ui8_SPEED_flag) {
			if(uint32_SPEED_counter > 200) { //debounce
				MS.Speed = uint32_SPEED_counter;
				uint32_SPEED_counter = 0;
				ui8_SPEED_flag = 0;
			}
		}
		...
		if (ui32_tim3_counter > 500) {
			if(uint32_SPEED_counter > 127999)
				MS.Speed = 128000;
			...
			ui8_slowloop_counter++;
			if (ui8_slowloop_counter > 3) {
				ui8_slowloop_counter = 0;
				send_ant_page(0, &MS, &MP);
			}
			ui32_tim3_counter = 0;
		}
		...
	}
}

// elapse frequency of TIM3 is 64M/7814 (Hz), interval is about 122.1 us
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if (htim == &htim3) {
		if(ui32_tim3_counter < 32000)
			ui32_tim3_counter++;
		...
		if (uint32_SPEED_counter < 128000)
			uint32_SPEED_counter++; //counter for external Speed sensor
	}
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	...
	//Speed processing
	if(GPIO_Pin == Speed_EXTI5_Pin)
		ui8_SPEED_flag = 1; //with debounce

}

void send_ant_page(uint8_t page, MotorState_t* MS, MotorParams_t* MP)
{
	...
	// *3,6 for km/h then *10 for LEV standard definition.
	uint16_t speedx10 = MP->wheel_cirumference / ((MS->Speed*MP->pulses_per_revolution) >> 3) * 36;
	
	ui8_tx_buffer[9] = speedx10 & 0xFF; //low byte of speed
	ui8_tx_buffer[10] = speedx10>>8 & 0x07; //lower 3 Bytes(needs correction) of high byte
	...
	HAL_UART_Transmit_DMA(&huart1, (uint8_t *)&ui8_tx_buffer, 12);
}

Thanks.

Does this work with Rad Power Bikes?

Hi,

I'm wondering whether this controller firmware is applicable to Rad Power Bikes with the Lishui controller, and I'm wondering whether the original display would be supported. If not, would the "open source eBike display" from EBiCS work with the protocol that this firmware uses?

Thanks!

Autodetect broken

Autodetect is currently broken on master for me.
It seems to move one tick and then hang, just pushing current through the motor, but the motor remains rock solid and unmovable.
Suspecting the watchdog, I reverted to b4ccd57 and here it still works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.