diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index d165199..b3db265 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -26,21 +26,21 @@ jobs: - arduino:mbed_rp2040:pico # rpi pico include: - arduino-boards-fqbn: arduino:avr:nano - sketches-exclude: calibrated mt6816_spi smoothing + sketches-exclude: calibrated mt6816_spi smoothing simplefocnano_torque_voltage required-libraries: Simple FOC - arduino-boards-fqbn: arduino:sam:arduino_due_x required-libraries: Simple FOC - sketches-exclude: calibrated smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated smoothing simplefocnano_torque_voltage simplefocnano_atmega - arduino-boards-fqbn: arduino:samd:nano_33_iot required-libraries: Simple FOC sketches-exclude: calibrated smoothing - arduino-boards-fqbn: arduino:mbed_rp2040:pico required-libraries: Simple FOC - sketches-exclude: calibrated smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated smoothing simplefocnano_torque_voltage simplefocnano_atmega - arduino-boards-fqbn: adafruit:samd:adafruit_metro_m4 platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json required-libraries: Simple FOC - sketches-exclude: calibrated smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated smoothing simplefocnano_torque_voltage simplefocnano_atmega # - arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # platform-url: https://dl.espressif.com/dl/package_esp32_index.json # required-libraries: Simple FOC @@ -48,19 +48,19 @@ jobs: - arduino-boards-fqbn: esp32:esp32:esp32 # esp32 platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json required-libraries: Simple FOC - sketches-exclude: calibrated smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated smoothing simplefocnano_torque_voltage simplefocnano_atmega - arduino-boards-fqbn: esp32:esp32:esp32s2 # esp32s2 platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json required-libraries: Simple FOC - sketches-exclude: calibrated smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated smoothing simplefocnano_torque_voltage simplefocnano_atmega - arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json required-libraries: Simple FOC - sketches-exclude: calibrated mt6816_spi smoothing simplefocnano_torque_voltage + sketches-exclude: calibrated mt6816_spi smoothing simplefocnano_torque_voltage simplefocnano_atmega - arduino-boards-fqbn: STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json required-libraries: Simple FOC - sketches-exclude: smoothing simplefocnano_torque_voltage + sketches-exclude: smoothing simplefocnano_torque_voltage simplefocnano_atmega # Do not cancel all jobs / architectures if one job fails fail-fast: false steps: diff --git a/examples/drivers/simplefocnano/simplefocnano_atmega/simplefocnano_atmega.ino b/examples/drivers/simplefocnano/simplefocnano_atmega/simplefocnano_atmega.ino new file mode 100644 index 0000000..5bbe119 --- /dev/null +++ b/examples/drivers/simplefocnano/simplefocnano_atmega/simplefocnano_atmega.ino @@ -0,0 +1,68 @@ +#include +#include +#include "SimpleFOC.h" +#include "SimpleFOCDrivers.h" +#include "drivers/simplefocnano/SimpleFOCNanoDriver.h" +#include "encoders/as5048a/MagneticSensorAS5048A.h" + + +MagneticSensorAS5048A sensor = MagneticSensorAS5048A(PIN_nCS); +SimpleFOCNanoDriver driver = SimpleFOCNanoDriver(); +BLDCMotor motor = BLDCMotor(11); // 11 pole pairs + +long loopts = 0; +int iterations = 0; +float volts = 0.0f; + +void setup() { + Serial.begin(115200); // enable serial port + delay(5000); + SimpleFOCDebug::enable(); // enable debug messages to Serial + + sensor.init(); // init sensor on default SPI pins + + // read voltage + SimpleFOCDebug::print("Bus voltage: "); + volts = driver.getBusVoltage(5.0f, 1024); // 5V reference, 10-bit ADC + SimpleFOCDebug::println(volts); + driver.voltage_power_supply = volts; // set driver voltage to measured value + driver.voltage_limit = 10.0f; // limit voltage to 10V + driver.pwm_frequency = 30000; // set pwm frequency to 30kHz + driver.init(); // init driver + + motor.linkSensor(&sensor); // link the motor to the sensor + motor.linkDriver(&driver); // link the motor to the driver + + motor.controller = MotionControlType::torque; // torque control + motor.torque_controller = TorqueControlType::voltage; // use voltage torque control + motor.voltage_limit = driver.voltage_limit / 2.0f; // limit voltage to 1/2 of driver limit + motor.voltage_sensor_align = 4.0f; // align voltage sensor to 4V + + motor.init(); // init motor + delay(100); // wait for driver to power up + motor.initFOC(); // init FOC and calibrate motor + + Serial.println("Motor ready."); + loopts = millis(); + + // Set the motor target to 2 volts + motor.target = 2.0f; +} + + +void loop() { + motor.move(); + motor.loopFOC(); + long now = millis(); + iterations++; + if (now - loopts > 1000) { + Serial.print("Iterations/s: "); + Serial.println(iterations); + Serial.print("Angle: "); + Serial.println(sensor.getAngle()); + loopts = now; + iterations = 0; + } + if (now - loopts < 0) + loopts = 0; +}