Low-level stepper motor driving

Hi,
I have some stepper motors with “dumb” driver HW, meaning I have to connect it to 4 GPIO pins (1 GPIO pin = 1 motor coil) and set “1” on them in proper order to turn the motor.

Problem is that using standard async task schedulling doesn’t allow for high enough frequency (motor turns slowly) and also it isn’t very precise, so movement is not smooth.

Is it possible to use timer interrupt for this without breaking other SDK functionality?

Thanks for help.
Mixi

Hi mixi,

the SDK does not have support for fast periodic callbacks but I found nice hack.

There is a function HAL_SYSTICK_Callback which is not used and it is weak. Which means that you can override that function (which is empty in SDK) with your own.

The second thing to do is disable periodic sleep of the Core Module and enable PLL by calling bc_system_pll_enable(). Without this you get those irregularities.

I did a test and I have a function which is precisely called 1000 times per second and outputting 500 Hz signal.

You need to add this to the application_init()

    bc_system_pll_enable();

    // Debug GPIO
    bc_gpio_init(BC_GPIO_P9);
    bc_gpio_set_mode(BC_GPIO_P9, BC_GPIO_MODE_OUTPUT);

and add this function to the application.c

void HAL_SYSTICK_Callback(void)
{
    bc_gpio_toggle_output(BC_GPIO_P9);
}

And you get nice square wave

Let me know if this works for you.

Hi Martin,
this works perfectly, 1kHz callback frequency seems to allow for precise enough motor driving.

Thanks a lot.

Mixi

1 Like