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! > OpenSource CNC Design Center > Open Source Controller Boards


Open Source Controller Boards Discussion for Open Source CNC type Controller Boards and other related items. (for personal use only)


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 11-10-2007, 02:30 AM
 
Join Date: Nov 2007
Location: USA
Posts: 4
Katratszi is on a distinguished road
PIC 18F Controller Issues

Hi, I'm new to the forums. I'm a computer science student with an interest in electronics and machining and I'm currently in the process of building a laser engraver. I had a bunch of parts and microcontrollers (specifically PIC18F252 and a few others) left over from a previous project and when I decided to build my engraver, well I decided to build the controller as well.

My problem has something to do with the parallel interface to the laptop I'm using. I'm using EMC2, but I believe the problem has something to do with my circuit and I'm at a loss to why. I don't have time to post a circuit diagram right now, but I can later if that'd be of help but a basic description is this:

I have a pic18F252, I'm regulating a 12V supply down to 5V for the MCU. The 12Vs is used to supply the stepper motor (52 oz/in 6-wire unipolar [6v at 0.8A]). The coils are driven by 4 TIP120 Darlington Transistors (with diodes to protect against back emf) that are wired to PORTB of the PIC (specifically ports 7-4). PORTC handles the incoming information, PortC.7 is used to control the (currently this is the x-axis others will be implemented later) x-steps and PortC.6 is used to control x-direction. If PortC.7 is high the stepper will rotate 1 step, wait 7 uS and then return to the main loop to check if the pin is high again (I can post the entire program later if need be).

Ok on to the problem.
There seems to be line noise and induced voltage on the control pins but I have no idea how. If I first plug everything up and turn it on, it works just fine, start up EMC2 and let it run and it seems to run just fine, but as soon as the job is done, the stepper starts...twitching, moving in random directions and usually continuing for partial rotations before turning back. I tried a 0.1uF cap on the control lines but that had no effect (and actually caused the motor to stop responding). I tried to pull the control pins to ground with a 10k resistor, and a 470 resistor, still random twitching. Lastly I used a diode and a resistor to hopefully pull the pins low enough to not trigger but alas, my stepper is still a twitching.

Oh and here is the really fun part -- I'm sure this will throw you for a loop.
If I unplug both the control lines from the breadboard the stepper stops moving as expected. But, if I move my finger within about 1/2" of the pins (without touching anything) the stepper starts twitching. The closer to the pins my finger moves the faster the stepper twitches, and yes anything conductive including wire and components moved withing the same area induce the same effect.

After hunting down other schematics for Pic based control circuits I'm not seeing anything indicating that this is 'normal'

I'm really at a loss here, has anyone ever heard of or seen this behavior before?

Thanks for your time, if there's anything confusing just ask and I'll try to clear it up, I'll also work on a circuit diagram and post it if that'll help.
Reply With Quote

  #2   Ban this user!
Old 11-10-2007, 05:30 AM
 
Join Date: Apr 2006
Location: U.K
Age: 51
Posts: 125
kwackers is on a distinguished road

I'm not sure there's enough information to give you a definitive answer, but my thoughts:-

The input pins on PIC's are very sensitive, moving your fingers near an unloaded input will cause the input to register. I usually pull the inputs high/low with a 10k resistor.
However you claim to have done this, what I'd suggest then is you're actually reading more than one input? I.E. The bit mask you've applied to read the pin is allowing more than one pin to be read allowing an input to be used that isn't pulled high/low. Ideally you probably want to set any unused pins to be set as outputs and then tri-stated.

Failing that is there any chance another output is 'coupled' to one of the inputs and whatever drives this input is floating?

I have a circuit diagram for a stand alone PIC based rotary table divider I designed, you're welcome to have a look at it - doesn't show much though other than a liberal sprinkling of 10k resistors to pull floating lines up with though
Reply With Quote

  #3   Ban this user!
Old 11-10-2007, 12:08 PM
 
Join Date: Jul 2004
Location: USA
Posts: 114
mcarvey is on a distinguished road
Buy me a Beer?
I've used a pullup and a buffer

You absolutely need to pull the inputs low/or high with a resistor (4-10K usually works). When I did my PIC18F452 motor controller I used an opto-isolator (6N137) between the computer and the PIC to prevent damaging inputs on the computer and the PIC. I have also found (the hard way) that you should never directly tie a long wire (a few feet) to an input/output pin for two reasons:
1. Long wires can easily pick up noise and fry inputs to the PIC which is bad news bears if it means replacing a PLCC44 that isn't in a socket. (I did this 3 times)
2. The PIC has trouble driving the capacitive load of a long wire (5 feet or so). It took a painful 5 hours to figure that one out.

My new policy is to always use buffers between the PIC and any long wire. Its much easier to replace a 40 cent SOIC than a 8 dollar high pin count PIC.

I hope this helps.

-Matt
Reply With Quote

  #4   Ban this user!
Old 11-10-2007, 02:00 PM
 
Join Date: Nov 2007
Location: USA
Posts: 4
Katratszi is on a distinguished road

Ok heres the circuit diagram, I'm sure the circuit has plenty of problems, I'm not exactly an electronics expert its more of a hobby. I can also post the program if anyones wants to see it (its written in picbasic).

By the way, PortB.7-4 are outputs, and PortC.7 and PortC.6 are inputs all the rest are left at their default values...which if I remember correctly PortA is Input, and PortB/PortC are outputs (with a bunch of special case pins on PortC).
Attached Images
File Type: jpg pic18f252steppercontroller.jpg‎ (67.1 KB, 214 views)
Reply With Quote

  #5   Ban this user!
Old 11-10-2007, 02:11 PM
 
Join Date: Apr 2006
Location: U.K
Age: 51
Posts: 125
kwackers is on a distinguished road

The two diodes in the step and direction lines shouldn't be there - they'll only conduct if the lines are pulled low - which given you're already pulling them low via the two 10k's makes me wonder how it's working at all... Remove the diodes but leave the pull-downs.

Also the arrangement of your stepper winding driving is such that the maximum voltage at the winding will be 5v-2.1v (the output of the pic minus the diode and the base-emitter junction of the darlington). What you really want to do is connect the winding between 12v and the collector (with a back emf diode across the winding) and the emitter of the transistor connected to 0v then drive the base through a suitable value of resistor. Bear in mind though, 12v is probably too high for the stepper at the very least you'll proably need a current limiting resistor...
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 11-10-2007, 02:24 PM
 
Join Date: Nov 2007
Location: USA
Posts: 4
Katratszi is on a distinguished road

You're right the diodes on step and direction did cause it to stop working, not sure why I put them there actually -- must have been tired last night when messing with it. Even with them removed I get the same issues as before though.

What sort of resistor values would you suggest for driving the base? I'm also not entirely sure what sort of resistor would be needed for the steppers. They're designed for 6v at 0.8A, at 12v would I need to limit the current to 0.4A? Which requires a 30-ohm resistor.
Reply With Quote

  #7   Ban this user!
Old 11-11-2007, 06:19 AM
 
Join Date: Apr 2006
Location: U.K
Age: 51
Posts: 125
kwackers is on a distinguished road

If the stepper coil is dropping 6v @ 0.8A then it's DC resistance is 7.5 ohms, since you want the current to stay the same but double the voltage then you need another 7.5 ohm resistor in series with each winding. (I'd check with a multimeter that the current is correct for 6v).

The current you need to inject into the base is the collector current / transistor gain. The datasheet I'm looking at gives a minimum gain of 1000 so to get (say 1A) you'd need 1mA injected. Since you want the transistors turned hard on and the pic can deliver around 20mA I'd simply go for a 1k resistor. The datasheet quotes 2.5v base-emittor, so with the pic delivering 5v on it's output that leaves 2.5v dropped across your resistor which would translate to 2.5mA which should be plenty to switch them hard on. (I notice the transistor has an internal diode across CE so you wouldn't need an output diode).

You may want to look at using the PIC to control the current, in the past using bi-polar steppers I drove a discreet H bridge using a 18f452. The 0v supply to the H bridge ran through a small resistor to allow me to measure the current it was using by measuring the voltage dropped across the resistor, I used the onboard ADC to measure this current and internally the software altered the duty cycle of one of the internal PWM whose output was gated with the H bridge drive signals. This allowed me to use a 50V supply for good dynamics but kept the current within the safe range. I think my PWM was running at around 50khz.

As far as the glitching goes...
If you ground the step input - does it stop? If not then it's more than likely a software issue.

If it does stop - is the 10k resistor you're pulling to ground really 10K? Have you got any other lines running close to the step input which could be capacitively coupled? Is there a fault on the parallel cable which is connecting more than one line to the step input?

This might seem stupid - but it's happened to me.
Are you reading from the correct pin or connected to the correct pin? (remember the ports are labelled 0-7 not 1 to 8) I've had this and the device has worked - because the actual pin I was connected to was the next along and the capacitive coupling was enough to get it to work - most of the time...
Reply With Quote

  #8   Ban this user!
Old 11-11-2007, 12:58 PM
 
Join Date: Nov 2007
Location: USA
Posts: 4
Katratszi is on a distinguished road

I double checked the resistor and found out that it was a 1k resistor and not 10k, replaced it and the glitching has stopped -- red/orange can be difficult to tell apart apparently. So at least that problem is out of the way, stupid mistake but oh well.

I have started to look at chopper circuits, it never occurred to me that since the motor is basically an inductor, the same basic rules for a switch-mode power supply should apply. I think I prefer this method vs power-resistors since it doesn't require more components and its more efficient, no need to waste all that power as heat.

Unfortunately I've never used the ADCs, and I've never made a switch mode power supply so I'm not really sure where to start. Theoretically its a simple concept if I understand it correctly, use a since resistor to figure out the current and increase the duty-cycle or decrease the duty-cycle until the right amount of current is reached. I'll start looking in to it a bit more in detail shortly.

I do have one problem left with the stepper but I believe its an issue in EMC2. The steps seem to work correctly, but the motor doesn't really switch directions when PortC.6 is high (which is direction) the motor slows to almost a crawl and will take only a couple steps in reverse.

Anyways my goal is to make the simplest working controller as cheaply as possible. Once it all works and I'm finished I'll definitely release everything if anyone else wants to build one. I'm sure I'm reinventing the wheel here, but sometimes that's half the fun.
Reply With Quote

  #9   Ban this user!
Old 11-11-2007, 01:44 PM
 
Join Date: Apr 2006
Location: U.K
Age: 51
Posts: 125
kwackers is on a distinguished road

Another way to do the current limit, is to use the sense resistor and feed the output to a comparator which in turn switches the output stage on and off.
the other input of the comparator could be fed either via a variable resistor or a R2R resistor network fed from the pic's outputs.
As the current through the resistor increases the voltage drop increases until it exceeds the voltage on the other input - this'll turn the output stages off (possibly feed the output of the comparator to a PIC input and generate an interrupt when it changes?).
You may need a capacitor to smooth the comparator input and prevent the switching frequency being too high.
Reply With Quote

  #10   Ban this user!
Old 11-12-2007, 01:00 AM
 
Join Date: Sep 2006
Location: romania
Posts: 218
eSilviu is on a distinguished road
schematic question

5V and 12 V power supply are in any way connected with the computer?
gnd from parallel port is connected to 0V of your circuit?!

if not, it should be!
Reply With Quote

Sponsored Links
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 On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A few issues with my VF2... LorenzoNH Haas Mills 6 08-21-2007 04:05 PM
Controller issues Selmac Machine Problems, Solutions , Wireless DNC, serial port 7 09-25-2006 11:39 AM
VTC-41 issues rond Mazak, Mitsubishi, Mazatrol 3 06-20-2006 06:25 PM
MDI & t & s issues? howling60 CamSoft Products 8 02-24-2006 10:27 AM
Feedrate issues with v20? mikesos1 BobCad-Cam 3 07-06-2005 04:07 PM




All times are GMT -5. The time now is 12:53 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 354 355 356 357 358 359 360 361