# Problem to execute SimpleFOC code on SparkFun RedBoard Artemis ATP?

**URL:** <https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735>\
**Category:** Robotics\
**Created:** [October 12, 2026, 10:19pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735 "2026-10-12T22:19:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 12, 2026, 10:19pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/1 "2026-10-12T22:19:15Z")

</div>

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](https://docs.simplefoc.com/position_control_example) 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.

 ![20261012_140736](https://canada1.discourse-cdn.com/sparkfun/original/2X/c/ca1cc397e9a194cbd6f2fece71c19a214dde51f1.jpeg)

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 13, 2026, 9:18am UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/2 "2026-10-13T09:18:00Z")

</div>

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](https://github.com/simplefoc/Arduino-FOC/blob/b3d8f3931342ae68a980d0140e24b9048eba098b/src/drivers/hardware_specific/generic_mcu.cpp#L58-L72), [\_writeDutyCycle6PWM](https://github.com/simplefoc/Arduino-FOC/blob/b3d8f3931342ae68a980d0140e24b9048eba098b/src/drivers/hardware_specific/generic_mcu.cpp#L116-L125)

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

Edit `_configure6PWM` in generic\_mcu.cpp. Replace it with:

```auto
// 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:

```auto
// 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:

 ![image](https://canada1.discourse-cdn.com/sparkfun/original/2X/4/42010945fa85ac5977996df0128d16ac2fba3566.png)

Best wishes,  
Paul

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 13, 2026, 6:06pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/3 "2026-10-13T18:06:28Z")

</div>

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](https://docs.sparkfun.com/SparkFun_Three_Phase_Motor_Driver-TMC6300/arduino_examples/example-BLDC/#example-code) 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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 14, 2026, 6:11am UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/4 "2026-10-14T06:11:26Z")

</div>

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](https://cdn.sparkfun.com/assets/1/5/c/6/7/Apollo3-Blue-MCU-Datasheet_v0_15_0.pdf) and the way `analogWrite` (`ap3_pwm_output`) is implemented in the [SparkFun core (CommonAnalog.cpp)](https://github.com/sparkfun/Arduino_Apollo3/blob/74a4786eef78e0457548d43e23366a20dfa4410e/cores/arduino/sdk/core-implement/CommonAnalog.cpp#L460-L686). 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

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 16, 2026, 12:21am UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/5 "2026-10-16T00:21:33Z")

</div>

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](https://docs.sparkfun.com/SparkFun_Three_Phase_Motor_Driver-TMC6300/hardware_overview/#current-sense-pin) . 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](https://docs.sparkfun.com/SparkFun_Three_Phase_Motor_Driver-TMC6300/arduino_examples/example-BLDC/)  
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.

 ![20261015_160224](https://canada1.discourse-cdn.com/sparkfun/original/2X/5/51ca5c41c37144371200c8a79640e0fa929309ca.jpeg)

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 19, 2026, 10:10pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/6 "2026-10-19T22:10:44Z")

</div>

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](https://mbed.com/s/error=0x80FF0144&tgt=SFE_ARTEMIS_ATP)

-- MbedOS Error Infor –

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

 ![20261019_140203](https://canada1.discourse-cdn.com/sparkfun/original/2X/0/03971e0bd7da4e1d2fff45e16eeda29be0c9f0cb.jpeg)

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 22, 2026, 3:49pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/7 "2026-10-22T15:49:09Z")

</div>

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](https://docs.simplefoc.com/position_control_example) 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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 22, 2026, 6:51pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/8 "2026-10-22T18:51:45Z")

</div>

Hi Boris (@B ),

Are you still using the [Three Phase Brushless Gimbal Stabilizer Motor](https://www.sparkfun.com/three-phase-brushless-gimbal-stabilizer-motor.html)? The datasheet says it has 8 poles, not 11. Could that be the problem?

 ![image](https://canada1.discourse-cdn.com/sparkfun/original/2X/0/0e8a324a02dbc1dd00d681177b7a81d07c3bef4b.png)

Best wishes,  
Paul

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 22, 2026, 9:48pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/9 "2026-10-22T21:48:15Z")

</div>

Hi PaulZC. I use these SparkFun gimbal motors with encoders AS5048A [Gimbal Motor with Encoder - 12V, 467RPM - SparkFun Electronics](https://www.sparkfun.com/catalog/product/view/id/17685/?utm_source=google&utm_medium=cpc&utm_campaign=Generic+%7C+PMax&utm_term=%7Badtype%7D&utm_content=Brand&gad_source=1&gad_campaignid=17479024039&gbraid=0AAAAADsj4ET-CoJduugAXjokHIkftSc1l&gclid=EAIaIQobChMI4eCaiMzOlwMV0wm8AR3YBiT9EAQYASABEgKKEfD_BwE) . The motor has 11 pole pairs based on its specification.

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 23, 2026, 6:05pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/10 "2026-10-23T18:05:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 23, 2026, 11:53pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/11 "2026-10-23T23:53:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 24, 2026, 12:56pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/12 "2026-10-24T12:56:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 26, 2026, 6:35pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/13 "2026-10-26T18:35:19Z")

</div>

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

[TLPE2\_Simple\_Diagram1.pdf](https://community.sparkfun.com/uploads/short-url/zXIy6dUFINVUifU3rP1xIhcjV6F.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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 28, 2026, 7:38pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/14 "2026-10-28T19:38:02Z")

</div>

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:

```auto
// 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:

```auto
#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

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 28, 2026, 9:16pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/15 "2026-10-28T21:16:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 28, 2026, 9:34pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/16 "2026-10-28T21:34:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 28, 2026, 9:40pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/17 "2026-10-28T21:40:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 28, 2026, 9:49pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/18 "2026-10-28T21:49:12Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [October 28, 2026, 9:57pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/19 "2026-10-28T21:57:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PaulZC](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/paulzc/32/67_2.png) [@PaulZC](https://community.sparkfun.com/u/PaulZC)\
**Post date:** [October 29, 2026, 4:49pm UTC](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735/20 "2026-10-29T16:49:21Z")

</div>

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](https://canada1.discourse-cdn.com/sparkfun/original/2X/6/6a9adf2aa4ee1a60001af12a4f47abd7914bf4d5.gif)

Here is the the report produced by Claude:

[SimpleFOC\_Artemis\_ATP\_Session\_2026-10-29.pdf](https://community.sparkfun.com/uploads/short-url/4Na5OO2PSkhEUVMmGcRerkZR79D.pdf) (287.8 KB)

You can find the apollo3\_mcu.cpp file it wrote at:

> <https://github.com/PaulZC/Arduino-FOC/blob/master/src/drivers/hardware_specific/apollo3_mcu.cpp>

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](https://github.com/PaulZC/Arduino-FOC/blob/master/src/drivers/hardware_specific/generic_mcu.cpp). All the new Apollo3 (Artemis) code is held in apollo3\_mcu.cpp.

Here is the revised single motor example:

```auto
#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:

```auto
#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

[Next page](https://community.sparkfun.com/t/problem-to-execute-simplefoc-code-on-sparkfun-redboard-artemis-atp/69735.md?page=2)
