Hi everyone,
I’m trying to get the SimpleFOC library working, and I’m using the following hardware setup:
- ESP32-S3-DevKitC-1-N32R8V
- Brushless Motor Driver TMC6300
- T-EM3215D2450Y1R-BEZE (same motor used by smartknob)
Unfortunately, the motor behavior is not as expected. It moves in a jerky way, switching directions back and forth.
Does this sound like a configuration issue to you?
Here is the code I’m using:
#include <stdio.h>
#include <math.h>
#include <Arduino.h>
#include <SimpleFOC.h>
#include "common.h"
#include "LED_App.h"
#include "My_sensor.h"
// Timer
hw_timer_t *timer = NULL;
volatile unsigned int u16_clock1ms = 0;
// Variables
// Define the pins for motor control
const int UL = 16;
const int UH = 8;
const int VL = 7;
const int VH = 18;
const int WL = 15;
const int WH = 17;
// Callback function for the timer
void IRAM_ATTR onTimer()
{
u16_clock1ms++;
}
void blink_led()
{
if (TIME_OVER(u16_clock1s, u16_clock1ms))
{
u16_clock1s = u16_clock1ms + TIMEOUT_1s;
if (bl_led_toggle == true)
{
LED_app_setColor("green", 10);
}
else
{
LED_app_setColor("green", 0);
}
bl_led_toggle = !bl_led_toggle;
}
}
BLDCMotor motor = BLDCMotor(7); // Number of motor poles
BLDCDriver6PWM driver = BLDCDriver6PWM(UH, UL, VH, VL, WH, WL);
MySensor sensor;
void setup()
{
// Reset tick system
u16_clock1ms = 0;
u16_clock1s = 0;
// Configure the timer for a 1 ms period (1000 microseconds)
timer = timerBegin(0, 80, true); // Timer 0, prescaler 80, count up
timerAttachInterrupt(timer, &onTimer, true); // Attach the interrupt
timerAlarmWrite(timer, 1000, true); // Period of 1000 microseconds (1 ms)
timerAlarmEnable(timer); // Enable the timer alarm
Serial.begin(9600);
SimpleFOCDebug::enable();
driver.voltage_power_supply = 5; // Motor power supply voltage
driver.init();
motor.linkDriver(&driver);
motor.voltage_limit = 5; // Voltage limit
motor.controller = MotionControlType::torque; // Control type: torque
motor.torque_controller = TorqueControlType::voltage;
motor.phase_resistance = 1.1;
sensor.init();
motor.linkSensor(&sensor);
motor.init();
motor.initFOC();
delay(1000);
}
void loop()
{
blink_led();
motor.loopFOC();
motor.move(2);
}
And here is the terminal output:
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: OK!
MOT: No current sense.
MOT: Ready.
Any help or suggestions would be greatly appreciated. Thanks in advance!