# Any Digital Designers Here?



## wrmiller (Dec 31, 2013)

Want to manually control a stepper motor on a single axis. In this case the Z-axis. Similar to the controls on my friend's CNC machines.

Rotary encoder/Hall Effect on a large dial for manual input of up/down. Dial turned CW direction would be up, CCW would be down. Faster the dial is turned the faster the motor turns.

Three position switch for selecting tenths, hundredths, or thousandths. No readout needed as I have a DRO for the machine already. Maybe this station could be the input/output for a stepper motor driver? Then I'd just need the power supply and a motor.

Once an initial design is done, I'd layout the circuit on a proto board and do the testing. Once the testing is done and everything works. I'd need a final schematic, a pcb file that I could send out to a small quantity board house, and a parts list (BOM). Preferably through hole on the circuit board/components as my eyes and fine motor control are no longer good enough to solder surface mount components. 

I don't have the hardware skills anymore to do this so I though I'd inquire here. Not expecting it to be free.

I'll ask some of the hardware guys at work next week to see if anyone is interested, but I thought I'd ask here first.

Bill


----------



## bhowden (Dec 31, 2013)

I am not that interested in extra work but this does sound useful.  The HW / code is trivial.  You can get an arduino that would do the trick for about $20.  You would need a stepper, a driver like a Gecko, and the power supply for the stepper.  I would suggest buying the driver already assembled as you will probably let the smoke out of quite a few parts building your own and it won't be any cheaper.  A couple of years ago I built an AVR (the chip used in the arduino) based tachometer that uses a rotary encoder to set the diameter of the stock being turned.  Pressing the encoder shaft toggled between mode (SFM, RPM, DIA), holding the shaft down while powering up put you in setup mode to set the number of pulses per revolution.  The code for that plus driving the 4 digit 7-segment display was around 100 lines of code so what you want would be pretty simple.  I am in the process of adding a stepper to my z-axis and I just received a couple of arduinos yesterday so I might give your idea a try.  I work very slowly (way too many projects and too many forums like this to waste time on!).  My guess is that you will have a solution long before I start but if not, you are welcome to any code I come up with.

Brian


----------



## David Kirtley (Dec 31, 2013)

I was playing with this the other day at work.  All I did was to use a rotary encoder and have each pulse move a number of steps. I don't know about making the speed of the encoder set the amount of acceleration. You want to run the encoder off of an interrupt and you don't necessarily know the speed as the timing for the interrupt occurs outside the program flow (kinda). If you don't do it interrupt driven, you have to really be careful of the timing as the clock speed of the chip will be more of a limitation (assuming you are using the Arduino IDE/Language.)

The three positions for number of steps per pulse is a much easier solution than the speed of the pulse train as you can easily lose pulses. It sounds like you would lose pulses more than you really do as the steps are so small. When I get back to work, I can post what I had working the other day (it's on my computer at work.)

Depending on how much power you are trying to run, the little Pololu stepper drivers or the EasySteppers from sparkfun can run a fairly decent stepper. Adafruit has a motor controller board that can do several things:  http://www.adafruit.com/products/1438 You can also run it off one of the L298 drivers that they already have shields for (Never personally used but lots of people use them) and not have to do any board development at all. They run a couple amps and can do a pretty good sized stepper.

I was going to pick up one of the nicer rotary encoders that sparkfun sells https://www.sparkfun.com/products/10790 that runs 200 pulse per revolution and is a bit more robust than the little one I was using.

http://bildr.org/2012/08/rotary-encoder-arduino/  has the easiest example (and worked the best from the ones I played with) I also liked it that it didn't need as much circuit as this one: http://www.hobbytronics.co.uk/arduino-tutorial6-rotary-encoder

The one on arduino.cc http://playground.arduino.cc/Main/RotaryEncoders didn't seem to work as smoothly.


----------



## pestilence (Dec 31, 2013)

Programmer here.  Can't you just store the time of the last interrupt and calculate the interval when the new interrupt happens?


----------



## David Kirtley (Dec 31, 2013)

pestilence said:


> Programmer here.  Can't you just store the time of the last interrupt and calculate the interval when the new interrupt happens?



Kinda. The problem is that when you start doing a lot of stuff in the interrupt handler and then you hit another interrupt during the handler. There is no buffer (nor would you want one.) You are going to lose stuff either way. Better just to make the handler as quick as possible and get out.

Edit:

The key point is that the code that the Arduino stuff generates is kind of unknown and not much clock speed. You can calculate the number of cycles per operation and see if you have enough time if you were doing it in assembly. I can't say what code is getting generated by the compiler. You could profile it and see how long it takes within a range of timing values but you cannot be really sure. Start having other things happen like another interrupt for some switches and stuff like that and you can get into an unknown state.

Realtime programming with interrupts can be a bit funky.


----------



## pestilence (Dec 31, 2013)

Excellent points.  I've never done any real time stuff.  

This thread is making me salivate.  I've had the urge to get a stepper for my G0704 as a first step toward slowly converting it to CNC by building autofeed and jog into each axis, starting with the X.  This kind of a thing is exactly what I was looking for.


----------



## David Kirtley (Dec 31, 2013)

When I was playing with it, the action on the stepper was really smooth. One of the earlier times I was doing it but it wasn't that great because the rotary encoder kept slipping out of the breadboard:

[video=youtube_share;igsxmkRfz5A]http://youtu.be/igsxmkRfz5A[/video]

It would be really simple to add to it to make a power feed as well.


----------



## pestilence (Dec 31, 2013)

That's it. I'm doing it.


----------



## David Kirtley (Dec 31, 2013)

It was mixed up with some other links before:  http://bildr.org/2012/08/rotary-encoder-arduino/

This one works best.  The one in the video was not interrupt driven and had a bunch of other resistors instead of using the internal pull up resistors on the arduino.  Much simpler circuit, smoother action and lowered part count in the link from bildr.org.

The encoder was a 24 pulse that actually works pretty well but I am going to do it next time with a better encoder that has a bit better resolution. I think the really high resolution would be a problem (They have them up to 1000 pulse and beyond) The 200 pulse per rev is the same as most of the steppers so one revolution of the encoder should come out close to one rev of the stepper without microstepping. Just add a multiplier for the steps to get different rates.


----------



## wrmiller (Dec 31, 2013)

I was thinking that the change in encoder rate (number of pulses/sec) is reflected in the number of pulses to the controller/motor. A 1:1 ratio if you will.

Faster encoder pulses directly causes faster step pulses (forgive me, I don't know stepper control. I do RTOS and SCSI code, not the servo on disk drives.). This isn't an accel/decel profile, it's just a pulse train, or so I think. What am I missing?

Isn't this where a ladder logic (?) or something can sample the encoder pulses as a function of time and simply drive a chip to output the same frequency to the controller? Sample period could be in the 10s of microseconds or even mili-seconds and still be sufficient for this.

When setting up my friends CNC for a Z-reference I would select the Z-axis, tenths, and rotate the dial until close to the workpiece, then switch to hundredths and get closer, then thousandths to a shim I had between the end mill and the workpiece. When I touched the shim, I removed it, added the thickness of the shim to the z location and called that zero. This is what I want to do with my z axis on my PM25.  

I figured this could all be done in logic without any firmware?

EDIT: I don't know the size of stepper I'd need for my 25 (G0704 with blue paint), probably a 32 at least?

Bill


----------



## David Kirtley (Dec 31, 2013)

You are going to be working like:

Get a couple pulses from the encoder (you need at least two to get a direction)
Move x number of steps (variable to the movement resolution) and possibly check limit switches between steps
Wait for more pulses to handle.

The number of steps you are servicing with the pulse is the tunable parameter. As an example, you can put it in inchworm mode and have to turn 10 full revolutions to get a step or in hyper-drive and move thousands of steps per pulse.

You need to allow yourself time to see and react to the movement. You are the control loop.  If you lose pulses on the encoder, no biggie. In fact, you might want to wait a few pulses before moving just as a debounce. 

The only acceleration was about the original idea of linking the speed of the encoder to the rate of movement. In this case, I think that would be problematic and require much more overhead.


----------



## DAN_IN_MN (Dec 31, 2013)

I'd like to make a stepper controlled indexer.  No hole counting.  How would this be done?  I'm thinking the control would be similar to this one you guys are talking about.


----------



## David Kirtley (Jan 1, 2014)

It would be the same. All you need to know is how many steps for a full 360 degrees.  With some gear reduction, you could be able to do a huge number of divisions.


----------



## DMS (Jan 1, 2014)

wrmiller19 said:


> ....
> 
> Isn't this where a ladder logic (?) or something can sample the encoder pulses as a function of time and simply drive a chip to output the same frequency to the controller? Sample period could be in the 10s of microseconds or even mili-seconds and still be sufficient for this.
> 
> ...



The trick is reading the encoder as a quadrature signal (assuming you want directionality). You could probably rig something up up using discrete logic, or using a CPLD. Honestly, if you are only making one or two, then the cheapest/fastest/easiest way is to get an arduino ($20), a small incremental encoder ($50), and an off the shelf stepper driver such as this [link]http://www.geckodrive.com/geckodrive-step-motor-drives/g250x.html[/link]. The pulse rate on the encoder should be slow enough to read, even in the mainline (no ISRs) (unless you have a really high count encoder, or you can move your arms _real_ fast.

The nice thing about the arduino is that it is flexible, and you can tweak things you want. If you want to leave it simple, they would be cheaper than spinning your own board. You would even be hard pressed to hand solder something on a proto board for what you can get one for.


----------



## wrmiller (Jan 5, 2014)

It is not a drop in fit, but I think I found something that might be made to work: A CNC pendant. Found some for sale online.

Now I think I would just need some logic that takes the pendant pulses and translates that to what the driver needs to step .1, .01, or .001 for each 'step' of the wheel on the pendant. I think a fwd/rev switch might be simpler to implement than trying to determine direction from the pendant wheel. Or not, I really haven't done any digital circuit design in decades so I'm just guessing here.

I have a STM32F4 Discovery board that I have a little RTOS and 4 tasks running on and a full Crossworks development IDE on my Mac if I want to do an event/interrupt driven implementation C, but I'm not interested in taking on a coding project. Did way too much of this at work, for way too many years.  

I'll have to borrow a friend's scope to determine the outputs and signal levels that come out of a pendant.

Bill


----------



## pestilence (Jan 5, 2014)

My arduino kit and rotary encoders have already arrived and my stepper, driver, and power supply should be here this week.


----------



## SEK_22Hornet (Jan 5, 2014)

If you prefer the PIC processor and using Basic, check out the processor boards at www.futurlec.com.  All kinds of micro building blocks including PIC, ARM and others.  Good prices - they are off shore, so delivery is a little slow sometimes.  Also I bough a Basic pic compiler for Mikroelectronica (www.mikroe.com - one US distributor is MMouser electronics).  I had played with programming PICs in their assembler and got nowhere, but the Basic compiler had tons of little routines already written that you can just drop in and go to build a program. It can be used free with limited number of lines of code.  As for the project, I've had a couple thoughts.  Using a stepper and translating the pulse count into Stepper pulses sounds great, but I am concered that someone may be looking for an analog feel that just won't be there. If you set the processor to move .100 for 1 pulse of the encoder, it will move that distance at whatever speed the processor generates the pulse train.  No way for the processor to determine a speed from one pulse input, so you may have to accept the fact that the output will never be smooth - it will always be "jerky" when translating the number of pulses.  A one pulse = one step would be smoothest possible mode. Add to that the fact that you have some serious lag time - say you have it set for .01 per step and you turn the encoder 10 steps, depending on the speed the processor is programmed to turn the stepper it may end up over shooting where you want to go, unless you count the clicks or add a display to tell you where it is "going". Maybe a more user friendly device would be a power feed with adjustable speed and settable stops. Add a LCD display and keypad that would allow you to preset speed, direction, start and stop. You could even set it up to reverse direction at the end of the programmed travel, or control both x and y and have a teachable or programmable x-y table on a mill. I think I would use an external stepper drive with step and direction input, just like you would use with a Mach3 setup.  Then it could be adapted to any size machine, small or large. Again, these are just my thoughts. The idea certainly has potential - especially if you think about controlling both X and Y together - programmable arcs anyone? Backlash correction? Angles?


----------



## SEK_22Hornet (Jan 5, 2014)

Well, for the simplest possible way to use an encoder to drive stepper motor, here it is.  Check this webpage out - pretty simple! Same thing could be done using simple logic and power mosfets to drive higher current motors. The ULN2003 is essentially a darlington transistor array (7 inverting 1 amp open collector drivers).


http://www.instructables.com/id/Simple-manual-control-of-stepper-motors-without-a-/

I don't think it is that practical for this application, but interesting none the less.


----------



## richl (Jan 5, 2014)

https://www.google.com/search?q=ope...ms-tmobile-us&sourceid=chrome-mobile&ie=UTF-8
This is a Google search for opensource arduino CNC controller. Seems to be a fair bit of material out their already. Even some shields for  arduino for controlling 3 stepper motors seems like that might be a good source for a project like this.
Hath
Rich


----------



## wrmiller (Jan 5, 2014)

I was thinking of using this for positioning the Z-axis only, not trying to translate X or Y while cutting, so jerkiness in the .1 or .01 step function is a don't care. For me.  

Bill


----------



## CNC Dude (Jan 5, 2014)

Hi group, I am a stepper motor driver designer. Have been doing both hardware, firmware and software design on this topic for the past 14 years. You can check some of my personal endeavors (designs) at www.avayanelectronics.com and some of my tutorials on www.ebldc.com. The tutorials are mostly intended for people interested in learning about the actual stepper control and driving, so if all you want is to drive an axis, they may be overkill. Saying this just in case.

If the group needs an actual hardware design which could be purchased in some kind of a short run, I could help with this effort. I have access to a very decent PCB design software tool and this has been one of my tasks for quite a while now. We could order bare board from a trillion different places and they are usually not that expensive. Assembling them would be a completely different endeavor...

Will be glad to help with this project!


----------

