Problem to execute SimpleFOC code on SparkFun RedBoard Artemis ATP?

Hello. We use the SparkFun RedBoard Artemis ATP microcontroller board to control two gimbal SparkFun 12V 3-Phase BLDC motors with encoders AS5048A via two SparkFun 11V Brushless TMC6300 motor-drivers. A short SimpleFOC code (please see below) was uploaded to check whether or not each motor works. Notice that motor.controller = MotionControlType::velocity_openloop used in the code does not require any sensors (encoders). The motors did not move at all. Then, we used an oscilloscope.

The oscilloscope showed just noise when we consequently connected its terminal to the microcontroller board pin ~18, ~37, ~44, please see photo attached. It was evident that the short SimpleFOC code was not supported by the microcontroller board. Next we connected the oscilloscope terminal to pin ~19 and uploaded a short code with digitalWrite(PIN, HIGH) with delay(3000) without any SimpleFOC code. The oscilloscope showed a good square curve.

Thirdly, we used the short SimpleFOC code for the motor #1. We connected pin ~19 to the oscilloscope terminal. The oscilloscope showed just noise again. It is evident that the SparkFun RedBoard Artemis ATP board does not work with the SimpleFOC code for some reason. Could somebody please clarify what is wrong? Is the short SimpleFOC code below wrong? Here is the short SimpleFOC code:

/*
The following code was built based on the example SimpleFOC control
code published on this webpage Position Control example | Arduino-FOC by editing the example SimpleFOC control code.
*/

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #2 having 11 coil pairs
BLDCMotor motor2 = BLDCMotor(11);

// Initialize 6PWM motor-driver
const int VIO_PIN2 = D1;
BLDCDriver6PWM driver2 = BLDCDriver6PWM(D37, D18, D45, D44, D42, D43, VIO_PIN2);

float target_velocity = 12.0; // radians per second

void setup() {
driver2.voltage_power_supply = 7.4;
driver2.init();
motor2.linkDriver(&driver2);

motor2.voltage_limit = 7.4;
motor2.controller = MotionControlType::velocity_openloop;

motor2.init();
}

void loop() {
motor2.loopFOC();
motor2.move(target_velocity);
}

Thank you.

Hi Boris (@B ),

You have been struggling with this for a long time. I hope the following helps:

You are using the Artemis ATP because it has many PWM-capable GPIO pins. That is OK except the SimpleFOC library does not have dedicated support for the Artemis / Apollo3 processor. So, it defaults to using the “Generic MCU”.

The code it uses is held in a file called “generic_mcu.cpp”. If you are using Windows, you can find that file in:

“C:\Users\YOUR_USERNAME\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\generic_mcu.cpp”

If you look at the code for _configure6PWM you will find that it is not implemented. Everything is _UNUSED. Likewise for _writeDutyCycle6PWM. The developers of SimpleFOC have never added generic support for 6-PWM. Here are links to the original source code on GitHub: _configure6PWM, _writeDutyCycle6PWM

I was able to make your code run by doing the following:

Edit _configure6PWM in generic_mcu.cpp. Replace it with:

// Configuring PWM frequency, resolution and alignment
// - BLDC driver - 6PWM setting
// - hardware specific
__attribute__((weak)) void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const int pinA_l,  const int pinB_h, const int pinB_l, const int pinC_h, const int pinC_l){
  // _UNUSED(pwm_frequency);
  // _UNUSED(dead_zone);
  // _UNUSED(pinA_h);
  // _UNUSED(pinA_l);
  // _UNUSED(pinB_h);
  // _UNUSED(pinB_l);
  // _UNUSED(pinC_h);
  // _UNUSED(pinC_l);

  // return SIMPLEFOC_DRIVER_INIT_FAILED;
  
  // Code taken from atmega32u4_mcu.cpp
  GenericDriverParams* params = new GenericDriverParams {
    .pins = { pinA_h, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
    .pwm_frequency = pwm_frequency,
    .dead_zone = dead_zone
  };
  return params;
}

For _writeDutyCycle6PWM, you need to change it and add the code for _setPwmPair. Replace _writeDutyCycle6PWM with:

// function setting the PWM pin pair - taken from atmega32u4_mcu.cpp
void _setPwmPair(int pinH, int pinL, float val, int dead_time)
{
  int pwm_h = _constrain(val-dead_time/2,0,255);
  int pwm_l = _constrain(val+dead_time/2,0,255);
  
  analogWrite(pinH, pwm_h);
  if(pwm_l == 255 || pwm_l == 0)
    digitalWrite(pinL, pwm_l ? LOW : HIGH);
  else
    analogWrite(pinL, pwm_l);
}

// Function setting the duty cycle to the pwm pin (ex. analogWrite())
// - BLDC driver - 6PWM setting
// - hardware specific
__attribute__((weak)) void _writeDutyCycle6PWM(float dc_a,  float dc_b, float dc_c, PhaseState *phase_state, void* params){
  // _UNUSED(dc_a);
  // _UNUSED(dc_b);
  // _UNUSED(dc_c);
  // _UNUSED(phase_state);
  // _UNUSED(params);

  // Code taken from atmega32u4_mcu.cpp
  _setPwmPair(((GenericDriverParams*)params)->pins[0], ((GenericDriverParams*)params)->pins[1], dc_a*255.0, ((GenericDriverParams*)params)->dead_zone*255.0);
  _setPwmPair(((GenericDriverParams*)params)->pins[2], ((GenericDriverParams*)params)->pins[3], dc_b*255.0, ((GenericDriverParams*)params)->dead_zone*255.0);
  _setPwmPair(((GenericDriverParams*)params)->pins[4], ((GenericDriverParams*)params)->pins[5], dc_c*255.0, ((GenericDriverParams*)params)->dead_zone*255.0);

  _UNUSED(phase_state);
}

With these modifications, I see PWM output on the pins. Here is what I see on D42, D43, D45 and D18:

Best wishes,
Paul

Thank you so much, PualZC. That stuff is not easy for me yet. It takes me some time to come up with those adjustments and a final code.

Now I have the following questions about choosing the SparkFun RedBoard Artemis ATP pins to connect to the SparkFun TMC6300 motor-driver PWM pins. This SparkFun example code Example - Basic - Hookup Guide - TMC6300 BLDC Motor Driver defines the RedBoard Plus microcontroller board pins: 5, 6, 9, 10, 3, 11. As far as I understand, these pins must be bound to the same internal timer counter to make the motor work correctly. Could someone please specify what six pins of the RedBoard Artemis ATP must be chosen to be connected to the motor-driver PWM pins? By the way, we need additional six pins which are bounded to another internal timer counter. Thank you.

Hi Boris (@B ),

The Artemis uses the Apollo3 Blue MCU from Ambiq Micro. It has 8 Counter / Timer modules, each of which is actually two 16-bit counter timers. The way the counter timers are connected to pins is complex and is performed by an interconnection matrix. The way analogWrite (ap3_pwm_output) is implemented in the SparkFun core only uses the first (0th) choice for which part of which counter / timer is connected to the pin. To understand this fully, you would need to understand both the Apollo3 Blue Datasheet and the way analogWrite (ap3_pwm_output) is implemented in the SparkFun core (CommonAnalog.cpp). In the datasheet, you would need to understand chapter 13 “Counter/Timer Module (CTIMER)”.

If you want to continue with the Artemis ATP, you certainly can. It is a very capable board, capable of generating complex PWM waveforms on multiple pins. But, for your dual-motor application, you may need to make changes to the software core itself so you can better configure the PWM output. It may be easier if you choose another board which already has dedicated counter / timer support in the SimpleFOC firmware and which has already been used in similar dual-motor applications.

Best wishes,
Paul

Dear PaulZC, I made all the changes you recommended to do with generic_mcu.cpp . After that I uploaded the code to move the motors (please see below). Now I got the motor-driver blue LED on as well as the red LED on (before the red LED (power) was on only). The blue LED indicates that the motor-driver is enabled Hardware Overview - Hookup Guide - TMC6300 BLDC Motor Driver . However, the motors did not move at all.

Today we checked the three PWM wires from the motor-driver to the motor with the oscilloscope. The oscilloscope showed the same square curve for each wire (about 7.4V), please see the photo attached. We also checked the six wires from the microcontroller board to the motor-driver with the oscilloscope. It showed a flat curve (zero volt). Could somebody please advice what to do to make the motors move? Here is the short SimpleFOC code I used today:

/*
The following code was built based on the example SparkFun control
code published on this webpage Example - Basic - Hookup Guide - TMC6300 BLDC Motor Driver
by editing the example SparFun control code.
*/

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 and Motor #2 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);
BLDCMotor motor2 = BLDCMotor(11);

// Initialize two 6PWM motor-drivers
const int VIO_PIN1 = D17;
const int VIO_PIN2 = D1;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);
BLDCDriver6PWM driver2 = BLDCDriver6PWM(D37, D18, D45, D44, D42, D43, VIO_PIN2);

float target_velocity = 50.0; // radian per second

// // instantiate the commander
Commander command = Commander(Serial);
// void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
// void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }

void setup() {

// driver config
// power supply voltage [V]
driver1.voltage_power_supply = 7.4;
driver2.voltage_power_supply = 7.4;

// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver1.voltage_limit = 7.4;
driver2.voltage_limit = 7.4;

// pwm frequency to be used [Hz]
// for atmega328 fixed to 32kHz
// esp32/stm32/teensy configurable
driver1.pwm_frequency = 32000; // tests were made with commented and uncommented
driver2.pwm_frequency = 32000;

driver1.init();
driver2.init();

// link the motor and the driver
motor1.linkDriver(&driver1);
motor2.linkDriver(&driver2);

// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor1.voltage_limit = 7.4;
motor2.voltage_limit = 7.4;

// open loop control without encoders
motor1.controller = MotionControlType::velocity_openloop;
motor2.controller = MotionControlType::velocity_openloop;

// initialize motor hardware
motor1.init();
motor2.init();

// add target command T
// command.add(‘T’, doTarget, “target velocity”);
// command.add(‘L’, doLimit, “voltage limit”);

Serial.begin(115200);
Serial.println(“Motors ready!”);
Serial.println(“Set target velocity in radians per second”);
delay(1000);
}

void loop() {

// motor1.loopFOC(); // tests were conducted with commented and uncommented loopFOC()

// motor2.loopFOC()
motor1.move(target_velocity);
motor2.move(target_velocity);

// user communication
command.run();

}

By the way, the motors did not work with commented driver1.pwm_frequency and driver2.pwm_frequency as well as with uncommented. The same was about motor1.loopFOC() and motor2.loopFOC().

Thank you.

Hello PaulZC. Today we checked the new RedBoard Artemis ATP microcontroller board, please see the photo attached. The same simple code was used (please see the post above). We observed the square curve when the oscilloscope screen was zoomed in enough. The signal curve (about 3.8V) was only for pins D19, D23 (motor #1) and for pins D18, D43 (motor #2). I used various speeds by changing target_velocity; however, the curve stayed the same (amplitude and width). The board was not connected to the motor-drivers.

There is the following error message in the Serial Monitor:

"++ MbedOS Error Info ++

Error Status: 0x80FF0144 Code: 324 Module: 255

Error Message: Assertion failed: status == osOK

Location: 0x23190

File: mbed-cs/rtos/source/ThisThread.cpp+255

Error Value: 0x0

Current Thread: main Id: 0x10004518 Entry: 0x24185 StackSize: 0x1000

StackMem: 0x10006188 SP: 0x10007114

For more info, visit: Arm Mbed · GitHub

-- MbedOS Error Infor –

Could you please provide any advice what might be wrong? Thank you.

Hello PaulZC. I finally made the two motors work with the code below. However, they move chaotically. I cannot understand why. It seems that the pins in BLDCDriver6PWM are allocated correctly: BLDCDriver6PWM(U_H, U_L, V_H, V_L, W_H, W_L, VIO_PIN). Could you please recommend how to change the code to make the motors work properly? Here is the code:

/*
The following code was built based on the example SimpleFOC control
code published on this webpage Position Control example | Arduino-FOC by editing the example SimpleFOC control code.
*/

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 and Motor #2 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);
BLDCMotor motor2 = BLDCMotor(11);

// Initialize two 6PWM motor-drivers
const int VIO_PIN1 = D17;
const int VIO_PIN2 = D1;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);
BLDCDriver6PWM driver2 = BLDCDriver6PWM(D45, D44, D37, D18, D42, D43, VIO_PIN2);

float target_velocity = 4.0; // radian per second

void setup() {
driver1.voltage_power_supply = 7.4;
driver2.voltage_power_supply = 7.4;

driver1.init();
driver2.init();

motor1.linkDriver(&driver1);
motor2.linkDriver(&driver2);

motor1.voltage_limit = 7.4;
motor2.voltage_limit = 7.4;

motor1.controller = MotionControlType::velocity_openloop;
motor2.controller = MotionControlType::velocity_openloop;

motor1.init();
motor2.init();

}

void loop() {
motor1.loopFOC();
motor2.loopFOC();

motor1.move(target_velocity);
motor2.move(target_velocity);
}

Thank you.

Hi Boris (@B ),

Are you still using the Three Phase Brushless Gimbal Stabilizer Motor? The datasheet says it has 8 poles, not 11. Could that be the problem?

Best wishes,
Paul

Hi PaulZC. I use these SparkFun gimbal motors with encoders AS5048A Gimbal Motor with Encoder - 12V, 467RPM - SparkFun Electronics . The motor has 11 pole pairs based on its specification.

Hello PaulZC. Today I changed the function BLDCMotor(11) for BLDCMotor(8) in according to your last post. It did not work. The motors moved chaotically again. I also used values such as 6, 7, 9, 10, 12, and 13. None of them helped. The motors moved chaotically. Could you please help to make the motors work properly? Thank you.

Hi PaulZC. I seem that I should have added motor1.initFOC() and motor2.initFOC() at the end of the setup() section of the code. That might be the reason why motors move chaotically. I will change the code and test the motors.

Hi Boris (@B ),

Can you please share your full wiring diagram? Please show all the connections between the ATP, the motor drivers, the motors, the power supply / batteries. If you do not have a diagram, please describe each and every wire, saying which two pins it connects. Please ensure you include all the Ground / 0V connections.

Thank you,
Paul

Hello PaulZC. Yes, I made the circuit diagram, please see the attachment

TLPE2_Simple_Diagram1.pdf (153.1 KB)

. Another person helped me to wire the parts. The diagram with the circuit KiCAD schematic will be published after final tests are conducted.

Today I checked all the connections. I found out that some PWM wires of the motor-driver #2 (motor #2) were connected incorrectly. However, all the PWM wires of the motor-driver #1 (motor #1) were connected correctly. Then, I uploaded the same short code with motor1.initFOC() and motor2.initFOC() at the end of the setup() section, please see my code below. The motors move chaotically again. I do not understand what is wrong with my code? Here is the code:

/*
The following code was built based on the example SimpleFOC control
code published on this webpage Position Control example | Arduino-FOC by editing the example SimpleFOC control code.
*/

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 and Motor #2 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);
BLDCMotor motor2 = BLDCMotor(11);

// Initialize two 6PWM motor-drivers
const int VIO_PIN1 = D17;
const int VIO_PIN2 = D1;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);
BLDCDriver6PWM driver2 = BLDCDriver6PWM(D45, D44, D37, D18, D42, D43, VIO_PIN2);

float target_velocity = 4.0; // radian per second

void setup() {
driver1.voltage_power_supply = 7.4;
driver2.voltage_power_supply = 7.4;

driver1.init();
driver2.init();

motor1.linkDriver(&driver1);
motor2.linkDriver(&driver2);

motor1.voltage_limit = 7.4;
motor2.voltage_limit = 7.4;

motor1.controller = MotionControlType::velocity_openloop;
motor2.controller = MotionControlType::velocity_openloop;

motor1.init();
motor2.init();

motor1.initFOC();

motor2.initFOC();

}

void loop() {
motor1.loopFOC();
motor2.loopFOC();

motor1.move(target_velocity);
motor2.move(target_velocity);
}

Thank you.

Hi Boris (@B ),

Thank you for the wiring diagram.

I have tried to replicate your motor1 test using the same Artemis ATP pins. I found there was a mistake in the _setPwmPair code I posted above. It was not generating complementary outputs on each pin pair.

In generic_mcu.cpp, please change _setPwmPair to:

// function setting the PWM pin pair - adapted from atmega32u4_mcu.cpp
void _setPwmPair(int pinH, int pinL, float val, int dead_time)
{
  int pwm_h = _constrain(val-dead_time/2,0,255);
  int pwm_l = 255 - _constrain(val+dead_time/2,0,255);
  
  analogWrite(pinH, pwm_h);
  analogWrite(pinL, pwm_l);
}

Then please test the following example:

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);

// Initialize 6PWM motor-driver
const int VIO_PIN1 = D17;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);

float target_velocity = 6.28; // radian per second
const unsigned long ramp_time = 5000; // ramp time in ms to target velocity

void setup() {
Serial.begin(115200);
while (!Serial)
  delay(1);
Serial.println("SimpleFOC Example");

SimpleFOCDebug::enable(&Serial);

driver1.voltage_power_supply = 7.4;
driver1.voltage_limit = 7.4;

if (driver1.init())
  Serial.println("Driver initialized");

motor1.linkDriver(&driver1);

motor1.voltage_limit = 2.0; // Increase this if needed

motor1.controller = MotionControlType::velocity_openloop;

motor1.torque_controller = TorqueControlType::voltage; // Default. See: https://docs.simplefoc.com/torque_control

if (motor1.init())
  Serial.println("Motor initialized");

//motor1.useMonitoring(Serial);

motor1.initFOC();
}

void loop() {
  
motor1.loopFOC();

// Ramp the velocity from zero to target_velocity over ramp_time ms
static unsigned long start_time = millis();
float ramp_fraction = (float)(millis() - start_time) / (float)ramp_time;
float velocity = (ramp_fraction > 1.0 ? 1.0 : ramp_fraction) * target_velocity;
motor1.move(velocity);

//motor1.monitor();
}

I hope this helps,
Paul

Thank you, PaulZC. I did all the changes you provided in the last post. Unfortunately, the motor #1 does not work properly again. Is something wrong with your code?

Is the blue LED on the motor driver illuminated? Does the motor move at all?

Paul, yes. The blue LED illuminates. The motor moves chaotically again. Did you test your code with the same SparkFun motor, the motor-driver board, and the microcontroller board? Thank you.

The motor moves chaotically again

Are you sure you changed and saved generic_mcu.cpp correctly? The motor was moving erratically for me too until I made those changes.

Did you test your code with the same SparkFun motor, the motor-driver board, and the microcontroller board?

Yes

I have double-checked the changes in generic_mcu.cpp on my laptop. All the changes are done in according to your instructions. I do not have any clue what might be wrong?

P.S. I accidentally broke the microcontroller board microphone while I screwed the bolt to fix the board to the clear plate. However, I do not think that the broken microphone can affect the motors motion in any way.

I asked Claude to take a look at the SimpleFOC library, to see if the 6-PWM could be implemented correctly on the Artemis (Apollo3). Here is the result:

IMG_3428_edited

Here is the the report produced by Claude:

SimpleFOC_Artemis_ATP_Session_2026-10-29.pdf (287.8 KB)

You can find the apollo3_mcu.cpp file it wrote at:

Place it in your Arduino-FOC library in: src/drivers/hardware_specific/apollo3_mcu.cpp

You can restore generic_mcu.cpp back to the original version. All the new Apollo3 (Artemis) code is held in apollo3_mcu.cpp.

Here is the revised single motor example:

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);

// Initialize 6PWM motor-driver
const int VIO_PIN1 = D17;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);

float target_velocity = 31.4; // radian per second
const unsigned long ramp_time = 5000; // ramp time in ms to target velocity

void setup() {
Serial.begin(115200);
while (!Serial)
  delay(1);
Serial.println("SimpleFOC Example");

SimpleFOCDebug::enable(&Serial);

driver1.voltage_power_supply = 7.4;
driver1.voltage_limit = 7.4;

if (driver1.init())
  Serial.println("Driver initialized");

motor1.linkDriver(&driver1);

motor1.voltage_limit = 4.0; // Increase this if needed

motor1.controller = MotionControlType::velocity_openloop;

motor1.torque_controller = TorqueControlType::voltage;

if (motor1.init())
  Serial.println("Motor initialized");

//motor1.useMonitoring(Serial);

motor1.initFOC();
}

void loop() {
  
motor1.loopFOC();

// Ramp the velocity from zero to target_velocity over ramp_time ms
static unsigned long start_time = millis();
float ramp_fraction = (float)(millis() - start_time) / (float)ramp_time;
float velocity = (ramp_fraction > 1.0 ? 1.0 : ramp_fraction) * target_velocity;
motor1.move(velocity);

//motor1.monitor();
}

Here is the revised dual-motor example:

#include <SimpleFOC.h>
#include <Arduino.h>

// Setting Motor #1 and Motor #2 having 11 pole pairs
BLDCMotor motor1 = BLDCMotor(11);
BLDCMotor motor2 = BLDCMotor(11);

// Initialize two 6PWM motor-drivers
const int VIO_PIN1 = D17;
const int VIO_PIN2 = D1;
BLDCDriver6PWM driver1 = BLDCDriver6PWM(D26, D19, D22, D4, D27, D23, VIO_PIN1);
BLDCDriver6PWM driver2 = BLDCDriver6PWM(D45, D44, D37, D18, D42, D43, VIO_PIN2);

float target_velocity = 31.4; // radian per second
const unsigned long ramp_time = 5000; // ramp time in ms to target velocity

void setup() {
  Serial.begin(115200);
  while (!Serial)
    delay(1);
  Serial.println("SimpleFOC Example");

  SimpleFOCDebug::enable(&Serial);

  driver1.voltage_power_supply = 7.4;
  driver1.voltage_limit = 7.4;

  if (driver1.init())
    Serial.println("Driver 1 initialized");

  motor1.linkDriver(&driver1);
  motor1.voltage_limit = 4.0; // Increase this if needed
  motor1.controller = MotionControlType::velocity_openloop;
  motor1.torque_controller = TorqueControlType::voltage; // Default. See: https://docs.simplefoc.com/torque_control

  if (motor1.init())
    Serial.println("Motor 1 initialized");

  //motor1.useMonitoring(Serial);

  motor1.initFOC();

  driver2.voltage_power_supply = 7.4;
  driver2.voltage_limit = 7.4;

  if (driver2.init())
    Serial.println("Driver 2 initialized");

  motor2.linkDriver(&driver2);
  motor2.voltage_limit = 4.0; // Increase this if needed
  motor2.controller = MotionControlType::velocity_openloop;
  motor2.torque_controller = TorqueControlType::voltage; // Default. See: https://docs.simplefoc.com/torque_control

  if (motor2.init())
    Serial.println("Motor 2 initialized");

  //motor2.useMonitoring(Serial);

  motor2.initFOC();
}

void loop() {
  
motor1.loopFOC();
motor2.loopFOC();

// Ramp the velocity from zero to target_velocity over ramp_time ms
static unsigned long start_time = millis();
float ramp_fraction = (float)(millis() - start_time) / (float)ramp_time;
float velocity = (ramp_fraction > 1.0 ? 1.0 : ramp_fraction) * target_velocity;
motor1.move(velocity);
motor2.move(velocity);

//motor1.monitor();
//motor2.monitor();
}

I hope this helps,
Paul