![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| PIC Programing / Design Discuss programing of PIC chips here and design of electronics using PIC chips. |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| |||
| |||
My mill positions using linear encoders on each axis. The controller outputs an analog voltage to the servo amps (AMC) to move the axis. The analog signal is proportional to the error between the commanded position and the actual position. I would like to upgrade my old controller to use PC based controls. I thought maybe someone could make a PIC circuit & program that would take step and direction inputs and encoder feedback, to output an analog signal for servo drives. A variation of this could output step and direction at a rate determined by the error (encoder feedback vs. step & direction internal counter) and gain. You could use microstepping drives for smooth control and move the axis 1 count per step from the control. Benefits: Would let you use servos or steppers with step & direction software. Positions from actual table position compensating for backlash, lead screw error, etc. You could position accurately with or without ball screws and wouldn't need to program backlash comp. The analog output version would be compatible with most servo systems. The step & direction output version would be compatible with steppers and servos that can use step and direction. I pretty much know how to do this project but have too many projects and not enough time. |
|
#2
| |||
| |||
I've written code to read quadrature encoders before. I connected A & B channels to pins that could be set up for interrupt on change. At each interrupt, I Exclusive OR'd the New A value with the previous B value, getting a 1 for one direction and a 0 for the other. So, for this project I would have A, B, & STEP on "interrupt on change" pins. The interrupt code would do something like: If A XOR PREV_B = 1 INC COUNT else DEC COUNT, PREV_B = B. If PREV_STEP = 0 and STEP = 1 then If DIR =1 INC DEST else DEC DEST, PREV_STEP = STEP. Return from interrupt Main loop: ERROR = DEST - COUNT. ANALOG_OUT = ERROR X GAIN (DIP Switches or jumpers for gain?) Are there PIC's with analog outputs? For the Step and Direction output option, perhaps set up an interrupt with a rate based on the error X gain. Or have a constant interrupt rate and step every so many interrupts. Any thoughts on this? I think it would be awesome to be able to position accurately with linear encoders even with less accurate lead screws. Depending on how many steps it takes to change your encoder 1 count, you would set up your gain to get to the exact position ASAP without overshoot or oscillation. Other I/O Perhaps an input from the control when it is disabled. Then set the DEST and COUNT both to zero, we don't want the axis moving when we first enable them. I would like to have maybe and output or green & red LED indicating ERROR = 0 or ERROR != 0. |
|
#3
| |||
| |||
| It's quite a bit more complicated than this. Yes, the error is the desired minus the actual position. When you talk about multiplying the error by a gain you are talking proportional control. This is a simple control approach, but most often sorely lacking in performance or ends up creating an unstable system. The standard approach is to use PID control (proportional + integral + derivative). The "P" is the gain you were talking about. As for overshoot, an optimally (settling time) tuned control loop has .707% overshoot. This is called critically damped. Granted, many apps, including machining, require 0 overshoot. This is an overdamped system. All that said, this is very doable. All modern servo drives that I know of are PID and use encoder feedback. If a stepper drive used encoder feedback, it could be used to make sure steps were never missed.
__________________ Steve DO SOMETHING, EVEN IF IT'S WRONG! |
|
#5
| |||
| |||
| If I understand your train of thought, this sounds exactly like a Step and Direction servo controller. These use a servo motor not a stepper motor, but can step the servo motor based on the resolution of the feedback or a ratio thereof. Someone else can go into further detail if this is what you have in mind. DC
__________________ Learn cause and effect through experience. Mastering those relationships is the "Common Sense" ability within the art of any trade. |
| Sponsored Links |
|
#6
| |||
| |||
| [quote=Madclicker;218670]It's quite a bit more complicated than this. Yes, the error is the desired minus the actual position. When you talk about multiplying the error by a gain you are talking proportional control. I already have PID control between my servo drive and servo motor. When I first bought this mill, it had a good deal of backlash in the table, I had to shim to take the play out between the ballscrew and the table. While it had the backlash, I moved the table out of position to watch the response. When I moved it out .0005", the servo motor ran slowly until the backlash was taken up and the table moved back to .0000 . When I would move the axis .001 out, it corrected approximately twice as fast, and so on. I figured out that this was running my servo in velocity mode with the velocity proportional to the error. If the control to servo loop was using PID, I don't think it would be stable with backlash in the system. Applying the same idea to a stepper system. Let's say for example that a system takes 10 stepper motor microsteps to increment the linear encoder 1 count. The CNC control sends out a step pulse creating a position error of 1 unit. The PIC sends step pulses to the stepper drive at a rate of error X gain, let's use a gain of 20 in this example. So, in a half second, the PIC sends out the 10 step pulses and as soon as the linear encoder transitions, the PIC stops sending pulses, you're in position, no overshoot. Of course this would be great to have PID control, you could tune to directly control servos with the PIC interfaced to a H-Bridge. Thanks for the response! |
|
#7
| |||
| |||
| Hi, I don't know any PIC (16F, 17C, 18F and dsPIC) who has an analog output. An easy way to acheive this is a PWM output coupled to an external RC filter circuit to filter the PWM. It's a slower response than a real DAC output but it is cheaper and at the reach of the hand. |
|
#9
| |||
| |||
| [QUOTE=RogerN;218823] I am also working on a same project and trying to figure out PIC side software for the whole operation. At the moment what i understand (Please correct me if I am wrong) is .. Step pulse width(high + low) which is inversely proportional to the vilocity from MACH2 and Pulse width from encoder as feed back (high + low) should be equal. So error between these pulses should be zero ( this is our set point for pid loop). I am not sure is it the right way to move forward on to write pic side code or not.(Please share your idea). 1- What is error in your understanding. is it difference between distances or difference between vilocities. ? 2- What about motion profile if using PID loop . Will the motion profile comming from MACH2 in form of step pulses and actual Motion profile of motor got after PID tunning can be the same.? Thanks Dani.. |
|
#10
| |||
| |||
| One technique I've seen for PWM: (for 8 bit resolution) 0 to 255 corresponds to 0 to 100% output. Add your pwm to a byte at each time interval that the loop is ran If you get an overflow, turn output on, else turn output off. So, starting from zero and using 50% (128) let's step through a couple of loops. (in no specific computer language) byte = 0; pwm = 128 LOOP: byte = byte + pwm if overflow the out_pin = 1 else out_pin = 0 ... ... goto LOOP First pass, byte = 128, output 0 second pass, byte = 0, overflow = 1, output 1 third pass, byte = 128, overflow = 0, output 0 and so on. The error is the difference between the commanded position and the actual position. |
| Sponsored Links |
|
#11
| |||
| |||
| I am just bigner and student in this field and working on PIC micro code. Please make it more allaborative for me. In step direction mode. what is the method to match the actull profile of servo motor with profile comming in the form of step direction. This question is confusing me a lot. suppose i get 1 pulse as a step pulse which is equal to the move .001 inch command. Now how i will tell motor that at which vilocity should it move so that i get exactly 1 pulse from encoder (if one pulse of encoder is also equal to .001 inch). Hope to hear soon. |
|
#12
| |||
| |||
| Unless you have some other form of control on the motor, you need more than 1 encoder count per .001" if you want to position to .001". I heard that a rule of thumb was that you needed 10 encoder counts per the amount you want to position to. The reason for this is that the output is based on error, that is the difference between desired position and actual position. P = error X Kp (proportional gain). D is the rate of change of the error, for example, if you're 2 encoder counts off and the error is getting larger, you can use a larger response. If your 2 encoder counts and zeroing in on the desired position, you can lower the response. The I gain is integrating the error over time, for example if you need to be in position under a load, such as a vertical axis fighting against gravity. Say for example it takes 10% of the motors torque to hold the vertical axis in position. You'll never get in position with just P and D because it take an error to get the 10% torque out of the motor. "I" will slowly (compared to the responsiveness of P & D) build up until the position error is zero and the torque will be the 10% required to hold the position. There are PIC servo application notes on Microchips website that you can get the actual code, schematics, etc. This "PIC project idea" that I have involves a second closing of the control loop. The basic idea is to have the PID control the servo, and the CNC controller to command a velocity based on the error between the desired position and the feedback position. I think the tightest following using servo or steppers would use velocity feed forward, P, and perhaps D to close the position loop. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |