CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Electronics > PIC Programing / Design


PIC Programing / Design Discuss programing of PIC chips here and design of electronics using PIC chips.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 11-15-2006, 12:47 PM
 
Join Date: Nov 2006
Location: USA
Posts: 20
RogerN is on a distinguished road
PIC Project Idea for CNC

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.
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 11-16-2006, 01:17 PM
 
Join Date: Nov 2006
Location: USA
Posts: 20
RogerN is on a distinguished road
Thoughts on details

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.
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 11-16-2006, 06:06 PM
 
Join Date: Jul 2005
Location: us
Age: 55
Posts: 668
Madclicker is on a distinguished road

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!
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 11-16-2006, 06:19 PM
 
Join Date: Aug 2004
Location: US
Posts: 2,782
ViperTX is on a distinguished road

Check cadcamcadcam.com it appears that he has a card that will generate the 0 to 10 VDC to drive a servo.
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 11-17-2006, 01:20 AM
 
Join Date: Aug 2005
Location: USA
Posts: 1,622
One of Many is on a distinguished road

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.
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 11-17-2006, 02:30 AM
 
Join Date: Nov 2006
Location: USA
Posts: 20
RogerN is on a distinguished road

[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!
Tweet this Post!Share on Facebook
Reply With Quote

  #7   Ban this user!
Old 11-18-2006, 10:46 PM
 
Join Date: Aug 2005
Location: Canada
Posts: 36
niclatrique is on a distinguished road

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.
Tweet this Post!Share on Facebook
Reply With Quote

  #8   Ban this user!
Old 11-19-2006, 12:09 AM
 
Join Date: Aug 2004
Location: US
Posts: 2,782
ViperTX is on a distinguished road

16C781 and 782 have DAC outputs.
Tweet this Post!Share on Facebook
Reply With Quote

  #9   Ban this user!
Old 11-22-2006, 09:42 AM
 
Join Date: May 2006
Location: Pakistan
Posts: 14
Danii is on a distinguished road
Question What about motion profile..?

[QUOTE=RogerN;218823]
Originally Posted by Madclicker View Post

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!
Hello Roger,

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..
Tweet this Post!Share on Facebook
Reply With Quote

  #10   Ban this user!
Old 11-22-2006, 02:02 PM
 
Join Date: Nov 2006
Location: USA
Posts: 20
RogerN is on a distinguished road

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.
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 11-23-2006, 10:51 AM
 
Join Date: May 2006
Location: Pakistan
Posts: 14
Danii is on a distinguished road
Unhappy

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.
Tweet this Post!Share on Facebook
Reply With Quote

  #12   Ban this user!
Old 11-23-2006, 05:19 PM
 
Join Date: Nov 2006
Location: USA
Posts: 20
RogerN is on a distinguished road

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.
Tweet this Post!Share on Facebook
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -5. The time now is 03:27 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353