Hello, I’m trying to adapt SimpleFOC library to work on a NXP microcontroller.
When the FOC is trying to initialise, I’m trying to find the sensor direction as it is not defined . So it calls “int BLDCMotor::alignSensor()”
During this step when the PWM is computed using SVM "setPhaseVoltage(voltage_sensor_align, 0, angle); "
I get high current’s (Around 20A) on each phase (have shunt resistors on each phase & current amplifiers). I have a fault logic which would disable the PWM when it detects high currents. Any idea on what could cause this ?
You’re working on a new MCU architecture? That’s so cool! If you get a PWM driver working for it, we would be very interested to see the code… perhaps you would consider contributing it?
Yeah, that should be an upper bound. If you have set the voltage_limits, then the current should stay within that limit. With 1.5Ω phase resistance the current should also not be rising sooo fast that it overloads in-cycle.
Some advice on creating a new PWM driver:
start out without a motor. Just use a logic analyser on the PWM pins.
Don’t test it via BLDCMotor, just use the BLDCDriver3PWM and _setPWM(). Then you can set specific values to the phases (25%,50%,75%) and check the output on the logic analyser.
Once your PWM output is perfect as you want it, then start testing via BLDCMotor and with a real motor attached
Maybe you already did it this way, in which case please excuse my redundant advice.
Ok, I understand much better what is going on now.
Porting all of SimpleFOC to a new framework will be a bigger effort, I understand now why you “had to modify the FOC library heavily”.
One option might be to see if you can make Arduino Framework work for your board based on the Teensy support. If there is a close match between the MCU you’re using and the one on some teensy board version, then it is usually just a matter of adapting a few pin-definitions in the variant.h files.
Or you can of course continue in Xpresso, but be aware that people here won’t be able to help you as much, because SimpleFOC is really intended for use within Arduino framework… but please mention that fact when you post, otherwise people will be confused.
I have been looking into the teensy 4.0/4.1 form factor and it does have a nice deadtime insertion function but this is not possible on the T4.0. (See edit below, I was wrong) Since the right pins are not available, I think. It might be on the T4.1. In order to set up 6 pin pwm switching with deadtime insertion you need 6 pins on the same FlexPWM with complimentary pairs A & B pins.
FYI I just found out that the FlexIO controller can go insanely fast using a 480Mhz clock.
There is the option to do a custom design with the T4 MCU and get the bootloader IC from Paul, but the one have to do via in pad I believe, which makes it a custom-custom job. Do you know where to do affordable via-in-pad prototyping?
Can someone explain to me the advantages of using 6 pin pwm switching, besides from the obvious fact that many half-bridge drivers expect two inputs? In which scenario would you turn both mosfets off. During regen braking?
Edit: just discovered it is possible to use the T4.0 for 6 pin pwm switching. Apparently you can use pins on multiple FlexPWM’s as long as they are paired (A and B pin). Do I need a Mosfet Driver? - Page 2
6-PWM gives you full control, depending on the driver / hardware used. So you have control over the dead-time insertion, optimising for your MOSFETs. And you can tie events/interrupts to the PWM generation to sync current sensing or voltage sensing to the commutation.
Both FETs off puts the half-bridge into “Hi-Z mode”, and is used for example in 6-step commutation and back-EMF sensing, IIRC…
If I understand it correctly (se page 13) only the lower side mosfets are switched to create a boost circuit, using the energy in the coils, to boost above charging voltage, by PWM duty cycle [only on low side]. ?
The idea behind this, corect me if im wrong, is the ability to raise voltage, when the energy field in the coil collapses [When current can´t flow to gnd]. That “spike” in voltage will then run through the body-diode of the high-side mosfets and back to the battery.
Hence, in order to do this, we need to have all the high side FETs turned off during regen braking, and we need to control the low-side FETs independently. Naturally it will be of great importance to measure the actual voltage on the bus, in order to boost as efficiently as possible. The voltage spike will accumulate in the bulk capacitors before returning to source, completing the boost circuit.
As a safety precaution, we might want to have a large resistor (brake resistor) in place, if the generated current is greater then the battery is able to charge, as to not raise the temperature to much or otherwise damage the battery. Ideally it should not be necessary, but it can also be used to brake the motor in dynamic braking mode. BLDC MOTOR BRAKING TECHNIQUES (Part-1) (thesixtech.com)
Edit: Since the BLDC has a constant KV, we can implement a PID control loop dependent on the speed of the motor, to control the regen switching/boosting. That is, the voltage being generated by the motor when in generator mode, to low to charge the battery. Naturally all this requires the setup to be a direct drive setup eg. a bike that does not freewheel when the motor stops driving.