10-30-2013 01:34 PM
10-30-2013 02:08 PM
Hello Automationnovice and welcome to the forums,
This sounds like an awesome project. I'm flattered that you consider this forum to be an oracle of general motion control knowledge- not just of National Instruments products. 🙂
Your encoder can be wired to digital inputs on your arduino. Both inputs can be tied to one interrupt function in your sketch. By connecting them to the interrupt you will be notified almost immediately when there is a change in their state without needing your sketch to constantly check them (called polling). By tracking the order in which the pulses change relative to each other you can determine which direction the motor is turning. By counting the pulses you can track the position of the motor. It is easy to find sketches that will show you how this is done.
When you have the current position in your sketch you will then be able to use digital outputs from the Arduino to tell your stepper driver where you would like to go. The type of driver isn't that important as long as it can output the power required by your motor. The driver spec will tell you how to interface with it. Pick the interface you like the best or better yet find one that other people are using that already has Arduino code written for it. I don't have sample code on hand at the moment but it is not hard to find. There are also Arduino shields that implement motor drives so you don't have to fiddle with the electronics.
At this point your program would have the ability to tell where it is and command the driver to take a step in a direction. Your sketch would now need a simple trajectory generator or step generator. This can be as simple as a loop: We are at 50. We want to be at 250. Output 200 steps in the positive direction to the driver. Monitor the encoder to make sure we get there properly and correct for any unexpected errors. If you need to this code can be made more sophisticated and account for desired velocities and accelerations.
On top of that code would be the logic that makes up your application. Where do you want to go and when.
I'd love to see this when you get it working.
10-30-2013 03:13 PM
NathanK,
First Thank you so much for taking the time to reply and the detailed explanation, it certainly helps me in the right direction!
Seems the interrupt based sketch is the best way to follow the encoder per say! I will Google the motor control shields for the ardunio as you suggested looks like a quicker path to success/ the way I read is a motor shield has the motor driver on it and plugs directly into the arduino board? ! The actual signal logic from the printer encoder will be driving the motor during printing I just need to intercept it thru the micro/driver for a stepper. The only other application I need is a load and eject, I was hoping to implement two limit switches on each end one for load position/stop and eject/ position stop. Press a button for load and effectively drive the motor until it reaches a limit switch to stop.. Im guessing I can control the pitch/steps in the micro like you said upon receiving a step signal from the printer effectively telling the driver to take x amount of steps based on the one input signal?
Thanks again for the detailed response I really appreciate it 🙂
Regards
10-30-2013 04:40 PM
I think your limit switch idea for the load/eject is great.
When you wrote: "The actual signal logic from the printer encoder will be driving the motor during printing I just need to intercept it thru the micro/driver for a stepper."
Do you mean that the encoder is attached to the printer's DC motor and will be running independently from your code? That your microcontroller just needs to spy on those signals so you can coordinate your stepper with the movement of the DC motor? This sounds like it should work.
10-30-2013 06:09 PM
NathanK
Reply to
When you wrote: "The actual signal logic from the printer encoder will be driving the motor during printing I just need to intercept it thru the micro/driver for a stepper."
Do you mean that the encoder is attached to the printer's DC motor and will be running independently from your code? That your microcontroller just needs to spy on those signals so you can coordinate your stepper with the movement of the DC motor? This sounds like it should work.
Yes. the encoder is the stock encoder that's connected to the printer and the printers dc motor for control and yes I just need to spy on it to coordinate the same movement from the stock movement to the stepper. Essentially when its printing the encoder on the dc motor/stock printer moves the paper based on the printers control. I would just be using a stepper to move a platen instead of paper to print on baked goods with edible inks! A few of the reasons to implement the stepper is
1. To over come the start up sequence of the printer. When it powers on it goes thru a series of checks which in turn move the drive and would cause my platen to move aswell, so by putting a delay in the programming on power up in the stepper/arduino would not run the program until start up was finished in turn not moving my platen. I know I could have implemented a electromagnetic clutch to disengage the drive using the stock motor on start up however the expense would be greater just for the clutch than the whole stepper set up (programming aside 🙂 and more difficult to implement into the drive system with specialized machined parts needed..
2. Having the added ability to add a load and eject feature into the programming via a limit switch for home and eject position. I would not have this control without adding a micro system/ circuit and clutch etc etc with the stock configuration. Again expense and seemingly more complicated circuitry?
3. A stronger motor more fit for the application of moving the platen which is a total of 6 pounds on linear guides.
I really appreciate the feedback on my project 🙂 and I hope to get going soon! Looking for a motor shield for the adruino now that would do the job. Im inexperienced so my search takes longer as I would like to get one with a good review and it seems these have different chips on the shields and I want to make sure to get a good one 🙂
thanks again..
regards
10-30-2013 06:26 PM
NathanK
Im very interested in using a motor shield for the project with the ardruino that you spoke of.. Will the shield make it more difficult as far as the interrupt pin configuration? Will the shield when plugged in to the arduino use the interrupt pins on the arduino that I need for the encoder a/b qaudrature input? Ahhh questions questions 🙂
regards
10-31-2013 11:10 AM
In general, shields pass through the pins that they don't use. If I recall, there are many Arduino digital pins that can be used for interrupts- a shield is likely to use only a couple digital pins. It is a good thing to check before you buy but it will depend on the particular shield that you are evaluating and you should ask that question to the maker of the shield.
11-18-2013 01:45 PM
NathanK
thanks for the reply, you have been a great help and given me encourgement 🙂
Im making progress!
After hooking it up. I noticed that the arduino may not be the correct micro controller to use for this project. my encoder count is high with about a 2 3/4 diameter and fairly quick at some points on eject etc. I had issues with getting an accurate encoder count using several different programs it will not be a consistent count/read and it seems the arduino is not fast enough. I tried various debounce programs and it didn't yield any better result. almost like its missing steps or something
It was recommended that I should use a microcontroller with QEI quadrature encoder interface that has noise filter etc like a pic? what is your take on that microcontroller?. can i use the same program the arduino uses and would a micro with the QEI (qaudrature encoder interface make my life any easier with this project 🙂 Can you explain the benefit of this system and could i still interface it to output to a stepper driver for step and direction with a driver like the big easy driver or pololu that uses the a4988 alegro chip? sorry for so many questions but i have to start somewhere 🙂
11-19-2013 10:48 AM
There are a few reasons that people, especially beginners, like Arduinos: It has a clear, high level programming interface; it has an large, friendly community; and it has a standard form factor so you can use third party shields.
Arduinos are just a development board based on the Atmel ATMEGA microcontrollers. These microcontrollers are perfectly capable alone but not everyone prefer them. With the Arduino dev board, bootloader, and programming environment it becomes very very easy to get started. The tradeoffs are that you do not get complete access to the functionality or timing abilities of the controller.
There are many other brands of microcontrollers. Microchip's PIC were very popular for a long time. I am not an expert on PIC microcontrollers and you would find more information on their community forums. In order to use a different microcontroller of any kind you will need to either find a dev board like the Arduino or build one yourself. If you can't find one, designing a board and having it made will be expensive and time consuming.
With the popularity of Arduinos other microcontroller communities have tried to make simplified programming environments with more or less success. You may be able to find a similar environment. It is possible but unlikely that you would then be able to reuse your Arduino code. If you can't find an Arduino-like simplified interface then you will have to learn how to use that microcontroller. This is no small task. Microcontrollers usually are programmed in C and used by interacting with a host of cryptically named registers. It takes a bit of effort and expertise to figure out the interface and they are not portable to other microcontroller families. You should ask in PIC forums if there are Arduino-like dev boards and programming environments.
All that said- I would expect your Arduino to be able to read your encoder. The Atmega chips run at speeds similar to competing microcontrollers. A printer encoder is not going to have that high a resolution or be moving that fast. Your interrupt routine needs to do as little as possible. The microcontroller will execute your main program until a pin that has an interrupt attached changes. Within just a couple clock ticks the microcontroller will switch execution away from the main program to the function that is registered to handle the interrupt. The processor will not be able to handle any other interrupts until you exit that function. For that reason it is very important that you do as little as possible in your interrupt handler.
That said- if you are only adding or subtracting a number in your handler and are still missing ticks then the Arduino may in fact not be fast enough and you would be better off using a faster microcontroller or, in the case of the PIC, a microcontroller that has dedicated hardware for encoders. Any microcontroller with free digital pins will be able to interface with your stepper driver, etc. Before jumping to a new platform I would present your problem to an Arduino forum. Many people use Arduinos in similar capacities and will be able to help you more.
Other notes:
I don't think noise on the encoder lines would cause you to miss ticks. If you were having that problem you would see spurious ticks all the time. This is not usually a problem. Debouncing is a way of ignoring noise generated by mechanical switches. Optical encoders should not need any debouncing.
With these questions you are starting to leave general motion topics and descend into specifics about embedded programming and microcontroller families. You would find better answers to these sorts of questions in forums dedicated to these technologies.
Good luck,
11-19-2013 11:45 AM
Thanks Again so much.
I think i will try one with dedicated encoder handling. I spoke with another fellow who did a similar conversion and he said the frequency of the pulses couldnt be handled by the arduino and he also had to go to a different controller. He uses pic but also reccomend atmel or a discovery board.. off to research!
thanks