Comment on Current limiting
litchralee@sh.itjust.works 1 week ago
I don’t think there’s a good way to adapt this circuit to provide current limiting on the 18v rail. Supposing that it was possible, what behavior do you want to happen when reaching the current limit? Should the motor reduce its output torque when at the limit? Should the 18v rail completely shut down? Should the microcontroller be notified of the current limit so that software can deal with it? Would a simple fuse be sufficient?
All of these are possible options, but with various tradeoffs. But depending on your application, I would think the easiest design is to build sufficient capacity on the 18v rail so that the motor and 5v converter inherently never draw more current than can be provided.
boojumliussnark@lemmy.world 1 week ago
Thanks for taking time to look at this! :)
The issue is that if something is blocking the motor, or the limit sensor is not working, the motor should stop before burning itself out or breaking stuff.
I did buy a hall effect current sensor (www.aliexpress.com/item/1005006222090940.html) that I was thinking of connecting to the pi pico on an interrupt enabled pin, so I could cut off the engine output at the source, and alert my upstream controller. But I just couldn’t wrap my head around how to implement it.
Another option that I considered was putting some kind of fuse on the 18v rail and try to figure out how to detect if the 18v rail was dead and feed that to the pico - but then I’m not really sure how much simpler (if at all) that would be.
The picos inputs are 3.3v btw.
litchralee@sh.itjust.works 1 week ago
In that case, I would suggest looking at a different motor driver. The driver you’ve specified doesn’t seem to have any provisions to detect a motor stall, which is something that other drivers can potentially do. Ideally, the driver would detect the back EMF from the stall and inform the microcontroller, which would then decide to stop movement.
An external current sensor might work, but that’s adding to the part count and might not be as capable as built-in functionality within the motor driver. Plus, fancier motor drivers have some neat features that you could take advantage of as well. I think it would be more prudent to consider a different driver before adding additional parts.
cmnybo@discuss.tchncs.de 1 week ago
The L298 has two sense pins. Connect a current shunt between each sense pin and ground and you can measure the motor current. Use an op amp to amplify it and measure it with the ADC in the microcontroller. The microcontroller can stop the motor if the current gets too high.
litchralee@sh.itjust.works 1 week ago
Ah, I entirely missed the sense pin when skimming the datasheet.
That said, using a shunt for an inductive load like a motor may have to contend with the corresponding spikes caused when switching the motor. This just means the thing doing the sensing needs to tolerate the spikes. Or mitigate them, with either a snubber or a flyback diode (is this actually doable with an H bridge?).
As for the op-amp and ADC, if we already accept the additional of the op-amp part, it is also feasible to use a comparator with a reference voltage set for the max safe current. The digital output of the comparator can then be fed directly to the microcontroller, providing fast reaction without the sampling time of an ADC. But this would be so quick that the spikes from earlier could get picked up, unless mitigated.
Still, these solutions are adding to the part count. If that’s a concern, then I’d look for a motor driver with this functionality built in.
boojumliussnark@lemmy.world 1 week ago
That sounds very cool - and way beyond my own understanding :-)
Is this something you could actually help with sketching out for me?
I found the datasheet for the L298 and I can see that for my use (I am using just out 1 and out 2) it should be pin 1 (Sense A) that should be relevant, right?
This looks like it is connected to gnd on the driver board (I can easily cut this connection).
Unfortunately I don’t understand what a current shunt is? :-)
It has me slightly worried that it says that pin 1 can go to -1v which I think would break the ADC input?
As far as I can tell the ADC input on the PICO accepts from 0 - 3.3v right?
Thanks a bunch for looking at this!
boojumliussnark@lemmy.world 1 week ago
Ah… Since I am not a smart man, I have already invested too much (for the project) in several of these motor drivers. :-(
litchralee@sh.itjust.works 1 week ago
Out of curiosity, what is this project?