Help with Pololu DRV8711 Stepper Motor Driver
Hello - I am trying to write a simple program to run a stepper motor back and forth using the Pololu DRV8711 driver (Link: https://www.pololu.com/product/3730). In order to use the driver, you must first enable it and then you can use the DIR and Step Pins to run your stepper. With other drivers, all you needed to do was drive the ENABLE pin high and you were good to go. With the 8711 board, you have to enable it via SPI. This is done by sending 16-bit values to the registers on the board. Page 27 of the data sheet for this (Link: https://www.ti.com/lit/ds/symlink/drv8711.pdf) shows the registers and gives the default values. Technically, all I should have to do is to set bit 0 of the CTRL register to 1 and that should enable the motor, correct? I also want to limit the current to 1/2 of it's maximum value of 4A. This is done using the lower 8 bits of the TORQUE register. Here is my routine to do that:
Code:
'****************************************************************
InitStepper1:
'Set current to 1/2 max (2A)
'$1180 = %0001000110000000
high M1SCS
Shiftout m1SDAT, M1SCLK, 1, [$1180/16]
low M1SCS
pause 50
'Enable Motor
'$0C11 = %0000110000010001
high M1SCS
Shiftout m1SDAT, M1SCLK, 1, [$0C11/16]
low M1SCS
return
'****************************************************************
I am leaving all of the other values at their default. After executing the InitStepper1 code, I go to stepping the motor by pulsing the STEP pin and nothing happens. My stepper spins freely and I get no indication from my power supply that there is any additional current draw. Is there something I am not doing or doing wrong? Thanks! Jeff
Re: Help with Pololu DRV8711 Stepper Motor Driver
Looks like you're shifting out $1180 divided by 16, truncated to 8 bits, so $22. That's not what you want, is it?
Be careful with / vs \ ;-)
Re: Help with Pololu DRV8711 Stepper Motor Driver
THANKS! Good catch and yes, I feel stupid. I will give this a try and let you know if that was it! Jeff
1 Attachment(s)
Re: Help with Pololu DRV8711 Stepper Motor Driver
Well, While that was a problem, it was not THE problem. Still no movement. I tried both mode 1 and mode 0 for the SHIFTOUT methods, also, to no avail.
Here is a snip of the circuit board design for examination. It seems pretty straight forward, so I think my issue is with setting the registers. Any thoughts are appreciated.
NOTES: There are 2 drivers on board. Green traces = 5V, Blue = Gnd, Red = 12V, Black = Signal. PIC = PIC16F877A. Thanks!
Attachment 9972
Re: Help with Pololu DRV8711 Stepper Motor Driver
Hmm...PortA...have you disabled the analog functions (ADCON1 and CMCON registers, I believe)?
Have you verified (logic analyzer or scope) that the expected data does appears on the pins?
Re: Help with Pololu DRV8711 Stepper Motor Driver
Yes, I did set ADCON1 and no, I have not used a scope on this yet. Here is the entire code. I am simply trying to initialize the driver and run a stepper back and forth with 2 LEDs that indicate which direction. I really feel that there is some initialization that I am not doing or not doing correctly. Other than setting the torque and enabling the driver, I am using all the other register defaults... Thanks!
Code:
'****************************************************************
DEFINE OSC 20
@ DEVICE HS_OSC
TRISA = %00000000
TRISB = %10111111
TRISC = %01110000
TRISD = %00000000
TRISE = %00000000
ADCON1 = 7 ' Set PortA Pins as I/O pins
' M1 = Stepper1
M1SCS var PORTB.6
M1SCLK var PORTA.0
M1SDAT var PORTA.1
M1DIR Var PORTA.2
M1STEP var PORTA.3
RedInd var PORTD.0
GrnInd var PORTD.1
Icnt var word
M1NumSteps var word
M1Delay var word 'delay between steps - 250-12500 uS
' CTRL Register
' EnableON = %0000110000010001 '$0C11
' EnableOFF = %0000110000010000 '$0C10
' Torque Register
' Torque50 = %0001000110000000 'Set current at 50% (2A) $1180
' Torque100 = %0001000111111111 'Set current at 100% (4A) $11FF
'****************************************************************
low RedInd
low GrnInd
low M1SCS ' Set reset pin low
low M1Sclk ' Set clock pin low
low M1Step
'****************************************************************
pause 1000
goto TestStepper1
'****************************************************************
'****************************************************************
TestStepper1:
gosub InitStepper1
M1numsteps = 4000
M1Delay = 5000 'uS between steps
DoAgain1:
high RedInd
low GrnInd
low M1DIR 'CW
for icnt = 1 to M1numsteps
high M1step
pauseus 10
low M1Step
pauseus M1Delay
next
low RedInd
low GrnInd
pause 1000
low RedInd
high GrnInd
high M1DIR 'CCW
for icnt = 1 to M1numsteps
high M1step
pauseus 10
low M1Step
pauseus M1Delay
next
low RedInd
low GrnInd
pause 1000
goto DoAgain1
'****************************************************************
InitStepper1:
'Set current to 1/2 max (2A)
'$1180 = %0001000110000000
high M1SCS
Shiftout m1SDAT, M1SCLK, 0, [$1180\16]
low M1SCS
pause 50
'Enable Motor
'$0C11 = %0000110000010001
high M1SCS
Shiftout m1SDAT, M1SCLK, 0, [$0C11\16]
low M1SCS
return
'****************************************************************
End