PWM based motor driver added from other project

This commit is contained in:
2024-11-16 20:04:38 +01:00
parent f6608075ff
commit 0181c72a9d
17 changed files with 1288 additions and 6 deletions
+23 -2
View File
@@ -29,6 +29,7 @@
// Component header
#include "Task.hpp"
#include "PwmExpanderPca9685.hpp"
#include "StepperDrv8833.hpp"
static const char *TAG = "Watch";
static esp_eth_handle_t s_eth_handle = NULL;
@@ -114,8 +115,8 @@ void LightingTask() {
ESP_LOGI(TAG, "Start Lighting");
static I2cMaster master(I2C_NUM_0,
/*sda=*/ GPIO_NUM_13,
/*scl=*/ GPIO_NUM_16);
/*sda=*/ GPIO_NUM_0,
/*scl=*/ GPIO_NUM_4);
// static PmwExpanderPca9685 pca9685(master);
static PmwExpanderPca9685 ledDriver1(master, /*iverted=*/ true);
static PmwExpanderPca9685 ledDriver2(master, /*iverted=*/ true, 0x41);
@@ -139,6 +140,25 @@ void LightingTask() {
}
}
void MovementTask() {
ESP_LOGI(TAG, "Start Stepper");
constexpr int MicroSteps = 32;
StepperDriverDrv8833::Pins stepperPins{
LEDC_TIMER_0,
{LEDC_CHANNEL_0, LEDC_CHANNEL_1, LEDC_CHANNEL_2, LEDC_CHANNEL_3},
{GPIO_NUM_16, GPIO_NUM_15, GPIO_NUM_14, GPIO_NUM_13},
};
StepperDriverDrv8833 stepperDriver(stepperPins, MicroSteps);
stepperDriver.setPos(0);
while (true) {
stepperDriver.step(1);
stepperDriver.getSubPos();
fos::Task::delayMs(100);
}
}
void app_main(void)
{
esp_err_t ret = nvs_flash_init();
@@ -150,4 +170,5 @@ void app_main(void)
// ESP_ERROR_CHECK(esp_event_loop_create_default());
initialize_ethernet();
static fos::Task lightingTask(LightingTask, "Lights", 0x4000uL);
static fos::Task movementTask(MovementTask, "Motor", 0x4000uL);
}