Hey,
I am using an esp32 Wroom 32 dev board and I'm having trouble controlling a led with the analogWrite() function. I am using the simpleFOC libary to control a BLDC and it is working just fine. When I write a code only to fade the led it is working. But when I control the BLDC, the analogWrite function seems to stop working, only digitalWrite works. If I change the led control in this code to digitalWrite functions it will work. Does anyone has an idea what is going on?
#include <SimpleFOC.h>
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
BLDCMotor motor = BLDCMotor(11);
BLDCDriver6PWM driver = BLDCDriver6PWM(26, 25, 27, 32, 12, 33);
float target_voltage = 0.5;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }
void setup() {
pinMode(4,OUTPUT);
analogWrite(4,50);
sensor.init();
motor.linkSensor(&sensor);
driver.voltage_power_supply = 5;
driver.init();
motor.linkDriver(&driver);
motor.voltage_sensor_align = 5;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::torque;
Serial.begin(115200);
motor.useMonitoring(Serial);
motor.init();
motor.initFOC();
command.add('T', doTarget, "target voltage");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target voltage using serial terminal:"));
_delay(1000);
}
void loop() {
motor.loopFOC();
motor.move(target_voltage);
analogWrite(4,100)
command.run();
}