Tachometer for spindle

This topic contains 25 replies, has 4 voices, and was last updated by Profile photo of karltinsly karltinsly 1 month, 1 week ago.

Viewing 26 posts - 1 through 26 (of 26 total)
  • Author
    Posts
  • #24313
    Profile photo of karltinsly
    karltinsly
    Participant

    I just got a 500W spindle and am working on getting it set up on my MPCNC. I’m also in the middle of upgrading all the parts on the MPCNC, which is an early model, so I still have a way to go before I’m actually cutting with it.

    Anyway, I’m thinking about building an arduino-based tachometer for the spindle, but wanted to check and see if anyone has done it already, or is aware if someone else has done it already.

    I plan to use some kind of optical sensor mounted to body of the spindle, pointing at the cooling fan at the top of the spindle. I’ll put a piece of reflective tape on the cooling fan, and have the arduino calculate the rpms from that. I’ll use a 2004 lcd to display the rpms. The spindle can turn up to 12000 rpm, so I hope that this setup can handle that.

    I’ve done a few projects with arduinos, but I’m still pretty new to them, so if you’re knowledgeable about them and have some ideas about how to approach this, please share your thoughts about this project.

    I have also seen handheld optical tachometers on amazon for around $15. If one of those would work with this spindle, it would be easier than building my own. Not nearly as cool, but easier. If anyone has experience using one of these, please let me know.

    #24317
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    12000 rpm is 200 Hz, which is 5ms/measurement. That should be fine on a dedicated arduino. You will want to make sure the sensor goes between low and high on the input pin, and either use the pulse in (might not be the right name) or an interrupt handler to measure it. The other thing working for you is that you don’t need to measure every pulse, just measure the time for one pulse, ten times or so, and then average them out. Then you can stop measuring, and go handle your LCD. The big advantage of an arduino (other than it’s cool, and you’ll learn a lot) is that you can then go the next step and control the speed of the spindle with closed loop feedback.

    That being said, the tachometers on amazon will probably work fine, just putting some reflective tape on the chuck.

    #24318
    Profile photo of vicious1
    vicious1
    Keymaster

    Speed alone doesn’t get you much, anytime the bit makes contact the rpm’s will vary greatly. What you are looking for is a RPM PID controller. That way if you set 1000 rpms, it will do it’s best to vary the power to keep 1000 no matter what.

    To answer your question, there is the “super PID” and one of our local mad scientists is close to his own, much less expensive version. Details on that to come.

    #24322
    Profile photo of karltinsly
    karltinsly
    Participant

    Good point about not needing to count every pulse, Jeffeb3! That will help. Instead of timing a certain number of pulses, could I just count the number of pulses in a specific amount of time, say 10 seconds, and calculate from that? Or is the way you suggest more accurate? Thanks for your input!

    Ryan, that’s also a good point about the RPM being different under load. The PID thing sounds cool! Maybe I should just get the $15 tach and wait for the PID controller to be developed and build that instead. I won’t learn as much, but it seems like a great solution.

    #24327
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    You could do it without interrupts, if that’s what you’re asking. Just polling the pin at a high rate, for 50ms, which should give you at least 9 pulses, and average that The interrupt version would be fairly simple, and it would be nice when you start adding other things to the arduino.

    #24654
    Profile photo of karltinsly
    karltinsly
    Participant

    So after reading Ryan’s post about someone working on a PID speed control for the spindle, I decided to research it myself. I glued a piece of a gift card to the spindle (the “fan” part at the top of the spindle, actually), and mounted an opto endstop so that the gift card “flag” passed through it. I’m getting an accurate rpm reading, as checked with a handheld optical tachometer. I started with a sketch that incorporates the PID library, and I’m ready to try using the PID part of the sketch to control the spindle speed.

    Which brings me to my question: has anyone actually done this? Hooked up an arduino to the PWM input on the power supply (meant for Mach3 control, I think)? Can I hook the arduino directly to the power supply? Do I need another piece, maybe a mosfet or something that can handle a higher current?

    Any advice, or even a link to info about this, would be appreciated.

    Here’s a pic of the tach sensor:
     photo 2017-01-10 20.04.13.jpg

    #24657
    Profile photo of karltinsly
    karltinsly
    Participant

    Here are a couple of other pics, one of my breadboard for the project, and another of the spindle with the tach sensor mounted on it. I originally tried using a mini IR sensor (usually used for bed leveling) for the tach, but it didn’t work right. The opto endstop is hot glued to mount I originally designed for the mini IR.
     photo 2017-01-10 20.24.39.jpg
     photo 2017-01-10 20.24.30.jpg

    #24673
    Profile photo of Leo69
    Leo69
    Participant

    @karl . You’ll need a triac to drive the load. The triac circuit will be high voltage across so it should be optoisolated from the Arduino circuit for safety reasons. A zero Cross detection circuit is also needed to find the exact point in the AC sine waveform where the triac switching should start. The zero Cross detection circuit should also be isolated for safety. Your Arduino will need to read rpm, handle PID loop, and apply phase control to the outgoing AC through the zero cross and triac input/output. Most of this needs to happen at high speed and precise timing so you’ll want to use the Arduino timers and interrupts to manage the zero cross and RPM input.

    #24674
    Profile photo of Leo69
    Leo69
    Participant

    Actually, what I just posted is more applicable to a router. What power supply does your little spindle run on?

    #24675
    Profile photo of Leo69
    Leo69
    Participant

    If your spindle power supply already accepts pwm input then you’re almost there. Post your sketch when you get a chance . There are a few coders on the forum now so I’m sure you’ll get some help.

    #24677
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    Do you have a data sheet for your power supply? The details of that pwm in are going to determine what kind of solution you need. It would be smart engineering to read the docs first.

    Most likely it’s just going to be a high impedance input, looking for a pwm input at 5V. Otherwise, it might be a pulse input, like an RC controller, but it still wouldn’t hurt it to have it connected, it just wouldn’t work. Still possible, but also unlikely is that it’s a 3.3V input, which you could damage with a 5V Arduino (you could use a voltage divider in that case). If it was something strange like a 12V input, you would need a transistor to get the Arduino output voltage higher. Still not a big MOSFET though. I would be pretty surprised if that needed much current at all, so a higher current circuit shouldn’t be necessary.

    The Triac stuff Leo was talking about is more for controlling 120VAC.

    #24683
    Profile photo of Leo69
    Leo69
    Participant

    Most of these Chinese spindles are made to work with Mach3 control which would be 5v pwm from a PC parallel port or USB motion controller. Karl mentioned something about Mach3. Should be Arduino friendly but it’s a good idea to make sure and avoid the magic smoke:)

    #24685
    Profile photo of karltinsly
    karltinsly
    Participant

    Thanks for the replies (good to hear from you, Leo!).

    The power supply came with this bundle: https://www.amazon.com/gp/product/B01LNBOCDA/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1. It is a chinese power supply and has inputs that are supposed to be for Mach3 control. I might just make a sketch to output different duty cycles to those terminals and see what it does.

    There weren’t any docs with the power supply. There is no non-chinese printing on it other than 110VAC and + or -, so there’s no model number to google. I’m guessing that 5v PWM at the Mach3 ports is what it’s looking for, though I have seen references on some CNC forums to jumpers in the power supply that might need to be set to enable PWM (not necessarily talking about this specific power supply, though).

    Anyway, that’s why I’m asking if anyone has any experience with this specific spindle and power supply. They are very common and cheap, so I thought someone might. I’ll post my code later if I get it working or need help with it. Currently it’s just a work in progress.

    Thanks again!

    #24690
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    Interesting. Their wiring diagram doesn’t match the pictures. One input is labeled “0-10vdc signal”, and the other is a potentiometer. If you measure the voltage across the red and black wires of the potentiometer, and that’s 5V, and you have a 5V arduino, then you should be able to put the arduino 5V PWM on the yellow connector. If you need to output a 10VDC PWM signal, one transistor would do it. It’s also possible the 10VDC would work with a 5V (even to 100%), and it’s just tolerant to 10V.

    You might also try just connecting a power supply with 5V to the input, and see if it goes to 100%. You could also measure the current that way, although I would be very surprised it if was anything significant. This definitely looks like a high impedance input.

    #24694
    Profile photo of Leo69
    Leo69
    Participant

    A Chinese product that doesn’t match the diagrams?! What a shocker ?

    #24706
    Profile photo of karltinsly
    karltinsly
    Participant

    Yes, mine matches the hand-drawn picture on the amazon item, with the Mach3 pins labeled 0-10vdc. I can’t remember if my terminals have that marked on them, but they are there. I will see what happens when I put a 5v PWM signal on them.

    #24732
    Profile photo of Leo69
    Leo69
    Participant

    Good to see you back Karl ? I know you used to run a DeWalt dw660. How would you say your current spindle compares as far as noise, power, speed, and quality of cut?

    #24758
    Profile photo of karltinsly
    karltinsly
    Participant

    Hi Leo! I can’t give an opinion yet. I printed the new middle and roller parts for my machine over the holidays. While I had it apart, I decided to get the spindle. I haven’t put the machine back together yet – waiting to get the PID speed control done. The only thing I can say so far is I’m sure it will be quieter! I might keep the 660 handy for things like dressing the waste board, since it will easily turn my 3/4 inch end mill, but I have high hopes for doing more precision stuff with different materials.

    I’m also designing a gantry-mounted dust shoe. I saw a video of one on a shapoko or x-carve and it definitely looks like the way to go. No deflection of the cutting head by the shoe or vacuum hose.

    Back to the subject of this thread: I hooked up a PWM output to the Mach3 input on the power supply this evening. The arduino PWM output is definitely controlling the speed of the spindle. Nothing is tuned and I don’t know what the range of control is yet, but it was controlling it for sure.

    I found this video on youtube: https://www.youtube.com/watch?v=kYFNUQgE26E&t=0s. I’ve ordered the same leonardo board and button lcd shield that he used, as well as the same kind of reflective IR sensor he used. I’ve downloaded his code and hope to use it with maybe only a little modification. This should simplify things for me. I do love figuring out how to do things myself, but it can be tedious and frustrating. If someone’s already figured it out, and I can adapt it, I’m fine with that too.

    #24765
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    Awesome!

    Did you try looking at the voltage at the motor connector when you had it on before, and when you had it at 100% with the arduino? I would think that it would be at 100V at max. But I haven’t ever owned one of these.

    I’m excited to see how this spindle works for you. I like the high-tech feel of it if that makes any sense. Seems neat to have a PID controller, and it also seems neat to have it electronically controlled. Just getting a digital on/off switch for the DW660 was quite a thrill.

    #24800
    Profile photo of karltinsly
    karltinsly
    Participant

    I didn’t measure the voltage, I’ll try later. All I was able to ascertain was that the input affected the speed, but I need to play with it a lot more before I understand how to set it up properly so that it actually holds the speed steady. In my brief test, I had a display set up to show me the PWM output, and it was either 0 or 255. The spindle was either slowing down or speeding up at full speed. I think that once it’s properly tuned, there will be some more nuance in the PWM output.

    I too like the high-tech feel of it. I originally got the spindle just to have something quieter than the screaming 660. But there are many discussion about bits and speeds here and on every other CNC forum, and it seemed to me that without being able to actually measure and control the speed of the bit, knowing what the speed should be for a given bit and material is a moot point.

    #24878
    Profile photo of karltinsly
    karltinsly
    Participant

    Okay, this evening I made a small sketch that set the duty cycle to 64, 128, 192, 255, and back down, for a few seconds each point. The power supply has three terminals connected to a potentiometer, and two terminals for PWM. Here are some of the things I observed:

    With the pot turned to zero, the PWM signals did nothing.

    With the pot turned up anywhere from just barely turning, or almost ready to turn, the PWM settings caused it to start, and run faster at each level. Unless the pot was turned up pretty high, the PWM signals would not get it turning beyond about 8000 rpm, and if turned up high enough, the higher PWM signals actually made it slow down.

    If the spindle is turning fast enough, it generates power that feeds back through the LCD, which gets darker (more pixels turning dark) until it’s unreadable, just solid blocks. If the power is off on the arduino, and I run the spindle up with the pot, it will also start to light up the LCD – I have not pushed it to full power like this.

    With the pot disconnected, and only the PWM wires connected, nothing happens at 64, it turns at 1100 rpm at 128, 2400 at 192, and 4400 at 255. It won’t go any faster than that.

    The voltage output to the motor varies over a range of maybe +/- 10vdc as the PWM cycles, centered around whatever voltage the rheostat is set to. I didn’t measure the output when I had the pot disconnected.

    Anyway, that’s just some observations. I’m not sure what to make of them yet. I post them here in case someone can decipher the behavior and give me an idea of how to get it all working.

    #24899
    Profile photo of Jeffeb3
    Jeffeb3
    Participant

    If the spindle is turning fast enough, it generates power that feeds back through the LCD, which gets darker (more pixels turning dark) until it’s unreadable, just solid blocks. If the power is off on the arduino, and I run the spindle up with the pot, it will also start to light up the LCD – I have not pushed it to full power like this.

    Uh… That’s not great. What power supply are you using? Do you have the arduino on a separate power supply? If the only connection between the motor and the arduino is the PWM, and the wall A/C, then I think you probably need to isolate the PWM signal.

    With the pot turned up anywhere from just barely turning, or almost ready to turn, the PWM settings caused it to start, and run faster at each level. Unless the pot was turned up pretty high, the PWM signals would not get it turning beyond about 8000 rpm, and if turned up high enough, the higher PWM signals actually made it slow down.

    It could be a bad pot. I would measure it with a multimeter. Maybe the resistance is actually going up at that end of the range. If you just connect the red pot wire to the yellow PWM, does it go full speed? When you get your PID in there, if this potentiometer is affecting it, your control loop will be trying to compensate, which, with an integrator, can cause some goofy issues, so hopefully you can just disconnect it, or just jumper it to ground or whatever that red is (5V, 10V?) and then ignore it.

    The voltage output to the motor varies over a range of maybe +/- 10vdc as the PWM cycles, centered around whatever voltage the rheostat is set to. I didn’t measure the output when I had the pot disconnected.

    So when the output voltage is about 50V, you are seeing +-10V oscillating? But that was only with the PWM connected. About what frequency was it changing? Every few seconds? I like to blame the pot for this too, because it might be varying a little bit… Otherwise, it might not be something to worry about, because the PID loop should be able to clean this up a bit, although the less work it has to do the better… I’m assuming it’s not coincident with the frequency of the PWM, so if your PWM was 500Hz, you aren’t seeing +-10V at 500Hz.

    This is cool. I wish I was there with you testing it out.

    #24929
    Profile photo of karltinsly
    karltinsly
    Participant

    When I said that the voltage varies, I meant that it varies as the PWM duty cycle changes. However, I just did some more testing, and here’s an example of the voltages. I started at a level that had the spindle already spinning, so there’s a voltage even at 0 PWM.

    PWM VDC
    0 22
    64 59
    128 69
    192 79
    255 94

    Interestingly, while I had this running, I unplugged the usb cable from the arduino. I expected the spindle, which was still running, to settle on a single speed, but it continued to cycle, so I realized that the EMF I had observed before must actually be powering the arduino. I then unplugged the motor from the power supply, and the arduino continued to run! Now, there is a huge capacitor in the power supply, so maybe that’s what kept it running, but it seemed weird. Also, as the program continued running, the amount of power feeding into the arduino varied at each PWM point (judging by the brightness of the LCD).

    Anyway, I don’t like the EMF feedback (or whatever it is), so I’ve ordered a PWM controller like this: https://www.amazon.com/gp/product/B00HUQY9HC/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1. This is the same type that jmhrvy1947 used in his project, so I’m hoping I’m set up to just use his solution with little modification. That controller should be here tomorrow, so we should know this weekend.

    #24972
    Profile photo of karltinsly
    karltinsly
    Participant

    Okay, I got it all hooked up and it works great! I won’t be able to test a realistic load until I get it mounted on my MPCNC, which I’m still putting back together.

    Those of you who are experienced coders can probably do all this with any combination of controller and sensor you have at hand, but if you want to put this setup together, here’s what you need:
    Spindle and power supply – $135
    Arduino Leonardo – $11
    LCD Keypad shield – $11
    IR Sensor – $7
    PWM Controller – $17

    You can see a video of the setup here:
    https://youtu.be/-4Qgf7hl_Ic

    #24975
    Profile photo of vicious1
    vicious1
    Keymaster

    Dude! Nice. Can’t wait to see how it handles load changes. That can/should make a very noticeable effect on your future cuts.

    Is that noise some sort of alarm or something, is there a peizo on there anywhere?

    #24991
    Profile photo of karltinsly
    karltinsly
    Participant

    Thanks, Ryan. I am looking forward to actually trying it out!

    I’m not sure where that whine is coming from. There’s no piezo I can find anywhere. It’s hard to isolate, but I’m pretty sure it’s coming from the PWM controller. I will continue trying to eliminate or mitigate it. It is not as loud as it might seem in the video. I certainly expect it to be drowned out by the sound of the bit cutting material, or maybe even just the machine moving.

Viewing 26 posts - 1 through 26 (of 26 total)

You must be logged in to reply to this topic.