Jump to content

Firmware


jayjay23

Recommended Posts

2 hours ago, electric_vehicle_lover said:

Since your firmware mainly lacks the EUC balance algorithm, I can't help you. After I finish the EUC balance algorithm, I may help you on that time.

It doesn't have to be VESC based, I can make entirely new designs pretty quickly now. The main thing is choosing an MCU that makes coding EUC software easy and reduces motor control components.

  • Upvote 1
Link to comment
Share on other sites

5 hours ago, lizardmech said:

It doesn't have to be VESC based, I can make entirely new designs pretty quickly now. The main thing is choosing an MCU that makes coding EUC software easy and reduces motor control components.

Well, I would make a design based on MW 30B4 and exchange only the STM32F103 for something a bit more powerful with FPU. There is even another STM32Fxxx direct pin replacement for STM32F103 that does FPU. Should be a matter just to use that instead and keep the same board.
This board is really cheap and simple to repair/mod/hack and understand technology. Also is very flexible: can work with the following batteries packs used on ebikes and many other devices:
- 24V (7S)
- 36V (10S)
- 48V (13S)
- 60V (16) for unicycles

The thing is, you can make the board what would be the next steps?? -- how to get production of them in quantities like 250 units to get decent prices per unit? how to get a shop to sell a unit and ship worldwide?? -- seems unlikely to happen :-(

Edited by electric_vehicle_lover
Link to comment
Share on other sites

Motor max current

Developed the code and tested:
• blocked the motor with my hand
• motor max current = 4 amps

As we can see on the graphs, Id current value (green) is 4000mA as defined for motor max current. Is possible to see that even increasing commanded PWM duty_cycle (orange) the Id current kept always at 4000mA - the force at my hand that motor does kept constant, even if it is blocked and I increase/decrease/maintain duty_cycle.

I tested with other values like 1A and 2A and the force I had to keep blocking with my hand kept constant and scaled accordingly with different Id currents.

0001.png

The code was kind of simple:

Added to FOC slow loop:

// Max current controller
//------------------------------------------------------------------------
if (abs_f(iq) > MOTOR_MAX_CURRENT) // start limitting the current
{
if (motor_max_current_factor > 0)
{
motor_max_current_factor -= MOTOR_MAX_CURRENT_STEP;
}
}
else
{
if (motor_max_current_factor < 1000)
{
motor_max_current_factor += MOTOR_MAX_CURRENT_STEP;
}
}
// ------------------------------------------------------------------------

And on FOC fast loop/PWM apply value:

// apply over current limit factor
_duty_cycle *= motor_max_current_factor;
_duty_cycle /= 1000;

Edited by electric_vehicle_lover
Link to comment
Share on other sites

Implemented motor over current and works!! Now I am almost ready to use this board and firmware on my electric bicycle. Before that I want to put the firmware looking at board temperature (reading temperature sensor on the MPU6050) and warn the user and limit the power when it reaches 65ºC. The electric unicycle application need to have also this temperature limit feature.
---
When getting at motor over current, the motor will coast and the buzzer will stay on in loop. User will need to power off the EUC.

Over current is currently defined for 25 Amps (MW 30B4 board should handle 30A). This over current will protect the board from burning, any possible damage to the motor and battery pack. I saw some reports of Gotways EUCs boards that got faulty when they were blocked a bit of time on the sand, the motor over current limit/protection should avoid this situations!

The code is simple to understand, on FOC fast loop (every 50us):

if (
(abs(_adc_phase_a_current) > ADC_MOTOR_OVER_CURRENT_LIMIT) ||
(abs(_adc_phase_b_current) > ADC_MOTOR_OVER_CURRENT_LIMIT) ||
(abs(_adc_phase_c_current) > ADC_MOTOR_OVER_CURRENT_LIMIT))
{
over_current_fault_counter += 10;

if (over_current_fault_counter > 1000) { motor_over_current_action(); }
}
else
{
if (over_current_fault_counter > 0) { over_current_fault_counter -= 1; }
}

void motor_over_current_action (void)
{
// disable PWM / motor!!
disable_phase_a ();
disable_phase_b ();
disable_phase_c ();

buzzer_on ();

// infinite loop: block here, user will need to reset the system
while (1) ;
}
 

Video:

 

Edited by electric_vehicle_lover
  • Upvote 2
Link to comment
Share on other sites

2 hours ago, electric_vehicle_lover said:

The thing is, you can make the board what would be the next steps?? -- how to get production of them in quantities like 250 units to get decent prices per unit? how to get a shop to sell a unit and ship worldwide?? -- seems unlikely to happen :-(

Pretty easy these days, there's a bunch of places that handle low volume assembly and handle shipping like https://www.seeedstudio.com/ The microworks design is no good because it has through hole parts, better to use all SMD parts a robot can place. Same with using cheap MCUs, some newer MCUs have features that let you remove some other parts so it ends up smaller and cheaper. You have to look closely at the MCU features as well, some MCUs have specialized hardware that makes motor control much easier to code.

  • Upvote 3
Link to comment
Share on other sites

10 hours ago, electric_vehicle_lover said:

@lizardmech, and can you make a plan to handle and negotiate all of that with that company??

There's quite a few companies to choose from, need to build prototypes first so size and component costs can be calculated.

Can you have a look at a certain MCU and it's software? I have been playing around with one of the newer Ti C2000 MCUs, it has a dedicated math accelerator for trigonometry. Basically you can just use floats everywhere, enable a compiler flag on c code and it will perform most calculations associated with motor control and balancing in hardware. 

Link to comment
Share on other sites

2 hours ago, lizardmech said:

There's quite a few companies to choose from, need to build prototypes first so size and component costs can be calculated.

I would not invest to build a prototype without further planning first. Right now we have at least prof of concept, the 30B4 board works very well!!

30B4 costs $55 and I don't want to pay more than that, in fact I wish it was cheaper. I just can see the price increase a bit due to using a more expensive microcontroller, to have FPU and more flash memory, nothing more. Would not pay more than $60 for a board. Or maybe there can be different versions of the board, and I would start with a cheap one like 30B4 that works already for electric unicycles, electric skates (one wheel) and electric bicycles -- from 24V up to 60V. The more expensive versions could handle more power full motor and maybe higher voltages than 60V.
 

2 hours ago, lizardmech said:

Can you have a look at a certain MCU and it's software? I have been playing around with one of the newer Ti C2000 MCUs, it has a dedicated math accelerator for trigonometry. Basically you can just use floats everywhere, enable a compiler flag on c code and it will perform most calculations associated with motor control and balancing in hardware. 

That's simple here - STM32! -- it's very popular: cheap $2 boards on Ebay; inside hoverboards, skates, unicycles, drones, etc.
And I am not interested to used closed source technology like TI IntaSpin, instead, using good OpenSource technology like VESC.

So, for me the price is really important!!! No point to invest on something that will have limited usage and price is probably the most important factor.

 

Edited by electric_vehicle_lover
Link to comment
Share on other sites

1 minute ago, electric_vehicle_lover said:

I would not invest to build a prototype without further planning first. Right now we have at least prof of concept, the 30B4 board works very well!!

30B4 costs $55 and I don't want to pay more than that, in fact I wish it was cheaper. I just can see the price increase a bit due to using a more expensive microcontroller, to have FPU and more flash memory, nothing more. Would not pay more than $60 for a board. Or maybe there can be different versions of the board, and I would start with a cheap one like 30B4 that can work for electric unicycles, electric skates (one wheel) and electric bicycles. The more expensive versions could handle more power full motor and maybe higher voltages than 60V.
 

That's simple here - STM32! -- it's very popular: cheap $2 boards on Ebay; inside hoverboards, skates, unicycles, drones, etc.
And I am not interested to used closed source technology like TI IntaSpin, instead, using good OpenSource technology like VESC.

So, for me the price is really important!!! No point to invest on something that will have limited usage and price is probably the most important factor.

 

30B4 can only be that cheap because production batches are in the 1000s., fixating on getting the board cost down to $50 is completely irrational, the controller is one of the cheapest part of an ebike or euc but one of the most critical when it comes to performance.

Saving money on cheap MCUs might seem like a great idea but what happens when saving $8 on an MCU means adding $10 more parts to the design to work around MCU limitations? Also consider programming complexity and time required. At the moment you're spending time trying to work around MCU limitations, on newer MCUs you can directly perform the math you need with a few lines of code.

The Ti MCU I have been testing isn't using instaspin it's completely open source. Instaspin is actually not very good in many regards, it uses IQmath everywhere which makes scaling a headache while not even using FPU hardware. On the open source FOC servo controller firmware I have been looking at 90% of the code is configuring MCU hardware such as PWM, ADC and timers  the actual motor control code is isolated and easily replaced with whatever you want.

Link to comment
Share on other sites

4 minutes ago, lizardmech said:

At the moment you're spending time trying to work around MCU limitations, on newer MCUs you can directly perform the math you need with a few lines of code.

To resume: I prefer to use this cheap 30B4 board and continue working around the MCU limitations. I think is possible to ask MW to improve the board using the direct pin replacement of STM32 that have FPU and 2x or 4x times more flash memory.

Link to comment
Share on other sites

3 minutes ago, electric_vehicle_lover said:

To resume: I prefer to use this cheap 30B4 board and continue working around the MCU limitations. I think is possible to ask MW to improve the board using the direct pin replacement of STM32 that have FPU and 2x or 4x times more flash memory.

There's no way to even know if you will ever be able to get them again now. Why only use proprietary hardware that isn't even possible to buy?

Link to comment
Share on other sites

20 minutes ago, lizardmech said:

There's no way to even know if you will ever be able to get them again now. Why only use proprietary hardware that isn't even possible to buy?

That's a risk. But they are ready to sell right now, it is just a matter to call Mr. Lee on Skype. I really believe they will be back next month with a renewed products.

In the case MW stop selling this board, I think will be possible to jump on similar hardware, even if is composed of 3 parts: STM32 board with IMU (from drones application) + ESC board + bluetooth module. There are a lot of this boards, cheap, from Ebay/China, for Arduino, etc. STM32 with FPU are found on Ebay for the drones application, with advanced OpenSource firmware.

 

Edited by electric_vehicle_lover
Link to comment
Share on other sites

I was looking around the different options a bit earlier. It seems ARM Cortex M4F's have FPU-instructions? I was looking at ST's STM32F4's that have evaluation boards starting at around $15, which already contain a 3-axis gyro, accelerometer and magnetometer (the last one is of course not actually needed with balancing), such as:

http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/32f411ediscovery.html

The STM32F411E-DISC0 kit is designed to evaluate the features of the STM32F411 series of 32-bit microcontrollers. The STM32F411 microcontroller is based on the ARM Cortex-M4F core with floating-point maths unit. This Discovery board is based around the STM32F411VET6 device.

  • STM32F411VET6 microcontroller featuring 512 KB of Flash memory, 128 KB of RAM in an LQFP100 package
  • L3GD20: ST MEMS motion sensor 3-axis digital output gyroscope
  • LSM303DLHC: ST MEMS system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor

The chips themselves seem capable of motor drive, as long as there's enough PWM outputs (probably it is enough just to adjust timers "bit-banging" whatever ports with digital outputs?) and ADCs (at least two for FOC, probably more needed for other stuff like measuring battery voltage etc)?

Of course the evaluation board would need to have a separate board for gate drive, mosfet half-bridges & current measurement to run the motor, plus probably contains lots of unnecessary components. But as a start, a low-cost evaluation board would seem a good way to go (for me, that is :P) and as a starting point for a custom board?

Edited by esaj
  • Upvote 1
Link to comment
Share on other sites

39 minutes ago, esaj said:

I was looking around the different options a bit earlier. It seems ARM Cortex M4F's have FPU-instructions? I was looking at ST's STM32F4's that have evaluation boards starting at around $15, which already contain a 3-axis gyro, accelerometer and magnetometer (the last one is of course not actually needed with balancing), such as:

http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/32f411ediscovery.html

The STM32F411E-DISC0 kit is designed to evaluate the features of the STM32F411 series of 32-bit microcontrollers. The STM32F411 microcontroller is based on the ARM Cortex-M4F core with floating-point maths unit. This Discovery board is based around the STM32F411VET6 device.

  • STM32F411VET6 microcontroller featuring 512 KB of Flash memory, 128 KB of RAM in an LQFP100 package
  • L3GD20: ST MEMS motion sensor 3-axis digital output gyroscope
  • LSM303DLHC: ST MEMS system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor

The chips themselves seem capable of motor drive, as long as there's enough PWM outputs (probably it is enough just to adjust timers "bit-banging" whatever ports with digital outputs?) and ADCs (at least two for FOC, probably more needed for other stuff like measuring battery voltage etc)?

Of course the evaluation board would need to have a separate board for gate drive, mosfet half-bridges & current measurement to run the motor, plus probably contains lots of unnecessary components. But as a start, a low-cost evaluation board would seem a good way to go (for me, that is :P) and as a starting point for a custom board?

The main thing is the ADC and PWM hardware, this is where most of the STM32 are limited they're very much general purpose MCUs. For example the max PWM resolution on some c2000 PWM is 170ps vs 4ns on the stm32. The ADC conversion is twice as long on the more general purpose MCUs. The biggest limitation is the inputs most of the more general purpose MCUs do not support differential analogue signals or delta-sigma modulators. Most of the newest current sensing ICs need either of those. Then there's other options such as using GaN fets at high frequencies to reduce the need for electrolytic capacitors and using them allows the entire 12V supply to be eliminated.

At the moment I have STM32F4 446RE and 405, freescale kinetis kv31 and Ti C2000 f28377S

The F4 446RE is a slightly faster and cheaper version than the VESC MCU, 180mhz vs 168mhz 512kb/128kb vs 1mb/192kb.

Kinetis KV31 m4 core at 140mhz ?Similar to the STM but quite cheap to buy.

C2000 f28377S technically the cpu is pretty weak for general purpose tasks but includes a special FPU which basically has an ASIC that can perform all the complex math needed for FOC in hardware. If that wasn't enough it has a second FPU that can run tasks without using the CPU and has access to ADC + PWM. Also has high res PWM, differential ADC and hardware based delta sigma processing.

In theory the C2000 should be much better for an EUC if it performs as advertised. I need to run some benchmarks on them all using FOC loops kalman filter etc. But I don't know how to make the code to test them out.  

  • Upvote 3
Link to comment
Share on other sites

7 minutes ago, lizardmech said:

The main thing is the ADC and PWM hardware, this is where most of the STM32 are limited they're very much general purpose MCUs. For example the max PWM resolution on some c2000 PWM is 170ps vs 4ns on the stm32. The ADC conversion is twice as long on the more general purpose MCUs. The biggest limitation is the inputs most of the more general purpose MCUs do not support differential analogue signals or delta-sigma modulators. Most of the newest current sensing ICs need either of those. Then there's other options such as using GaN fets at high frequencies to reduce the need for electrolytic capacitors and using them allows the entire 12V supply to be eliminated.

Ah, ok, didn't think there was that much difference. So probably better go with a more high-end MCU than using low-end + a bunch of extra components for all the needed things, taking up board-space and adding complexity...

 

7 minutes ago, lizardmech said:

At the moment I have STM32F4 446RE and 405, freescale kinetis kv31 and Ti C2000 f28377S

The F4 446RE is a slightly faster and cheaper version than the VESC MCU, 180mhz vs 168mhz 512kb/128kb vs 1mb/192kb.

Kinetis KV31 m4 core at 140mhz ?Similar to the STM but quite cheap to buy.

C2000 f28377S technically the cpu is pretty weak for general purpose tasks but includes a special FPU which basically has an ASIC that can perform all the complex math needed for FOC in hardware. If that wasn't enough it has a second FPU that can run tasks without using the CPU and has access to ADC + PWM. Also has high res PWM, differential ADC and hardware based delta sigma processing.

In theory the C2000 should be much better for an EUC if it performs as advertised. I need to run some benchmarks on them all using FOC loops kalman filter etc. But I don't know how to make the code to test them out.  

The F28377S Launchpad doesn't seem that bad either, around 30€, funny that the MCU-chip itself alone is over 2/3rds of that when bought in small quantities. I know I should move on to "real" MCUs from the 8-bit ATMegas, but as I have no experience with the toolchains and the gazillion ARM-development environments out there, I can't be of much help until I get some hardware and learn the basics ;)

Link to comment
Share on other sites

16 minutes ago, Tomek said:

@lizardmech, saw your post at http://vedder.se/forums/viewtopic.php?f=6&t=590&start=20#p4275

looks great! really curious how it will fare with VESC6 firmware... (almost, almost there!)

btw what's the consolidated price from your prototype's bill of materials?

I think it's maybe $110 USD in moderate quantities, most of the cost is capacitors and mosfets. Though it's complete overkill it should be able to drive up to something like 8KW motors. The chinese controllers for that much power sell for $400 or so.

  • Upvote 1
Link to comment
Share on other sites

3 hours ago, electric_vehicle_lover said:

Search on Ebay for "Raceflight Betaflight CC3D" that costs $20:

Features:
- MPU6000 SPI Bus
- 128Mb Flash(16M Byte)
- 6PWM output (Pinheaders)
- Only 36x36mm, mount holes 30.5x30.5mm
- STM32 F405 MCU, frequency up to 168Mhz

 

 

It's no cheaper than what I can build them for, last batch of f405 cost me $8 per mcu with free shipping. Riser board are a headache signaling issues, they vibrate loose. The f405 is old anyway the f446re is faster and cheaper. You can buy all of these parts straight from the manufacturer you will never get cheaper MCUs by harvesting them out of other products.

Link to comment
Share on other sites

Because of all uncertainty, I decided to talk with a developer that I met on Endless-sphere (and is also in Portugal) and that designed a controller for EBikes, to replace the original board of cheap ones and still use the same aluminum bar and case for mosfets. He will investigate the possibility to change the original microcontroller to the same as 30B4 board, to be cheap and also the pin compatible higher version of STM32. We need to explore ways to have assembly done by someone or automatically in china or such, even for small quantities. This board may have also the IMU and also work for EUC application.

The most important objective: be as cheap as possible but must do FOC and bluetooth; easy as possible to assembly by hand.

The project is here: https://endless-sphere.com/forums/viewtopic.php?f=2&t=88285&p=1287903#p1287903

DSC_0681_800.JPG

 

  • Upvote 1
Link to comment
Share on other sites

7 hours ago, electric_vehicle_lover said:

Because of all uncertainty, I decided to talk with a developer that I met on Endless-sphere (and is also in Portugal) and that designed a controller for EBikes, to replace the original board of cheap ones and still use the same aluminum bar and case for mosfets. He will investigate the possibility to change the original microcontroller to the same as 30B4 board, to be cheap and also the pin compatible higher version of STM32. We need to explore ways to have assembly done by someone or automatically in china or such, even for small quantities. This board may have also the IMU and also work for EUC application.

The most important objective: be as cheap as possible but must do FOC and bluetooth; easy as possible to assembly by hand.

The project is here: https://endless-sphere.com/forums/viewtopic.php?f=2&t=88285&p=1287903#p1287903

DSC_0681_800.JPG

 

It's literally a Ti instaspin board with a drv8301, it's not going to be running any EUCs without a complete redesign, same issue as the VESC hardware.

  • Upvote 1
Link to comment
Share on other sites

6 hours ago, lizardmech said:

It's literally a Ti instaspin board with a drv8301, it's not going to be running any EUCs without a complete redesign, same issue as the VESC hardware.

That being said looking through his code it's fairly nice job of expanding on instaspin framework. It would be easier to turn this into an EUC controller than work with microworks controllers. It would only come down to if you are willing to use the instaspin observer as a stopgap until you can write an open alternative. If you both worked together on the software it wouldn't take long at all to get it working.

  • Upvote 1
Link to comment
Share on other sites

The only thing I still don't like is the idea to need assembly the board. Looks like PCB assembly service can cost $0.2 for resistors and higher values for bigger components!! Very expensive.

Another idea - and this one seems a bit crazy: use the cheap $22 EBike controller from http://www.szktdz.com/en/news.php?type=344
This ones have a STM8S105 8bits, 16 MHz, 32 KB. The controller board have the header for programming. They have 1 shunt resistor. They also have wires on outside for UART + GND + VBatt. I will make the OpenSource firmware for them but BLDC only, for sure :-)
The crazy idea: firmware for the STM8S105 would only control the PWM of the motors. Another external board with STM32F303 + MPU ($25 on Ebay) reads hall sensors 2 phase currents and do FOC, sending the angle correction value to the STM8S105 by UART. The current signals would be read using a 50A ACS758 (wired on the 2 wires phase on the outside of the controller) also found on Ebay, cheap module. This would mean: user will need to open the controller and flash the STM8S105. Also flash the FOC firmware on the STM32F303 board. This would be more like Arduino world, using board modules, wiring cables and hit the flash firmware button.

Edited by electric_vehicle_lover
Link to comment
Share on other sites

That's more or less impossible, ADC sampling has to be synchronized to PWM, the latency issues are too significant. I don't get the fixation on cheap controllers, the batteries and motor costs mean any unicycle will be $300 or more, on top of that most of the cheap controllers have high shipping fees you will probably end up paying $100 USD or more anyway unless you order a container load. Is saving $30 worth it when the only option for decent EUCs at the moment is to buy existing models for $800 or more?

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...