Thank you for the quick response.
I have only used GitHub to download items - I have never uploaded or created forks etc. I will try to find some examples of defining static variables and functions. These variables are created in the first section of my sketch and the nrfx_ routine is from another library loaded in the sketch. I believe this nrfx_ library is the only way to get into the bowels of PWM functions on the Nordic platform (a 4x4 chip with DMA etc - see https://content.arduino.cc/assets/Nano_BLE_MCU-nRF52840_PS_v1.1.pdf for more details on it and all the other built in functions such as Encoders) - with this I can change the PWM frequency, the create a count_Up_Down PWM trigger which essentially would create centre aligned PWMs.
This is in the Pre-amble
// PWM Library
#include "nrfx_pwm.h"
static nrfx_pwm_t pwm1 = NRFX_PWM_INSTANCE(0);
static nrf_pwm_values_individual_t seq1_values[] = {0, 0, 0, 0};
static nrf_pwm_sequence_t seq1 = {
.values = {
.p_individual = seq1_values
},
.length = NRF_PWM_VALUES_LENGTH(seq1_values),
.repeats = 1,
.end_delay = 0
};
the Setup section has the following
nrfx_pwm_config_t config1 = {
.output_pins = {
0x80 + 32 + 2, // Arduino pin 10
0X80 + 32 + 1, // Arduinopin 11
0X80 + 32 + 8, // Arduino pin 12
NRFX_PWM_PIN_NOT_USED,
},
.irq_priority = 7,
.base_clock = NRF_PWM_CLK_2MHz,
.count_mode = NRF_PWM_MODE_UP_AND_DOWN,
.top_value = 255,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_TRIGGERED,
};
nrfx_pwm_init(&pwm1, &config1, NULL);
And from the loop section I can change the 3 variables that I tried to add to the subroutine earlier and the call the playback routine as described earlier.
(*seq1_values).channel_0 = (255 - constrain(int(255.0*dc_a),0,255));
(*seq1_values).channel_1 = (255 - constrain(int(255.0*dc_b),0,255));
(*seq1_values).channel_2 = (255 - constrain(int(255.0*dc_c),0,255));
(void)nrfx_pwm_simple_playback(&pwm1, &seq1, 1, NRFX_PWM_FLAG_LOOP);
In the interrupt that is called based on when the PWM waveform has completed I call a
nrfx_pwm_stop(&pwm1,false);
If this code was not used then if someone could simple remove the code from the compiler that references the experimental code regarding a locked I2C bus (maybe put within a
#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
section) and then the rest would compile and load on the BLE33 (and I assume the Sense) and run using the standard Generic Hardware calls. I modified /Sensors/MagneticSensorsI2C.cpp & h, and /base_classes/sensor.h.
I do not have a scope so I donât know if those calls would be center aligned PWMs. I think I saw in the Arduino docs that the PWM frequency by default on the BLE33 is 50Khz.
In regards to my interrupt structure - I do not want to replace the two main loop calls - simply call them on a regular interval determined on the interrupt. I have many other tasks that need to be done other than just running the motor in my project (flight controls, SBUS Receiving & Transmitting, GPS decoding, etc). Unless I am assuming wrong - the only way to perform the other tasks and keep the fast running motor code running is via interrupts. If this controller becomes overloaded I may need to look at a smart FOC board with its own processor that can be used simply to manage the motor position and speed control.
Thanks again and Regards