0

I want to control stepper motors with an ESP32 directly via a L298 power driver. That works with fullstep mode, but I cannot generate the signals for halfstep mode (Enable, In1, In2 In3, In4). Here is the constructor of the control class:

    McpwmStepperControl::McpwmStepperControl(gpio_num_t In1, gpio_num_t In2,
        gpio_num_t EnA, gpio_num_t In3, gpio_num_t In4, gpio_num_t EnB, gpio_num_t CapPin, gpio_num_t RefPin, int GroupID)
            : _reverse(false), _In1(In1), _In2(In2), _EnA(EnA), _In3(In3), _In4(In4), _EnB(EnB), _CapPin(CapPin), _RefPin(RefPin),
             _GroupID(GroupID), _direction(false), _error_relay(0), _debounce(0),
             Timer(GroupID),
             Operator{McpwmOperator(GroupID), McpwmOperator(GroupID), McpwmOperator(GroupID)},
             Comparator{McpwmComparator(Operator[0]), McpwmComparator(Operator[1]), McpwmComparator(Operator[2])},
             Generator{McpwmGenerator(Operator[0], In1, 0), McpwmGenerator(Operator[0], In2, 1),
                 McpwmGenerator(Operator[1], In3, 0), McpwmGenerator(Operator[1], In4, 1),
                 McpwmGenerator(Operator[2], EnA, 0), McpwmGenerator(Operator[2], EnB, 0) } 
{
    setSpeeds(10, 150); // set default values
    _dp = GPIO_NUM_NC;
    Operator[0].connectTimer(Timer);
    Operator[1].connectTimer(Timer);
    Operator[2].connectTimer(Timer);
    Timer.setComparators(&Comparator);
}

Here is how I try to initialize one of the generators:

    ESP_ERROR_CHECK(mcpwm_generator_set_actions_on_timer_event(Generator[0].getHandle(),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, Comparator[0].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, Comparator[1].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, Comparator[2].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, Comparator[2].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, Comparator[1].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, Comparator[0].getHandle(), MCPWM_GEN_ACTION_TOGGLE),
            MCPWM_GEN_COMPARE_EVENT_ACTION_END()
            ));

The code compiles and starts ok, but no it only toggles at the Comparator[0] events. (I commented out all combinations of MCPWM_GEN_COMPARE_EVENT_ACTION macros, but I always get the same waveform). Is this a trivial coding bug or a limitation of the ESP32 MCPWM hardware?

Scope image

The yellow channel is triggered by timer full and empty and the blue channel is the generator output. As you can see, it only toggles on Comparator[0].

Here is the link to the complete code on github:

https://github.com/tommiport5/McpwmTest.git

0

1 Answer 1

0

I actually found limitations in the implementation of th MCPWM hardware, which were not so clear to me from the documentation:

  1. A group can have 3 operators.
  2. One operator can have up to 2 comparators.
  3. One operator can have up to 2 generators.
  4. A generator can only react on comparator events from its own operator.

With these limitations I currently don't see a way to generate the 4 independent signals for half step mode. Feel free to use my test system on github as a base for your research.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.