Home > Software engineering >  ESP32 Two stepper motor on different speed
ESP32 Two stepper motor on different speed

Time:03-16

I want to control two stepper motors at the same time but one needs to be slower (about 83% in comparison with the other stepper motor). I'm using an esp32 for programming. By my code I only can change both stepper motors speed at the same time.

#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "errno.h"
#include "string.h"
#include "esp_log.h"
#include "driver/mcpwm.h"

#define dir 26
#define step 25
#define dir1 21
#define step1 19


void app_main(void)   {

  printf("hello");
  gpio_reset_pin(dir);
  gpio_reset_pin(step);
  gpio_reset_pin(dir1);
  gpio_reset_pin(step1);
  
  gpio_set_direction(dir, GPIO_MODE_OUTPUT);
  gpio_set_direction(step, GPIO_MODE_OUTPUT);
  gpio_set_direction(dir1, GPIO_MODE_OUTPUT);
  gpio_set_direction(step1, GPIO_MODE_OUTPUT);


while (1)
  { 
    vTaskDelay(1000/portTICK_PERIOD_MS);
    //Rechts
    gpio_set_level(dir1, 1); 
    gpio_set_level(dir, 1); 

    for (int i = 0; i < 1500; i  )
    {
    gpio_set_level(step1, 1);
    gpio_set_level(step, 1);
    ets_delay_us(1500);
    gpio_set_level(step1, 0);
    gpio_set_level(step, 0);
    ets_delay_us(1500);
    }

CodePudding user response:

You can use parallel programming. So you can do two things at the same time. So if you do that by this case you can program 1 stepper motor faster then the other one. See esp32 documents for examples parallel programming on the esp32

  • Related