0

I am trying to control a stepper motor, using a A4988 driver along with a Nucleo 144 board with an STM32F767ZI on it.

The A4988 driver expects a single rise in voltage to HIGH in order to step the motor.

Having made some voltage readings using a multimeter, I have found that during and even while the program is paused, there is a steady voltage of around 1.2V being output by the pin.

I also added some lines to toggle an LED (built onto the board) whenever the output to the A4988 driver is toggled between HIGH and LOW, which works fine.

Here is the code:

main.c

#include "./headers/stm32f767xx.h"
#include <stdint.h>

int main(void)
{
    initMotor(0);
    initLed(0);
    uint32_t a = 0;
    while (1)
    {
        if (a >= 300000)
        {
            toggleLed(0);
            stepMotor(0);
            a = 0;
        }
        a++; 
    }
}

./drivers/motor.c

#include "../headers/stm32f767xx.h"

void initMotor(int step_pin)
{
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN; // enable GPIOG clock
    GPIOG->MODER &= ~(0b11 << (step_pin * 2)); // clear bits
    GPIOG->MODER |= (0b01 << (step_pin * 2)); // set mode to OUTPUT
    GPIOG->OTYPER &= ~(0b1 << step_pin); // set output type to PUSH-PULL
    GPIOG->PUPDR |= (0b10 << (step_pin * 2)); // pull the pin down
    GPIOG->ODR &= ~(0b1 << step_pin); // set output to LOW
}

void stepMotor(int step_pin)
{
    GPIOG->ODR ^= (0b1 << step_pin); // toggle between LOW and HIGH
}

./drivers/led.c

#include "../headers/stm32f767xx.h"

void initLed(int pin)
{
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // enable GPIOG clock
    GPIOB->MODER |= (0b01 << (pin * 2)); // set mode to OUTPUT
    GPIOB->OTYPER &= ~(0b1 << pin); // set output type to PUSH-PULL
    GPIOB->ODR &= ~(0b1 << pin); // set output to LOW
}

void toggleLed(int pin)
{
    GPIOB->ODR ^= (0b1 << pin); // toggle between LOW and HIGH
}

I've verified, using a multimeter, that the voltage being provided to the board via an STLINK USB is 5V (which I believe is sufficient), and the driver is also receiving the correct voltage of 5V.

I do not believe this to be a problem to do with the A4988 driver. I have tried multiple of the same driver from various manufacturers, and still I get the same result. The motors are also being supplied a high enough voltage (12V) but are not drawing it all in.

I have come to the conclusion that it is most likely an issue originating from the Nucleo 144 board, but a little stuck as to what the actual issue is.

I am using GPIO G pin 0, which is labelled "IO" on the board.

Any suggestions as to what I should try next, or ideas as to what it could be, are greatly appreciated.


As requested, here is a diagram of my setup:

diagram

Starman
  • 168
  • 1
  • 11
  • 1
    this is an electrical engineering stack exchange question, also add your schematic and other relevant information. – old_timer Apr 07 '21 at 18:20
  • @old_timer I am asking here so I can try to eliminate the possibility that it is a software issue. I think the software I have written is correct, but of course I may have overlooked something due to a lack of knowledge. Saying this though, I think it is unlikely to be an issue with wiring either. Perhaps I should have rephrased the question to something along the lines of "why is the output not being changed" – Starman Apr 07 '21 at 18:25
  • does this chip have a bsrr? you can use that to set/clear the pin without (you) having to deal with the others. just FYI not necessarily a problem here. – old_timer Apr 07 '21 at 19:11
  • @old_timer it does, thanks i'll bear this in mind – Starman Apr 07 '21 at 19:21

1 Answers1

3

If you configure the output to be PUSH/PULL, adding a PULLDOWN resistor will divide the output voltage over the resistor. Do not use PU/PD resistors with PP, because it is always driven and doesn't need a PU/PD.

PeterT
  • 920
  • 8
  • 20
  • The pin I am outputting to on the driver is left floating. I have seen in various places on the internet not to leave pins floating, and that a pull up/pull down resistor should be used to stop this. How else should I handle this if I cannot use pull up/pull down resistors with push-pull? – Starman Apr 07 '21 at 18:29
  • 2
    @user15278978 Using push-pull output will always drive to either high or low, so the pu/pd resistor is not needed and the input will not be floating. like PeterT said, adding one in will create a voltage divider and will produce the results you're seeing. – theCreator Apr 07 '21 at 18:44
  • when you disconnect the driver chip and measure the pin what do you see? you dont need/want to combine push-pull and pull up/down. – old_timer Apr 07 '21 at 19:10
  • @theCreator thanks for clearing this up for me, i now understand this all a little better – Starman Apr 07 '21 at 19:22
  • @old_timer the voltage being output by this pin now seems to be stuck at 0V when disconnected from the driver, and around 4V when connected to the driver – Starman Apr 07 '21 at 19:24
  • double/triple check your init code, something seems broken. maybe you fried it. double check everything you sure you are on the right pin on the board and that pin number marking is the right pin and port a3 instead of b3 kind of a thing, etc, etc. right base address for the gpio port. try another gpio port or a few of them see if they all behave strange or just that one pin... – old_timer Apr 07 '21 at 21:18