Jump to content

Firmware


jayjay23

Recommended Posts

20 hours ago, electric_vehicle_lover said:

@Tomek I couldn't understand what you mean. Can you please explain using other words?

in my understanding, the principle works like in these sketches.

a ) with one hall sensor you get a "tick" for each magnet, so if you have 47 magnets, you get a tick every ~7.66 degree

b ) with more sensors you get more resolution, i.e. with each "step" first sensor1 ticks, then sensor2, then sensor3 etc., and then again

c ) this situation gives same reading as b )

(edits: small sketch correction, and descriptions of the sketch...)

 

FullSizeRender-3.jpg

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

Thanks @Tomek. I verified that phase A and phase B voltages are exchanged on my EUC2 motor. Still I don't have the firmware running on it yet...

Max motor velocity of my EUC1
I just decided to run the motor at 60V (I usually test at 22V that is the minimum voltage for MicroWorks 30B4 board to work) and record a video.
Here is the calcs for the max velocity:
Vin = 60V
Motor have 46 magnets. Each 1 will give a voltage level (ON or OFF) on the hall sensor signal. I measured with oscilloscope a square wave signal of 7.2ms period. 1 full rotation of the wheel is: 46 * (7.2ms/2) = 165.6ms. For 1 second will rotate: 1/0.1656 = 6 rotations per second.
Velocity in Km/h: (6 * 1.12 * 60 * 60) / 1000 = 24km/h.
The wheel have a 14 inch diameter tire. The perimeter of the wheel is ~1.12 meters (measured with inflated tire and without anyone on top of the EUC).

I think this cheap EUCs like mine EUC1 just gave about 16km/h max speed. The difference 24km/h - 16km/h may be reserved torque / force to be able to balance the rider.

 

Edited by electric_vehicle_lover
Link to comment
Share on other sites

I got the EUC2 motor working but I had to make a few changes (and involved a lot of guess working). The difference for this motor is that phase A and Phase B and exchanged but is not enough to exchange the cables... In firmware I had to exchange the phase A for phase B in the wave timings generation (120º between each of them), the calcs for the angle estimation, exchange Ia to Ib, increase rotor angle by 45 degrees and finally the signal/direction of angle correction. That's a LOT and that's why different boards do not work for different motors!! But with this firmware that will be possible - using the same board with custom configurations for each motor.

Max motor velocity of my EUC2
I just decided to run the motor at 60V (I usually test at 22V that is the minimum voltage for MicroWorks 30B4 board to work) and record a video.
Here is the calcs for the max velocity:
Vin = 60V
Motor have 46 magnets. Each 1 will give a voltage level (ON or OFF) on the hall sensor signal. I measured with oscilloscope a square wave signal of 7.6ms period. 1 full rotation of the wheel is: 46 * (7.6ms/2) = 174.8ms. For 1 second will rotate: 1/0.1656 = 5.7 rotations per second.
Velocity in Km/h: (5.7 * 1.12 * 60 * 60) / 1000 = 23km/h.
The wheel have a 14 inch diameter tire. The perimeter of the wheel is ~1.12 meters (measured with inflated tire and without anyone on top of the EUC).
I think this cheap EUCs like mine EUC2 just gave about 16km/h max speed. The difference 23km/h - 16km/h may be reserved torque / force to be able to balance the rider.

 

  • Upvote 1
Link to comment
Share on other sites

Previously I used integers calculations for motor position_correction_value of FOC and now I implement with floats to see if the motor noise could decrement -- and it didn't, IMO.
The FOC_fast_loop() do that calculations and here is the time it takes:
- integers: 9us
- floats: 50us

I am currently using PWM at 10kHz (100us) to have spare time for this calculations... the time the calculations take will limit the PWM speed. The EUCs I have, the original firmware runs PWM at 15.625kHz (64us).

So now I know some limits. I think I will focus next on the currents measurements... I think most of noise and oscillation came from currents noise values.

Then I want to make the motor running on the both directions and finally make the balance code/EUC application.

 

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

Can you make it so PWM runs at a multiple of the FOC loop? For example have it update every third PWM cycle so you get a 5khz FOC loop with 15khz pwm. I think most controllers do a significant amount of signal processing on the current readings as well.

Link to comment
Share on other sites

3 hours ago, lizardmech said:

Can you make it so PWM runs at a multiple of the FOC loop? For example have it update every third PWM cycle so you get a 5khz FOC loop with 15khz pwm. I think most controllers do a significant amount of signal processing on the current readings as well.

I am now running at 20kHz and didn't see any improvements. I think I will stop for now on this and keep moving to having the EUC application.

About the currents, I did filter them when reading at the PWM frequency and FOC didn't work. But filtering on DQ frame (Iq and Iq) works well so I am sticking with this - Shane Colton also just filter like that. And I think VESC also don't filter the currents readings before use on Park/Clark transformations.

Edited by electric_vehicle_lover
Link to comment
Share on other sites

Wow! Good progress recently.

Do you think your code is advanced enough to drive an ebike or etrott motor?

I have a Microworks (6 mosfet) and a ReinTech (12 mosfets)  boards laying around I'd like to test for a two wheels vehicle, no need for balance code.

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

13 minutes ago, RolluS said:

Wow! Good progress recently.

Do you think your code is advaneced enough to drive an ebike or etrott motor?

I have a Microworks (6 mosfet) and a ReinTech (12 mosfets)  boards laying around I'd like to test for a two wheels vehicle, no need for balance code.

Yes, I am being working kind of full time recently.

It is difficult to make the code work for a different motor, difficult changes on the code that need to be verified, like changes on the phases wires must change the code in a few parts.

Also current code lacks max current management/protection (Iq current). And the potentiometer I am using need to control the motor current and not PWM as it is doing now (but that should be an easy change on the code: Iq current).

The code for now also do not rotate the motor on both directions but for an electric bicycle should not be a need.

So, if you are willing to develop a bit the code, yes, it is near for what you are looking for.

I will need to work on current management and rotating on both directions, as next steps.

Link to comment
Share on other sites

I think I'm skilled enough to adapt the existing code 'I'm a hobbyist, not a developer). I have a stlink 32, power supply, etc...

Power managment may be tested on the street then. Here is the vehicle: (currently shipping from Netherlands to France):

c677558bbedd7d2a628e7342a4ef2e54.jpg

(note: vehicule on the left, on right it's not the same ride)

Here is the motor:

IMG_20170214_210850b.thumb.jpg.7557d4b2897e12106031a5436dca4fab.jpg

Here are the boards:

IMG_20161110_185727c.thumb.jpg.f858cbe8a156e5ce09b29e0761e69005.jpg

How is the potentiometer electrically working? I think I'm seeing an interface between it and the board

 

  • Upvote 3
Link to comment
Share on other sites

Uau!! Great idea to put that vehicle electric!! I didn't find a GausWheel electric, maybe you will be the first :-)

That GausWheel seems the same idea of an EUC, but without the motor and balance, it needs the second small wheel and also the mechanical brake.

I can help you and in fact I am very curious about your idea!!

For the potentiometer, please see refer to the schematic of the 30B4 board: https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-30B4-30kmh-controller-board-with-bluetooth

I am using pin 2 of J6 as analog input to the STM32F103. Taking the 3.3V signal from J? header (LEDs header) and the GND from the same J6 header. Very simple.

When we have the firmware for the 6 mosfet boards, we can move to the boards with 12 mosfets for more powerful and rapid motors, maybe like 22'' wheels :-)

  • Upvote 3
Link to comment
Share on other sites

On 26/03/2017 at 8:11 PM, electric_vehicle_lover said:

Uau!! Great idea to put that vehicle electric!! I didn't find a GausWheel electric, maybe you will be the first :-)

That GausWheel seems the same idea of an EUC, but without the motor and balance, it needs the second small wheel and also the mechanical brake.

I can help you and in fact I am very curious about your idea!!

Link to comment
Share on other sites

I know a french vESC reseller/maker sent a board to Gausswheel headquarter in Hungary.

I've bought an ebike programmable board, so I can have a reference of what a finished product can do. Thank you for your help and potentiometer clarification. 

The motor is a 48V/1000W so it will definitly work on the 6 mosfet board (I'm confident with the higher voltage). My 12 mosfet board has a throttle header, near J6

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

This boards can work with a minimum of 22v input, tested with the lab power supply. So something like 30v battery may be ok as minimum.

I now know how VESC and Shane Colton limit the max current and over current. I will implement something alike.

I am now implementing current control instead of the duty cycle control and I found some bugs that I need to resolve before moving forward.

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

Using 30V will surely reduce top speed but why not if it can be safer to the hardware. I need current limit working before attempting to test.

Current is torque and duty cycle is speed right? So controlling current will control balance on an EUC and acceleration on my thing.
 

I'm a noob at flashing anything else than an arduino, is there some doc for crosscompiling and flashing on your github please?

Link to comment
Share on other sites

13 hours ago, RolluS said:

Current is torque and duty cycle is speed right? So controlling current will control balance on an EUC and acceleration on my thing.

I'm a noob at flashing anything else than an arduino, is there some doc for crosscompiling and flashing on your github please?

 

Current is torque. Duty cycle is the amount of voltage you apply to motor, for instance, 0.5 (50%) duty cycle will be 30V applied to motor (assuming 60V on the battery).
Balance controller will have as input the angle of the IMU and as output the current value. And yes, I think you will want controlling the current for the bicycle application.

For compiling, you can find many information on google for using Eclipse IDE and flash and debug using OpenOCD. I shared my very resumed notes using a CherryTree notes file:

Screenshot_from_2017-03-31_10-44-33.png

The notes files is on documentation repo: https://github.com/EGG-electric-unicycle/documentation/blob/8b71785d09e58bff6f927c09a71377e5c2ba3229/EGG_Electric_Unicycle-firmware.ctb

 

  • Upvote 1
Link to comment
Share on other sites

Found an interesting things about the microcontroller on MicroWorks 30B4 boards:
- there is a version of Arduino (Blue Pill board on Ebay) with the same microcontroller, that costs only 2€!!!
- this microcontroller STM32F103C8T6 officially have 64kbytes flash memory for the firmware but in reality they have 128kbytes :-) :-)

Just found an important tool for debug, that plots in real time the data from the serial port/bluetooth from MicroWorks 30B4 board: https://bitbucket.org/hyOzd/serialplot/

serialplot.png

  • Upvote 1
Link to comment
Share on other sites

On 31/03/2017 at 1:21 PM, electric_vehicle_lover said:

Found an interesting things about the microcontroller on MicroWorks 30B4 boards:
- there is a version of Arduino (Blue Pill board on Ebay) with the same microcontroller, that costs only 2€!!!
- this microcontroller STM32F103C8T6 officially have 64kbytes flash memory for the firmware but in reality they have 128kbytes :-) :-)

Today I hit the 64kbytes of firmware flash memory... then I went to explore the mentioned option... and I found the needed instructions on OpenOCD mailing list:

On Tue, Feb 05, 2013 at 04:42:53PM +0000, gerrit@... wrote:
> It has been seen on some stm32 targets that the flash size register that
> is probed by the driver may contain an invalid size.

Not only that, I've been told at ##stm32 that all of the STM32F103C8T6
(e.g. as found on ST-Links) have 128K flash instead of 64K. So it's
technically valid but limited for marketing reasons at least on some
chips, here's when this change will come useful too :)

Error when trying to flash a firmware file over 64kbytes -- OpenOCD flash up to the limit of 64Kbytes:

image.png

After changing this line on the STM32Fxx OpenOCD script file: flash bank $_FLASHNAME stm32f1x 0x0800000 0 0 0 $_TARGETNAME
to: flash bank $_FLASHNAME stm32f1x 0 0x20000 0 0 $_TARGETNAME
Now flashing the same firmware file over 64kbytes!!! And it works :-)
image.png

RESUME: The Electric Unicycles and Hoverboards boards that use the STM32F103C8T6 microcontroller, should be able to run/store a firmware file of 128kbytes instead of the official 64kbytes.

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

8 hours ago, changfrancis said:

I got the parts but a yet to link up the system to program. Can u make a video on the setup and tutorial to setup the IDE ?

Sorry, I do not have time to make such video and there are many tutorials online on how to setup the Eclipse IDE for the ARM. I am keeping updated some quick notes with screenshots of my setup here, which I recommend for you to read:

For compiling, you can find many information on google for using Eclipse IDE and flash and debug using OpenOCD. I shared my very resumed notes using a CherryTree notes file:

Screenshot_from_2017-03-31_10-44-33.png

The notes files is on documentation repo: https://github.com/EGG-electric-unicycle/documentation/blob/8b71785d09e58bff6f927c09a71377e5c2ba3229/EGG_Electric_Unicycle-firmware.ctb

Link to comment
Share on other sites

I am being testing the balance controller, and I started to try use current control for the motor and found a lot of instability... now I don't think current control is used to control the motor torque, due to a lot of noise on the current measurements and high gain on the electronic circuit. I am now thinking that the control is done simple with PWM duty_cycle.

My current balance controller, that have as input the vertical angle error (-20; 20 degrees limit) and as output the duty_cycle value for the PWM duty_cycle controller:

// called at each 10ms
void balance_controller(void)
{
  float angle_error;
  static float duty_cycle_f = 0;

  angle_error = IMU_get_angle_error ();

  duty_cycle_f = qfp_fadd(duty_cycle_f, qfp_fmul(K_BALANCE_CONTROLLER, angle_error));

  // limit value
  if (duty_cycle_f > 1000) { duty_cycle_f = 1000; }
  if (duty_cycle_f < -999) { duty_cycle_f = -999; }
 
  set_pwm_duty_cycle ((int) duty_cycle_f);
}

This balance controller works as my experience with my MicroWorks unicycle: I need to lean forward for the motor increase speed. If I lean an higher value, the motor increases at a faster rate the speed. If I keep the lean over time, the motor keeps incrementing the speed.
To maintain the speed, I just need to keep in vertical, without any lean. To decrease the speed, I need to lean in the inverse direction.

The math is this:   duty_cycle = duty_cycle + K_BALANCE_CONTROLLER * angle_error (this math should be done every 10 milliseconds)
K_BALANCE_CONTROLLER should define the rate at which the motor sped increases.

Edited by electric_vehicle_lover
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...