a4988 component working?

mkeveney
Posts: 9
Joined: Sun May 05, 2019 12:25 am

a4988 component working?

Postby mkeveney » Sun May 05, 2019 1:01 am

I want to drive stepper motors, so I'm trying out the a4988 component.

No luck so far.

With code straight from the repo, I get this:

Code: Select all

    .
    .
    E (247) ledc: ledc_set_duty_with_hpoint(383): hpoint argument is invalid
    .
    .
Looking at the a4988.cpp(), it appears that the ledc init code never set
this 'hpoint' parameter. Perhaps that was for an earlier version of ESP-IDF?
The intr_type paramter is also missing.

So, I updated a4988.cpp to initialize these to (what I assume to be) reasonable defaults:

Code: Select all

  ledc_ch.intr_type  = LEDC_INTR_DISABLE;
  ledc_ch.hpoint     = 0;
This cures the 'hpoint' error, but now I get a 'LoadProhibited' crash:

Code: Select all

    Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
    Core 0 register dump:
    PC      : 0x40086423  PS      : 0x00060930  A0      : 0x800864f2  A1      : 0x3ffb6ae0
    0x40086423: prvProcessReceivedCommands at /Users/mkeveney/src/esp/esp-iot-solution/submodule/esp-idf/components/freertos/timers.c:961

    A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x3ffb51b4
    A6      : 0x00000000  A7      : 0x00000001  A8      : 0x00000008  A9      : 0x3ffb6aa0
    A10     : 0x00000001  A11     : 0x00000000  A12     : 0x3ffb6314  A13     : 0x00000000
    A14     : 0x3ffb63ac  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x0000001c
    EXCVADDR: 0x00000014  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000

    Backtrace: 0x40086423:0x3ffb6ae0 0x400864ef:0x3ffb6b20
    0x40086423: prvProcessReceivedCommands at /Users/mkeveney/src/esp/esp-iot-solution/submodule/esp-idf/components/freertos/timers.c:961

    0x400864ef: prvTimerTask at /Users/mkeveney/src/esp/esp-iot-solution/submodule/esp-idf/components/freertos/timers.c:961
The EXCVADDR 0x0000014 suggests a null reference to a struct, but there doesn't seem to be such a reference near the code referenced in the backtrace. Am I missing something obvious?

My code is almost verbatim from the unit test:

Code: Select all

    CA4988Stepper stepper(CONFIG_STEP_GPIO, CONFIG_DIR_GPIO, STEPS_PER_REV,
        LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0);

    stepper.setSpeedRpm(80);
    stepper.step(100);
    vTaskDelay(1000/portTICK_RATE_MS);      // crash happens during this delay.
    stepper.step(-100);
    vTaskDelay(1000/portTICK_RATE_MS);
Has anyone ever got this component working? What's the secret?

-Matt

ESP_@In逍遥子
Posts: 132
Joined: Thu Nov 15, 2018 2:06 am

Re: a4988 component working?

Postby ESP_@In逍遥子 » Mon May 06, 2019 2:13 am

Hi,
Please provide your complete log and code for analysis.

mkeveney
Posts: 9
Joined: Sun May 05, 2019 12:25 am

Re: a4988 component working?

Postby mkeveney » Tue May 07, 2019 6:48 pm

> Please provide your complete log and code for analysis.

Will do shortly. I got tied up for a few days. Thanks for your interest.

mkeveney
Posts: 9
Joined: Sun May 05, 2019 12:25 am

Re: a4988 component working?

Postby mkeveney » Wed May 08, 2019 3:19 am

Here's my source code (including a log as produced by 'make monitor').
The 'stepper_test' directory goes in 'examples' under esp-iot-solution/.
I'm also including my modified a4988 directory. The only change is the two lines mentioned above.

Thanks for taking the time!
Attachments
a4988-test.zip
(30.3 KiB) Downloaded 843 times

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: a4988 component working?

Postby meowsqueak » Fri Feb 14, 2020 9:30 pm

@mkeveney - did you end up solving this problem? I found `a4988.cpp` in the espressif/esp-iot-solution repository, but I'm not sure about the status of this repository at the moment - seems to have been a long time since it was last updated. In particular, `a4988.cpp` hasn't been updated since July 2018, predating your post.

gmdriscoll
Posts: 9
Joined: Mon May 11, 2020 8:26 pm

Re: a4988 component working?

Postby gmdriscoll » Sat Jun 27, 2020 11:54 am

Hello, I would like to re-open this issue.

With either low speeds and/or short distances, the ESP returns:
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4008fd37 PS : 0x00060130 A0 : 0x8008fe02 A1 : 0x3ffc5d00
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000002 A5 : 0x00000001
A6 : 0x00060021 A7 : 0x00060023 A8 : 0x00000008 A9 : 0x3ffc5cc0
A10 : 0x00000001 A11 : 0x00000000 A12 : 0x3ffc5550 A13 : 0x00000000
A14 : 0x3ffc55e8 A15 : 0x3ffbc370 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000014 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000

With a low velocity specified with no acceleration, or using a high frequency with acceleration, the application errors out. It also errors out with the same error if a move completes and there is a delay in them main calling task. ie vTaskDelay(5000/portTICK_RATE_MS); //delay

This is does not happen all the time, but easily reproduced in a short amount of time.

Thanks

gmdriscoll
Posts: 9
Joined: Mon May 11, 2020 8:26 pm

Re: a4988 component working?

Postby gmdriscoll » Sun Jun 28, 2020 9:42 pm

I found the main problem. Looks like it is trying to stop the acceleration timer using a null object when it completes the step sequence.
In a4988.cpp, the interrupt handler stepper_pcnt_intr_handler needs a check to make sure the timer pointer is not null before stopping it.
change:
xTimerStopFromISR(dev->tmr, &HPTaskAwoken);

to:
if (dev->tmr){
xTimerStopFromISR(dev->tmr, &HPTaskAwoken);
}

Good Luck!

bunfight
Posts: 14
Joined: Mon Mar 08, 2021 5:33 pm

Re: a4988 component working?

Postby bunfight » Tue Mar 16, 2021 12:18 pm

Hello

Is this working OK now? I wish to control a stepper with an ESP32 but the espressif a4988 project appears absent from github.

Can you post a working version of the a4988 project which was on github, or any version at all?

Thanks.

Who is online

Users browsing this forum: No registered users and 10 guests