Hbozyq's questions!

Hey guys.
Since STM32duino is really a fat ass and eatting all the flash(64k is not enough for i2c using), I am working on some transplant to keil project.
I copy some snippets from the souce code and try to make it work without arduino lib. The main purpose is cheaper design, high performance and less flash using. Though Im not a pro programmer and I will always need your help. So this is the thread where I leave my question and log my progress.

Again, thanks to everyone and this awesome project!

The very first question is about setPWM()
The dc_a/dc_b/dc_c here is the duty cycle in decimal from 0 to 1 right?
That way i just need to rewrite _writeDutyCycle3PWM(), multiply dc_x with ARR and get the CCRx.

Hi,

if the HardwareTimer class isn’t part of the KEIL toolchain, then you’ll have to rewrite the hardware driver for the STM32. That includes the _writeDutyCycle3PWM and configure3PWM parts.
Also you’ll have to look at the timer functions (_micros()) and the SPI / I2C code.
The algorithm itself should be fairly portable.

It would be cool to hear about it if you succeed!

Hey @hbozyq,

@ngalin has alread done a great job of porting the simplefoc to the keil toolchain. It is specific to her her boards but it is a great place to start. Here is the git repo:

_micros() wont be matter. Im going to call the loopFOC funciton at regular frequent.
That way something is easier.

image
So far I do made some progress. Now PWM, current sensor, position sensor are available. Once the loopFOC ,LPF and PID are done I am able to test something! The source code is really readable. Thats supreme helpful.

BTW whats this for?
I just leave it at 0.
image

You can use this to move the zero-position to a different location. This has no real effect on anything, it is just like adding an offset to the set-point.
It can be helpful in real-world setups, where you want zero to be in a certain place, and don’t always want to do offset calculations in other code (or your head).

Its almost done, but sth is still not working.So I wrote a function to verify the code.

image

In loopFOC() I set the voltage velocity to a specifed direction, e.g. PI.
When the rotor stabilized, the measured Q&D axis current is like this:
image
If I force the rotor spin 90 degree of electrical angle(at the middle of 2 “stop”), the current is like this:
image

Does this mean the Clark & Park transformation code is correct?
The motor’s pole pairs is 7.

Hey, I’m sorry, I don’t know the answer to that one…

If you just set a static voltage to the motor. When the motor stabilizes you’ll have a current in d direction not in q direction.
Q axis of current is responsible for generating torque and if you have any q current your motor will try to move to cancel it. Once when it stops you’ll have any the current in d direction which does not generate any torque, but a lot of heat :slight_smile:

So I’d say that you still have a problem in the code.
Are you sure that electrical zero angle is well aligned?