piranha32

Test case code

Dec 18th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <SimpleFOC.h>
  2. #include <esp_task_wdt.h>
  3.  
  4. TwoWire I2Cone = TwoWire(0);
  5. BLDCMotor motor = BLDCMotor(11);
  6. BLDCDriver3PWM driver = BLDCDriver3PWM(32,33,25,22);
  7. hw_timer_t *timer = NULL;
  8.  
  9.  
  10. void ARDUINO_ISR_ATTR foc_loop() {
  11. // noInterrupts();
  12. motor.loopFOC();
  13. motor.move(10);
  14. // interrupts();
  15. esp_task_wdt_reset(); //reset WDT
  16. }
  17.  
  18. void setup() {
  19. Serial.begin(115200);
  20.  
  21. esp_task_wdt_config_t wdt_config = {
  22. .timeout_ms = 5 * 1000, // 5s converted to ms
  23. .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
  24. .trigger_panic = true // Enable panic to restart ESP32
  25. };
  26.  
  27. Serial.println("De-init WDT");
  28. esp_task_wdt_deinit();
  29. Serial.println("Init WDT");
  30. esp_err_t ESP32_ERROR = esp_task_wdt_init(&wdt_config);
  31. Serial.println("Last Reset : " + String(esp_err_to_name(ESP32_ERROR)));
  32. esp_task_wdt_add(NULL); //add current thread to WDT watch
  33.  
  34.  
  35. Serial.println("RT test with disabled interrupts");
  36.  
  37. I2Cone.begin(19, 18, 400000);
  38.  
  39. driver.voltage_power_supply = 12;
  40. driver.init();
  41. motor.linkDriver(&driver);
  42.  
  43. motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
  44. motor.controller = MotionControlType::velocity;
  45.  
  46. motor.init();
  47. motor.initFOC();
  48.  
  49. Serial.println("Delay");
  50. _delay(1000);
  51.  
  52. Serial.println("RT timer attach");
  53. timer = timerBegin(1000000);
  54. timerAttachInterrupt(timer, &foc_loop);
  55. timerAlarm(timer, 100, true, 0);
  56.  
  57. Serial.println("Go!");
  58. }
  59.  
  60. void loop() {
  61. // motor.move(10);
  62. esp_task_wdt_reset(); //reset WDT
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment