VNH3SP30 Motor Driver not working with STM32F4 Discovery

Hi, I recently bought a Pololu VNH3SP30 Motor Driver for a project I am currently working on. I’d like to control the DC motor I currently have (datasheet mfacomodrills.com/pdfs/Minia … motors.pdf), an MFA como drills re 540/1.

I currently use an STM32F4 Discovery board to produce a PWM pulse of roughly 10kHz at 50% duty cycle (have tried various frequencies 1-10kHz and duty cycles), and to control the state of INA and INB (I will upload a picture of the oscilloscope output on Monday). Unfortunately the motor does not turn when the motor driver is supplied with an Ansmann 7.2V 3000mAh battery supply (datasheet rapidonline.com/pdf/18-3811.pdf). I have tested the input voltage to be 7.4V at the motor driver terminals, also the PWM voltage input is 1.44V at 50% duty cycle and the INA are INB voltages are roughly 2.9V (obv not at the same time :p), but measures 0V at the motor terminals. Attached is a picture of my current setup, where you can see the blue LED which is connected to the PWM timer at 10kHz. Code is below:

[code]#include “stm32f4xx.h”
#include “system_stm32f4xx.h”
#include “stm32f4xx_usart.h”
#include “stdio.h”

void INIT_(void);
//void delay(unsigned int);

/**************************** Main program *****************************/

int main (void){
INIT_();
GPIOD->ODR|=0x01; //Set INA high and INB low for clockwise rotation
TIM_SetCompare4(TIM4, 250); // 250 = 50% duty cycle
while(1){
}

}

/**************************** Ports and Timer Setup *****************************/

void INIT_(void){

GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;

/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

/* INA Port D pin 0 (PD.00) configuration */ //INA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* INB Port D pin 1 (PD.01) configuration */ //INB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* TIM4 channel 4 pin (PD.15) configuration */ //Motor Timer
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_TIM4);

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 16; //(sysclk/2/5MHz Timer 3 clk)-1
TIM_TimeBaseStructure.TIM_Period = 499; //(5MHz/10KHz output clk)-1 produces 10kHz output
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4 , &TIM_TimeBaseStructure);

TIM_OCStructInit (& TIM_OCInitStructure); //Setup Output Capture Compare
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC4Init(TIM4 , &TIM_OCInitStructure);

// Enable Timer Interrupt and Timer
//TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4 , ENABLE);
}
[/code]

Please could someone help me to get this working as it’s a crucial part of my project? Thank you :slight_smile:

P.S. If any more info is required please let me know


Hello.

Your PWM and INx voltages are too low for that driver. According to the datasheet, the minimum voltage for a high signal on those pins is 3.25V. How were you measuring the voltage?

- Jeremy

Thank you so much for your reply. I had thought this might be the issue, but I have used 2n2222a transistors for the INA, INB and PWM pins from the discovery board. All pins now output 5v, and the motor driver works correctly :smiley: For anyone else who has come across this problem; attached is a proteus sketch of the transistor circuit is used for each INA, INB and PWM pin from the discovery board. When a GPIO pin is set high the output voltage is 0V, and when low is 5V. So if you want the motor to rotate clockwise set the GPIOs controlling INA low and INB high. Doesn’t matter for PWM since it simply inverts the pulse:

GPIOD->ODR|=0x02;                //Set INA low and INB high for clockwise rotation   //INVERTED

Also setting the timers prescaler and pwm period values to the following will give you a period of roughly 9.8 Khz (dont forget to set timer capture compare accordingly!):

TIM_TimeBaseStructure.TIM_Prescaler = 16; //(sysclk/2/5MHz Timer 3 clk)-1 TIM_TimeBaseStructure.TIM_Period = 160; //(5MHz/10KHz output clk)-1 produces 10kHz output

Hope this can help people with the same problem, and thanks once again to JeremyT cheers :slight_smile:

P.S. Picture of working setup attached also… Good luck!




Thanks for letting us know and sharing your schematic. I am glad you got it working.

- Jeremy