585,973 active members*
4,094 visitors online*
Register for free
Login
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2007
    Posts
    4

    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.

  2. #2
    Join Date
    May 2006
    Posts
    184
    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

  3. #3
    Join Date
    Jul 2004
    Posts
    127

    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

  4. #4
    Join Date
    Nov 2007
    Posts
    4
    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 Thumbnails Attached Thumbnails pic18f252steppercontroller.jpg  

  5. #5
    Join Date
    May 2006
    Posts
    184
    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...

  6. #6
    Join Date
    Nov 2007
    Posts
    4
    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.

  7. #7
    Join Date
    May 2006
    Posts
    184
    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...

  8. #8
    Join Date
    Nov 2007
    Posts
    4
    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.

  9. #9
    Join Date
    May 2006
    Posts
    184
    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.

  10. #10
    Join Date
    Sep 2006
    Posts
    218

    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!

Similar Threads

  1. A few issues with my VF2...
    By LorenzoNH in forum Haas Mills
    Replies: 6
    Last Post: 08-21-2007, 10:05 PM
  2. Controller issues
    By Selmac in forum DNC Problems and Solutions
    Replies: 7
    Last Post: 09-25-2006, 05:39 PM
  3. VTC-41 issues
    By rond in forum Mazak, Mitsubishi, Mazatrol
    Replies: 3
    Last Post: 06-21-2006, 12:25 AM
  4. MDI & t & s issues?
    By howling60 in forum CamSoft Products
    Replies: 8
    Last Post: 02-24-2006, 05:27 PM
  5. Feedrate issues with v20?
    By mikesos1 in forum BobCad-Cam
    Replies: 3
    Last Post: 07-06-2005, 10:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •