Porting to my hardware

I have an STM32F072 board and just designed a simplefocmini compatible board.

So I’m trying to get this combination to work. First got the sensor (AS5600) working. So now on the the real FOC.

So I had first made a mistake to use PA7-8-9 instead of PA8-9-10. Oops. Then tried it with the hardware still wired up for PA7-8-9 and got bad signals on PA7. That took much too long before I realized I had fixed the software to use 8-9-10. So then I hooked up that part correctly verified good PWM signals on all three wires going to the driver board. Then I plugged the three signals into driver board and… the motor started spinning! Great!

Then I restarted the “angle control” example, and… nothing! Still “no movement detected” at startup. :frowning: . No power draw at all either.

PS: Oh. Just checking: Can I use any pin for “EN” ? I used PB9 (I was aiming for PA0, but missed).

PPS: Another thing! On simplefocmini: Is the series-resistor of 10k on EN intended or was that meant as a pulldown?

I measured the loop speed at between 800 and 900 Hz. i.e. way too slow. So moving up from 'F072, should I chose 'F411 or 'G431 ?

(I have the aliexpress arduino-nano-lookalikes with the F411, and I have an unproven PCB for the G431 and some bare chips).

The DRV8313 already has pulldowns (100k) integrated on all digital pins, so there is no need to add an additional pull-down to the ground.

The 10k series resistor serves the same purpose as the pull down basically. If any digital pin is connected to the EN and if it is floating, it will not be able to provide enough current to pass through the 10k resistor. And effectively it will be pulled to the ground. If the EN pin is in HIGH (3.3 or 5) it will have it will easily push 0.5 mA through the resistor.

So yeah, they are not really necessary, especially since the pulldowns are already integrated in the chip

Update:
I got openloop speed to work.

Then when going back to the angle control example, I noticed that it was different after a power supply cycle. I think the drv chip may have been asserting fault and then refusing to do anything.

So now I’ve hooked up nRESET, nSLP and nFLT , now I get the calibration cycle to run. This required setting the voltage for the angle calibration to 1V. That now seems to work.

Then the motor becomes really acitve, (i.e. vibrating) when the angle-control becomes active. Then when I modify the PID parameters of the angle-pid, it seems I can get the calibration to fail. I don’t understand why that would be the case. I now have: motor.P_angle.P = 2; which is 10x lower than the example suggests, but still unstable.

supply = 12V,
limit = 1V. (now).
Any suggestions on what to tune next?

OK, update: I managed to get the velocity PID tuned and now also the angle control works.

Hey @rew,

Yeah you can use any pin really. You can even use a 3.3V/5V pin as a matter of fact, this might be more or less elegant of a solution depending of your application.:slight_smile:

Yes it’s a pulldown, to avoid floating EN pin.

Ehh. Then better check the schematic in the git repository: it definitively isn’t a pulldown. Maybe the Altium file was updated but the schematic not re-printed… I can’t open Altium files, so I can’t check.

PS: I remembered that I have an altium-365 account. But the file doesn’t load.

5V/ 10k = 0.5mA. So 3.3V is definitely not enough for 0.5mA and 5V is marginal. (i.e. works if the 5V line happens to be 5.1V and might not work when it happens to be 4.7).

That said… On many processors, pins have a default pullup or pulldown that activates under reset. That pullup or pulldown is on the order of 50k. That will quite possibly overrule the about 100k pulldown in the chip (*). Now the RP2040 has almost exclusively pulldown resistors and the EN on the DRV8313 is active-high, so in that case things would all be fine. I’ve looked it up for STM32F4 and there the vast majority of the pins are configured floating at reset.

So I agree that it will usually work as is, but it is quite evident that a pulldown was intended. I just realized “any pin is acceptable”. PA15 is pullup by default. As I don’t use JTAG, it is labeled available as “GPIO” on my schematics. I agree that it would be a bad choice due to the default pullup, but that’s what a 10k pulldown would solve.

Why would you want a series resistor in the EN line?

(*) On the simplefocmini there are 3 in parallel, 33k… That’s going to be close if it activates or not…

So on the Cortex M0 of the F072 you should be able to achieve a bit more speed, maybe 2-3kHz loop speed should be possible. What’s holding you back is the I2C sensor, I2C is very slow.
We have a dedicated driver for the AS5600 which can run it in a faster mode, you could try this and should see a bit more performance.

But really it’s the lack of FPU that makes the F072 slow running simpleFOC - a Cortex M0+ with FPU or a Cortex M4 will have considerably better performance.

So with a STM32G4 MCU, SPI or ABZ based sensor and using the CORDIC for sin/cos calculations you can expect >10kHz loop speed.

Good! I have the G431 board up-and-running. Seems to work. :slight_smile:
Now I just have to plug the driver board into the G431 board.

I’m really afraid for “regressions”. So that means building a new driver board and copying the wiring.

Let us know how it goes :slight_smile:

Will do. Other stuff needs to be done “now” so later this week.

Besides AS5048A are there other SPI chips available? (Preferably with cheap aliexpress breakouts?)

Chatgpt came up with MA730, but LCSC doesn’t have the chip and I don’t see breakouts on Aliexpress.

It also suggested TMAG5170, but again no breakouts on aliexpress. This time the chips are available at LCSC. Scanning the datasheet makes me think that it isn’t intended to be used for motor control so might be slow even if the SPI is fast.

Edit: MT8616 ?

The various AMS, MagnaTek and MPS sensors all tend to work well.

You mean MagnTek, right? :slight_smile: There are several companies named magnatek, but none of them make magnetic encoders… (Turbo decoder and Dent tool company have a product with that name, Magnatek APS: Xray tubes. magna-tek makes water softener systems, Magnatek1 makes ATA/IDE harddrives and there is a household appliance company with that name on linkedin…)

I’ve got MT6701 and MT6816 breakouts on the way.