Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SimpleFOC.h>
- #include <esp_task_wdt.h>
- TwoWire I2Cone = TwoWire(0);
- BLDCMotor motor = BLDCMotor(11);
- BLDCDriver3PWM driver = BLDCDriver3PWM(32,33,25,22);
- hw_timer_t *timer = NULL;
- void ARDUINO_ISR_ATTR foc_loop() {
- // noInterrupts();
- motor.loopFOC();
- motor.move(10);
- // interrupts();
- esp_task_wdt_reset(); //reset WDT
- }
- void setup() {
- Serial.begin(115200);
- esp_task_wdt_config_t wdt_config = {
- .timeout_ms = 5 * 1000, // 5s converted to ms
- .idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Bitmask of all cores, https://github.com/espressif/esp-idf/blob/v5.2.2/examples/system/task_watchdog/main/task_watchdog_example_main.c
- .trigger_panic = true // Enable panic to restart ESP32
- };
- Serial.println("De-init WDT");
- esp_task_wdt_deinit();
- Serial.println("Init WDT");
- esp_err_t ESP32_ERROR = esp_task_wdt_init(&wdt_config);
- Serial.println("Last Reset : " + String(esp_err_to_name(ESP32_ERROR)));
- esp_task_wdt_add(NULL); //add current thread to WDT watch
- Serial.println("RT test with disabled interrupts");
- I2Cone.begin(19, 18, 400000);
- driver.voltage_power_supply = 12;
- driver.init();
- motor.linkDriver(&driver);
- motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
- motor.controller = MotionControlType::velocity;
- motor.init();
- motor.initFOC();
- Serial.println("Delay");
- _delay(1000);
- Serial.println("RT timer attach");
- timer = timerBegin(1000000);
- timerAttachInterrupt(timer, &foc_loop);
- timerAlarm(timer, 100, true, 0);
- Serial.println("Go!");
- }
- void loop() {
- // motor.move(10);
- esp_task_wdt_reset(); //reset WDT
- }
Advertisement
Add Comment
Please, Sign In to add comment