another noob question, Im aware this is one of many posts on motor speed control, however im looking for the simplest way to have a motor run at a fixed speed, with feedback (i need an output triggering if the speed drops to zero)
the general method ive seen on these forums uses PID. full disclosure ive very little idea about what that really means beyond headline description. i do get the impression that it involves a fair amount of tuning and fiddling to get something to work with a specific motor and encoder.
i found this page online:
which looks fairly trivial to build and seems to be robust without much tuning needed.
i wonder
a) how this differs from the method generally suggested on these forums,
b) whether its better/worse and
c) whether this method translates trivially to the Arduino nano i just bought to play with rather than buying and fiddling round with another microcontroller.
Bear in mind im a complete beginner, so if somebody is willing to help with the code i would be most appreciative. im willing to pay a modest fee for somebody’s time if necessary, this is a small part of a project thats rapidly growing in complexity and im trying to learn 50 things at once!
the motor is still to be chosen. it will be small (less than 25mm diameter) and will spin a small (1cm diameter) mirror at a fixed speed.
i need feedback for a safety mechanism, so i think a dc motor with encoder is the better option. the speed must stay within about 0.1 percent of 2400 rpm. these figures are ballpark at the moment.
The link i posted does not appear to use anything as complex as this “PID” thing looks, judging by the posts here.. is it basically the same thing or a different method entirely?
If your motor is rotating something, use that something with a sensor to tell you the speed. Since you are specifying RPM, is that how often you need to compute the rotation speed? In your software development, you need to determine how you will make adjustments to the indicated speed and how often to make the adjustments.
Remember, you also have zero RPM to contend with, plus a varying rpm as the speed ramps up. How long will that take and will that cause problems?
As a beginner you will likely find it easier learn and program using the Arduino IDE and Arduino AVR MCUs. Anything that can be done with a PIC chip can probably also be done with an AVR MCU.
Having recently run into a similar scenario where the discussion, which was regarding a specific project, diverged into an AVR vs PIC debate, and having subsequently dipped a toe into programming PICs, I can make the following observations:
tooling up for programming an AVR is cheaper then for PICs - it requires just an Arduino board of some description. PIC requires a programmer of some sort - either a PICkit5, PICkit4 (if you can get one used) or a SNAP
AVR programming with Arduino IDE is done using a C++ like language*. PIC programming is done using MPLABX and the C language. There is a lot of overlap between C++ and C, but the former is easier for the beginner to get to grips with.
MPLABX IDE is rather more complex to get to grips with than Arduino IDE
don't bother with PICkit3 as its no longer supported by MPLABX - all PICkit3 for sale nowadays are clones of the original anyway
programming PICs using assembly language (as opposed to C) is virtually obsolete - the original assembly programmer that came with MPLABX, mpasm, is no longer available, the replacement is incompatible with mpasm code examples and generally poorly regarded
I ended up purchasing a PICkit5 programmer and a handful of chips, but my purchase was not specifically for my project, but for the learning experience. I was curious enough to see, understand and compare for myself. The PICkit5 can also program other chip architectures and work as a debugger which I considered useful for my purposes.
The PIC programmer cost around £70 all in. The SNAP can be had for much less (£10ish plus VAT plus postage) but does have limitations. The cost of an Arduino clone board or an AVR chip is less than the cost if the SNAP, and even a genuine Arduino board costs far less than the PICkit5 programmer.
In this case you may not need full AVR capabilities (for example serial comms) so if you want a smaller MCU, then one other option might be to use one of the ATtiny family MCUs. The advantage is that they can be programmed using the Arduino IDE, although you might need either an FTDI UART adapter board or an Arduino board to program it, but you would need that and a breadboard and some jumper wires to program a standalone AVR chip anyway - unless its a 328P that can be dropped into a spare UNO R3 board.
Ultimately the choice is yours.
I see other are already chipping in with motor specific comments.
PIC chips are a different MCU family with a different programming method.
Note*: Arduino language is a subset of standard ISO C++ with specific methods added for hardware programming.
thanks for the detailed reply.. im looking for the most “plug and play” solution possible. as you state the PIC programming is more complex and requires a programmer, this makes me lean towards arduino. i also already have my first arduino (nano, arrived today) however if i follow the guide on that page, i have ready made code that apparently “just works” although id probably need to tweak some values depending on the encoder i use (and as noted there, to support faster rotation speeds an encoder with less “teeth” is required. thats trivial though.
i guess the ideal would be if i could translate that c code to work on the arduino and use the same circuit. however i get the impression from your post that this would not be trivial as id hoped.
I'm thinking of a 4-pin computer/laptop fan. They already have the tach sensor and speed controller included. They come in all sizes an you can remove blades if needed. Only small ones might reach 2400 RPM.
Leo..
you are probably right. i was hesitating about using a stepper since
a) it has no feedback so something must be added
b) they generally dont like going fast, 2400 rpm seems to be pushing it according to what ive read online
c )ive seen suggestions that at very high speeds, not every stepper driver can keep up, and specific ones must be used, although in that case ive no idea if 2400 rpm is considered “very high speeds” and if the arduino + standard stepper driver can handle 2400 rpm.
d) code must be added to gradually ramp up and down the speed when going fast with a stepper, you cant just set it to go fast.
all of the above gave me the impression it was NOT going to be the simplest option.
Stepper software like AccelStepper can only do about 4000steps/sec on an Uno.
2400RPM is 40RPS, so a 200 steps/rev motor needs 40 * 200 = 8000 steps/sec.
Too much for an Uno with AccelStepper.
A stepper motor will also likely make the sound of a jet plane at that speed.
What I also worry about is the balancing/centering of the mirror attachment.
Leo..
the balancing of the mirror attachment is a concern for me too, ive made a 3d model of the mirror holder and ill be 3d printing it. for now i split the model along the vertical axis through the motor shaft in my 3d software and adjusted it so the volume of material is the same on both sides. if that is not sufficient ill have to tweak it further, probably printing a few variations with small amounts of material added to either side to see which works best.
in any case i think i will investigate repurposing a 4 wire pc fan. as mentioned they have the speed controller built in, plus a tach output. however ive no idea how precise the speed controller is in those things, or if they use their own tacho output to regulate speed. i imagine 100% precise speed control is not a priority on a fan.
Once up to speed, it should run at fairly constant RPM. I'd try something simple like PWM to start with which the Arduino does very well. I would imagine that some sort of soft start would help, depending on driven load.
Initial trials wouldn't need feedback, but could be added.
“im not sure “fairly constant rpm” is going to cut it. im in a discussion on “allaboutcircuits” and one contributor to the thread suggested even a 1% variation in the rotation speed at 2400 rpm would cause the laser pattern (if not synced) to shift around the circular beam at 24rpm
for my initial tests im just using a small dc motor on a cv power supply.