Ok I still didn’t get the motor running.
But I did find something interesting with the config behaviour.
DRV8316Driver6PWM driver = DRV8316Driver6PWM(PHA_H, PHA_L, PHB_H, PHB_L, PHC_H, PHC_L, DRV_CS, true);
I assumed this would setPWMMode to PWM6_CurrentLimit_Mode. Setting current limit to true does not affect PWMMode.
driver.setPWMMode(PWM6_CurrentLimit_Mode);
But it does change when I set call this function in setup. The weird thing is, this even works when I use the DRV8316Driver3PWM CLASS.
That said, I’m not sure why the motor doesn’t move. I tried changing these
This is probably a kind of bug. We should probably align these different modes and setter functions so the resulting settings always make sense.
But as long as you can configure the mode you need (even if you need multiple calls that don’t seem logical) this isn’t a problem per se, just a useability issue.
When you set the 3-PWM vs. the 6-PWM mode, does it reflect in the status you print via printDRV8316Status()? I.e. have you seen any output that isn’t all-zero?
However I don’t measure any voltage on that pin. So not sure whats the issue
But you’re right, the mosfets don’t seem to be enabled.
I will check with another board and confirm.
Edit:
I was measuring the voltage between the phases, between phase and ground. So the voltage was 0.
There is full voltage when I measure between a phase and Vin. So the low side mosfets are infact enabled. That’s relief, DRVOFF is infact internal pulldown.
To confim this, I soldered a wire to the DRVOFF. When I connected it to 5V, voltage between phase and Vin dropped. Indicating that the mosfets are disabled by DRVOFF.
I also checked the pwm outputs from the MCU. It is working well, So that means only the driver is the issue. I will see if there is any other way to debug this stuff.
I can confirm the driver mosfets are working but not with simplefoc.
Brute forced a commutation with analogwrite. Since all the Low side mosfet were enabled, I simply toggle pha_h, pha_b, pha_c one by one.
#include "Arduino.h"
#include <Wire.h>
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "drivers/drv8316/drv8316.h"
SPIClass SPI_1(SPI_MOSI, SPI_MISO, SPI_SCK);
BLDCMotor motor = BLDCMotor(11);
DRV8316Driver6PWM driver = DRV8316Driver6PWM(PHA_H, PHA_L, PHB_H, PHB_L, PHC_H, PHC_L, DRV_CS, true);
// velocity set point variable
float target_velocity = 20.0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
Serial.begin(250000);
Serial.println("Initializing...");
driver.voltage_power_supply = 12.0;
driver.voltage_limit = 12.0;
driver.init(&SPI_1);
driver.setSlew(Slew_25Vus);
driver.setPWM100Frequency(FREQ_40KHz);
driver.setBuckVoltage(VB_5V);
driver.setOCPRetryTime(Retry5ms);
//driver.enable();
Serial.println("Init complete...");
delay(100);
printDRV8316Status();
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Done");
}
void loop() {
for (int i = 0; i < 6; i++) {
int pins[3] = { PHA_H, PHB_H, PHC_H };
for (int j = 0; j < 3; j++) {
if (i == j) {
for (int k = 0; k <= 40; k++) {
analogWrite(pins[j], k);
delay(10);
}
} else {
analogWrite(pins[j], 0);
}
}
}
}
Good news is the PCB is working well, no hardware errors found so far. I will look into the simplefoc code and check if anything is missed.
So far I have tested and confirmed these:
MT6701 is working
Driver SPI communication is good
Driver Mosfets are working
So the only thing left to check is the simplefoc code. On the hardware side I still have to check the CAN transceiver.
PS: The lights you’re seeing in the video visualizes BLDC commutation. It is made with 6 leds in delta configuration along with diodes and resistors for protection.
But you already mentioned that you could see the PWM output on the MCU? So that means SimpleFOC is working if that’s the case?
To me that would indicate there is still some kind of setup/initialization/enable problem that means SimpleFOC is producing output but the driver isn’t passing it on to the phases?
Use diodes rated for your voltage. I use a maximum 12V, so this works fine.
Use a different colour for odd leds ( LED1, LED3, LED5 ) and even leds ( LED2, LED4, LED6 ).
The working principle is very simple:
The diodes make sure the odd and even light up according to the current direction. For low voltages (below 5V) you can get away without diodes since LED are also diodes.
This setup is connected to a 3 phase driver output. It allows us to visualize the active phase and current direction.
I am using the generic G431 config without cordic and fdcan enabled. I assume it is using the internal clock now. So I will create a board def next
The past few days have been rough with this thing, Only last night I suspected that there might be some issue with platformio core since it is usually a bit outdated than the arduino cores.
Anyway It is finally working!
Look at that mesmerizing pwm.
My bad friend, I was getting pwm from the MCU but all pins were giving the same voltage. That’s how suspected it might actually have to do something with the platformio core. Now with this Arduino core I can confirm that the pwm is actually changing voltage according to commutation.
But I’m not sure its really an issue with platformIO - I use it all the time for my development on SimpleFOC, and the G431 is one of the more used chips I test with.
So its definitely possible to get it working with platformIO and a “generic” G431 board.
If you’re happy to use ArduinoIDE we can drop this topic, but if you’d like to make PlatformIO work we can compare versions and try to find the issue for you…
.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/system/STM32G4xx/system_stm32g4xx.c: In function 'SystemInit':
<command-line>: error: expected expression before '{' token
.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/system/STM32G4xx/system_stm32g4xx.c:199:39: note: in expansion of macro 'VECT_TAB_OFFSET'
199 | SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
I can’t get the arduino_simplefoc_boards working. This error shows with both boards, lepton and microspora.
The generic board defs compile well, but not the simplefoc defs @runger can you please give some advice, I’m totally lost here.
I’m currently testing a similar setup with the DRV8316EVM and an STM32G431 Nucleo. Have you been able to get the low-side current sense to work?
Closed-loop torque control using voltage works, and currently trying to monitor the d and q currents using step 4 from the getting started. But getting an nFAULT (not sure which one) on the EVM and serial monitor gets stuck at:
I also didn’t get the current sense to work, I got the error that current sense was not initialized, but not the timer error. I tried different gain settings in 8316.
Currently I am occupied with another project.
I will look into it again next week. I am determined to get this fully working.