DRV8711 BOOST programming using Energia on MSP430F5529

drv8711 arduino tutorial
Help us grow. Share with your friends!

I recently required the nice little DRV8711 stepper motor driver to run a large stepper motor. I especially like the ability to easily program it and use the internal microstepping indexer. If you have ever tried doing microstepping on a stepper motor, you would know that it is not that easy. The DRV8711 has an internal indexer which you can configure to do 1/2, 1/4….upto 1/256 stepping resolution. Additionally, the BOOSTER pack also has low Rds MOSFETs which do not get hot at all. If you prefer to create your own stepping sequence by manually turning the pins on and off, you can do so by disabling the internal indexer.

There is automatic fault and stall detection, so you do not have to worry about excess current running through the motor and burning the coils. Thanks to this mechanism, I was able to identify a faulty motor I had. One of the coils in the stepper motor had a burnt coil and that was causing excess current to be drawn because of ruined insulation (enamel coating). The auto-fault detection was stopping the motor from taking more than 1 step and then stalling it.

The status register gives full information about what fault has occurred. I did not feel the need to read the registers back as I was quite sure that my code was able to program the registers, but the undue stalling of motor made me quite frustrated and only then I decided to read back the registers. We will talk about this further down the line in this article. First let us have a look at how to program this little monster.

I am using Energia API because I am a lazy programmer that likes to have easy to use functions at hand to speed up the process.

Firstly, I include all the necessary libraries. Since, I am using Code Composer Studio, I had to manually include Energia.h at the beginning. Then there is the same old stuff required to initialize the whole thing.

This function initializes all the registers on DRV8711 chip through SPI.

The entire function is shown below:

The contents of each register can be modified as per your needs by carefully reading the data sheet.

As the function name says, it is used to write the register contents using SPI interface. You have to make sure that you use correct format to form your register word before writing. While writing, the MSB has to be low and the following 3 bits are register addresses. Thus, if you are writing the STALL register which has the address 0x05H, your first 4 bits will be 0101 and then your register content will follow. All registers are 16 bits in width.

When you want to read the register back, you have to form a word with MSB = 1 and the following three bits indicate the register address that you intend to read. So, for reading back the STALL register you will need your word to be 1101. Indeed, this is not the entire word, but you get the idea how it should begin.

The above code gives you the entire insight into the function. The commented part shows that you can use the Energia SPI function to make your day easy, but I preferred to do it the other way. Additionally, the readData will contain the register value you intended to access only while reading the register, otherwise it would return null if you are writing to register.

This function does exactly as it says, it fetches all the register values and prints it on the Serial terminal. Optionally, you can modify the code to read the registers and store it in a 16 bit wide variable if you prefer to do conditional programming or change the configuration automatically by taking feedback from the driver chip.

Now we arrive at the point when we have done initializing the register and got ourselves ready with necessary functions. All we have to do is get the motor actually RUNNING!

In order to do so, we have to send pulses to the STP pin on the chip. At every rising edge of the pulse, the indexer increments by one address location. So, we just have to make sure that we provide a pulse train for desired amount of time to cover the required angle or whatever you have to do. We can do that in the void loop()

My application required me to cover a sweep of 90 degrees and return back. My motor was connected to a gear mechanism, so 90 degree sweep required about 10275 * 90 steps at 1/4 stepping.

I also reverse the direction of the motor once it has covered 90 degrees so it can come back to its original location.

Finally, I halt the motor and hook my process into infinite loop.

I hope you found this tutorial helpful. You can also choose to use an Arduino and use the same code for driving stepper motors. Do leave a response below so I can put more interest tutorials and articles in the future.

nuclearrambo

Salil is an electronics enthusiast working on various RF and Microwave systems. In his free time he writes on the blog, talks over ham radio or builds circuits. He has Yaesu FT2900R VHF transceiver, FT450D HF transceiver and a TYT UV8000E Handheld transceiver.

You may also like...

2 Responses

  1. roy wood says:

    I really appreciate this code. I could not find a place to start until I found this. I am able to get a motor spinning with this code but the registers don’t appear to be set correctly. The 12bits of data read back from the registers does not match 12bits written into them. I did find that the results were different when I divided the SPI clock down by 16 instead of just 2.

    • nuclearrambo says:

      Glad you found this useful. How much is the variation in the register read back? Are the bits significantly different on all the registers? You said results were different on a divide by 16. Did it perform well on 16 than 2?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.