Using the allegro a4950 as a driver

First id like to apologize for anything obvious i might be overlooking, ive little experience with brushless motors.

Im looking to use a2212 motors with simpleFOC, i understand they need current limiting to run at slow speeds. A tight budget rules out the usual recommended drivers, so I ended up looking at the allegro a4950. It can handle more than enough power for my application and has built in current limiting. 2 of them per motor, a as5600 and an stm32 sounds like it should do the trick, however this seems way too good and easy to be true. Am I missing some something?

What kv are the motors? Most a2212 I’ve seen are >1000kv, which is not good for low speed, and won’t have much torque with 3.5A limit.

You don’t really need current limiting for low speed since the motor back EMF is not very much, so you can just keep the voltage limit below what will burn. High speed is where things get dicey without current sense, because you have to apply more voltage to counteract the back EMF, but if the real back EMF is less than what’s predicted from the measured speed, the current can go much higher than expected.

As for those chips, if you have to make a custom PCB for them, then I don’t think any of us would call it “too easy to be true” :slight_smile: If I were you I’d just buy an MKS Dual FOC. Two motors for $15, higher current capability, with proper current sense rather than just an emergency shutdown if you trip the limit (though as said, you may not need it for low speed).

The motors im looking at are 930kv, however they will be run through a 1:12 mechanical reduction, so for my application will be reaching around 2k rpm max, and be run off a 12v supply, should i expect them to develop reasonable torque at those speeds? eg. comparable to a brushed dc motor at the same voltage and current, which they will be replacing.

What rules out an off the shelf board like you suggested for me is simply cost, needing control over 12 motors (for a quadruped robot) the price for the control boards alone is prohibitive.

These chips are attractive because they, at least are supposed to have, proper pwm current limiting. Which if set to 2 amps, as the common breakout board for them does, would let me simply connect a motor straight in and not worry about current or voltage control on the microcontroller side of things, just feeding pwm to the approporiate control pins, like with an ln298n, as far as I understand at least, correct me if im wrong id prefer to know before i mess up. And of course a low low price tag.

Oh, somehow I got the impression you only had two motors, but 12 is indeed worth more effort to cut cost.

I also failed to read that datasheet properly and thought it only had overcurrent protection, but the adjustable limit is much more useful since it won’t shut down if you hit it.

What is the price for the breakout board? I wasn’t able to find it. The bare chips are $0.41 on LCSC, so that would be cheap indeed with a custom PCB.

I have little experience with DC motors, so I can’t say how they’d compare. But 2A on those motors would be 2*8.3/930=0.0178Nm, which is far below what they can do, so your robot will be much heavier than necessary. Even 2204 can handle that much continuously, and 2-3x more for short times.

This is the best deal I’m aware of on 22xx motors https://www.ebay.com/itm/265124279479 but they are even higher kv, so not a good match for those drivers and your 12V supply. Are you going to be removing the stators and machining new mounts as part of your actuators, or is your project not that ambitious? Once the stator is off the mount, they do have just enough length on the wires to convert the termination from delta to wye, which gets them down to ~850kv. Although there is epoxy on the wires at the base, so it’s difficult to avoid damaging the wires and having to rewind it. It still would be overkill for 2A drivers, but less overkill than 2212 and cheaper.

If you rewind all of them you could have any kv you like and get plenty of torque from 2A, but I think it took me an hour or two to rewind one, so it would be a lot of work.

Be careful with that. These chips (unlike the L298) have a lot of protection functions, and in particular you can’t set the H-H or L-L states which you would need for BLDC driving.

Maybe if you use one chip per phase it can work, but not with 2 ICs for 3 phases…

Barely 2 dollars, at least on a aliexpress, for 2 modules on one board.

Ah, yeah that is way not enough torque, I’ll need to use a low kv motor then. From the cheap gimbal one’s ive found on aliexpress the BL3525O (or the very similar TY3816B) caught my eye, ripping off the included driver board should just yield a brushless motor with a nice low kv, though i cant say im certain i correctly analyzed its parameters.

Good catch, thanks, 3 per motor it is then.

Neither of those motors looks very good. TY3816B is very heavy at 130g, and has a crappy ceramic magnet ring. BL3525O doesn’t list weight, but looks like 2808 stator so probably ~70g, and has good magnets, but hardly any copper if the photos are accurate. Usable torque is directly proportional to copper mass (lower resistance = less heat for same torque) so once again it will have a lot of dead weight. Although with 2A limit it shouldn’t get too hot anyway, so if cost is absolutely top priority, then I’d use that one. The listed 3100RPM and 12V implies ~260kv, so torque would be 2A*8.3/260=0.064Nm.

I’d recommend sticking with the 2212 and saving up for better drivers. Legged robots really benefit from proper FOC since they naturally use short bursts of high torque interspersed with low torque when the leg is off the ground, and fast changing speed that throws off voltage-based current limiting. Plus you get better feedback of how much force you’re applying to the ground.

Well shucks then, so do i understand correctly that neither the motors nor custom drivers would be any good?

In that case what would you recommend i go with, looking for ehh around 0.16Nm of torque? Rewiring the 2212 really the best option? With the battery ive currently got i could maybe provide 40A continous spread across the 12 motors. And what for a better driver board, simply more current capacity or something else?

Hope im not asking for too much of your time.

Edit: I could also theoritically add another gearbox stage for a higher reduction if it means better options for motors or drivers.

Don’t worry, I enjoy writing on forums. It’s so much more relaxing than live communication since you don’t have to hurry to respond :slight_smile:

What are your goals for the project? Will it function as a resume for a job, or just for your own interest? Are you more interested in the mechanical construction or software? If software, just learning to use brushless motors, or the whole robot coordination of many motors to perform a task? Will you be machining parts, 3D printing, or off-the-shelf gearboxes?

Personally I’d be more inclined to build a single high performance leg than a whole dog that can barely walk. But if your interest is the walking software, then that wouldn’t work. But you can’t really write good walking software anyway if the motors are too weak and/or slow to do anything more than scoot along like James Bruton’s early dogs.

Keep the gear ratio low. Backdriveability is important for walking robots. Otherwise you might as well just build a servo dog.

Closer to the second, its for a general mechatronics competition. Not strapped for time though, aiming for next year anyway.

Ive mainly 3d printed the parts for it, though ive gotten a few structural parts laser cut from plywood.

About that, Ive got most of the thing built already, expect using brushed motors and potentiometers. The problem with those is I simply wasnt able to tune my pid controller well enough for them to work, too much oscillations, especially on the last joints with little inertia. Im switching to brushless more for the accuracy and relatively simple control of an foc bldc, though the power density is definitely nice, with 2212’s shaving the weight down by 2kg, leaving it at around 1,5kg.

From how far I got into testing the brushed motors they seemed to have just barely not enough power to hold it up on 2 of the four legs, so if I could get similar power out of a bldc it should have no issue. Not gonna be doing any jumps or acrobatic either, just going from point a to b, maybe climbing a few steps.

Oh might be worth mentioning, its more of a spider layout than dog, with the legs sticking out diagonally. Probably not optimal but its there already. I can attach some photos if that helps shed some light on what the hell im doing.

edit: I could, in theory, exploit the aliexpress first time discount a few times to get 2208 80T motors well within my budget. 114KV, 39 grams, only problem is their winding resistance is 24ohms so with 12V I couldnt push anywhere near even 2A

Ah, now that changes things! Impressive work so far. This style of leg does not need to be so powerful since the first joint passively supports weight, and the other two motors are out on the leg where their weight doesn’t put much torque on the joints. But that does give the legs a lot of inertia, so you will need statically stable walking motion, and then backdriveability is not important so you can use higher gear ratio.

I think you should give it some more effort with the brushed motors before rebuilding the whole thing. Maybe add a belt reduction stage to the knee joint for more torque, with the motor flipped underneath.

What is the control loop like for the ankle motor? Are you just setting the driver to forward or reverse each update, or are you PWMing the driver inputs for smooth voltage control? You could even try voltage-based current control like SimpleFOC. The joint potentiometer should give a usable velocity reading to calculate the motor back EMF. It would be nice if you could set the input to forward or reverse and dynamically control the current via the driver’s VREF pin instead, but that would need a DAC rather than simple PWM, and most MCUs only have one or two DAC outputs so you’d need some additional circuitry to make it work.

There is a DC motor version of SimpleFOC, but it doesn’t look like it would work with those drivers as-is. They need complementary PWM on the two inputs, whereas the DCDriver2PWM class sets one input to 0 and PWMs the other.

Alright then.

I could, but that would require a full redesign of the legs, no way to mount it let alone fit it in otherwise.

And this would require a full PCB redesign, likely including changing microcontrollers since the stm32f103c6t6 Has no dac at all.

And well, none of that is anything I couldnt but, but if i’m going to be doing all that redesign and replacement anyway i think i might as well switch to the better technology of bldc? You dont get a 2kg weight saving everyday.

Also, im not gonna lie, i dont much like how it has turned out, the potentiometers especially cause a lot of trouble, bloody connections break if you look at them wrong.

I am pwming them based on the output from a pid.

Only the middle segment. I was imagining the motor in one of these two locations, turning a pulley which turns the pinion that the motor currently turns directly.

There aren’t any with 12 DAC channels that I’m aware of. I was thinking either filtering PWM outputs to produce analog voltages, or using a multi-channel DAC chip like this https://www.mouser.com/ProductDetail/ROHM-Semiconductor/BH2221FV-E2
But it would be cluttery getting it wired up to all the driver VREF pins, and I’m not sure it would be significantly better than PWMing the input pins anyway. But cramming 18 of those driver boards in there would be cluttery too. They are very elegant for brushed motors, so it would be nice if you could make it work.

Another possibility would be to use MG995 servos for the ankle joints. They only cost ~$5 and should solve the PID oscillation problem, and reduce leg mass too. Though it would involve adding a 5V power rail. And redesigning the second leg segment as well, of course.

Yeah, that’s too low kv for 12V. I had an 80T 2208 that I bought with the intention of rewinding, and just out of curiosity tried spinning it with a 3S battery on a regular ESC before tearing it up. Slow to accelerate and slow top speed. Your drivers are rated for 40V though, so you could potentially use those motors with an 8S battery for good performance. Still can’t reach the 2A limit, so it wastes the current limiting feature of the driver, but it shouldn’t burn up instantly even if you apply full voltage at 0 speed so SimpleFOC’s voltage-based current limiting should be fairly safe to use. Especially if you add some code to detect oscillation and drop the voltage limit to a guaranteed-safe level until it stops. In my experience, oscillating with bad PID tuning is what really throws off the voltage-based current limiting’s back EMF estimation.

Damn those are some pretty dang good ideas. I’ll need to do some hard thinking about if a brushless swap is really worth it over that.

I’ll need to solve the pot wiring issue to go further with the brushed motors though, the wires are first soldered onto the pots 3 leg, then strain relief is provide by ziptying them to the leg a few millimeters behind that, and then the solder joints get covered with hot glue. With all that after a little motion the connections still get quite unreliable. Might simply have to swap to wires thicker than 0.24mm2

Id at most need 4 dac channels per micro, as i have 3 of them running in parallel, each handling 4 joints. Though the dac chip is quite attractive too.

Ah why not, ive got plenty of time, ill do some playing around with the brushed motor simplefoc version. Im guessing id need custom code to run a potentiometer as a sensor with that?

Hmm, hot glue would have been my recommendation for the potentiometer wires if you hadn’t already tried it. Perhaps hot glue on the zip tie as well? The tie alone doesn’t prevent motion of the wires from reaching the solder joints, and hot glue alone might come loose, but the two together should hold the wires firmly against the solid structure so the segment between the tie and joint will hold still.

I think there are some STM32 models with 4 channels, but the 12 channel chip seems nicer to me since it would allow controlling all motors from a single MCU. You’d need to make a breakout board for it, but that’s easy enough to do by hand. Grind the bevel edge off an x-acto knife so it comes to a tiny chisel point and you can use it to carve traces. Either that or glue the body of the chip to a piece of wood or plastic and solder fine wires directly to the pins, and then glue the wires down as well for strain relief.

It sounds like your current code does pretty much the same thing, so probably not worth the trouble of getting it to work. But if you want to give it a shot, then I think the only custom code you’ll need is a potentiometer sensor class that calls analogRead in getSensorAngle and scales the value to radians (the STM32 implementation of analogRead is insanely slow, but one call per frame won’t kill you), and a driver class where setPwm sets the driver inputs according to the voltage sign and DAC output according to magnitude (though in this case the value would actually be in amps, not volts, which makes everything a little confusing).

Or if you’re sticking with PWMing the driver inputs, then probably the easiest way to go about it would be to use the BLDCDriver6PWM class. Implementing a complementary 2PWM would involve fiddling around in the hardware-specific code, which is the dark underbelly of SimpleFOC :slight_smile: I think you could use one 6PWM to control 3 motors, but it would involve a bit of hackery to get where you can call setPwm with the 3 motors’ voltages rather than having them individually call setPwm from within setPhaseVoltage. Perhaps have them talk to a dummy driver class that doesn’t do anything. The voltage.q that they pass to setPwm is cached in the base FOCMotor class, so you can still access it after they all finish their update. So the loop would look something like this:

for(int i = 0; i < 3; i++)
  motor[i].move();

driver.setPwm(motor[0].voltage.q, motor[1].voltage.q, motor[2].voltage.q);

EDIT: Thanks, by the way! This is one of the reasons I enjoy forums. If not for hearing about and thinking about your wire breakage problem, I would have continued on my path to suffering the same fate. The 3D model of my robot had features to guide the wires along, but nothing that would firmly clamp them in place, so I’m sure my solder joints would have fatigued as well. Much easier to design in screw holes and structure for wire clips now before machining the parts than trying to shoehorn them in later. Hot glue might have been enough to save me, but motor wires may get hot enough to melt it.

Glad it helped you too!

Ill be designing and testing the additional belted reduction over this week, ill post the results once im done.