Programming help for 18v18 shield

My first project. I’m using an Arduino R4 with the Pololu 18v18 shield, and have the demo program working fine using a single motor.

The thing is, I don’t really know the recommended way of using the setM1speed() function. If I just call it with a speed of 200 (for example), then a call to getM1fault() immediately returns true. The demo loops through setting the speed to 1, then 2, etc. until it reaches the requested speed and can do that without generating a fault.

I want to run the motor forward, then reverse, at different speeds. What’s the recommended logic to use? Empirically I’ve discovered adding a delay() after starting or stopping the motor helps, but I’m just guessing at how long the delay should be.

Secondly, when the demo program receives TRUE from getM1fault() it just goes into a while(1) loop. What’s the recommended way to programmatically recover from this error? Right now I’m just turning it off and on, which seems inelegant.

Any general directions or rules of thumb in working with this would be greatly appreciated. Although I’m a rank novice at microcontrollers, I have a pretty thorough background in programming.

Hello.

We have multiple products with “18v18 shield” in the name; could you clarify which you are using?

Could you post more details about your motor specs (e.g. a link to a product page or spec sheet)? Commanding a motor to go at full speed from rest can create a large current spike, which might be what is triggering the motor fault. Ramping up the speed, like in our example code, can smooth out the current draw and puts much less stress on the motor. So, I suspect that is what you are seeing. If your application allows for it, I recommend ramping up the speed gradually (i.e. acceleration limiting).

As far as how to handle motor fault conditions, our example is conservative as you mentioned. I generally prefer this kind of behavior since it helps avoid potential damage if something is going seriously wrong, but it ultimately depends on your application and how you want to handle it. For example, you might want to add a button that allows you to continue the program if the fault has been cleared.

Brandon

Thanks for your reply. I’m using the “Pololu Dual G2 High-Power Motor Driver 18v18 Shield for Arduino”, and a wiper motor from a junkyard Mercedes that I don’t have the specs for. It’s being driven by a 12v 5A off-the-shelf power supply.

Your idea about current spikes sounds good, and my code now ramps the speed up and down as in the demo but I still get a fault from time to time. I’ll try ramping a little more slowly. And thanks for explaining the fault, that gives me an idea of how to handle the error.

Is there any more granularity available about the motor fault, or is it just “yup, you got one”?

Thanks again for taking the time to explain this stuff to me.

On the Dual G2 High-Power Motor Driver 18v18 Shield for Arduino the detectable driver faults include short circuits on the outputs, under-voltage, and over-temperature. There is no clear indication of which one is being triggered.

Your fault might be getting triggered from under-voltage since I suspect your wiper motor will try to draw more than the 5A that your supply is rated for on startup. You might try monitoring the input voltage closely when the fault occurs (e.g. using a scope or a multimeter with a min/max feature).

Brandon

Ah, that makes sense. You’ve given me some things to try when diagnosing my next project, but since this was a Halloween project I just tried adding delay(1) to the motor start loop and that seems to have eliminated the error. The thing worked flawlessly all evening, thanks so much for your help!

2 Likes