Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16f driving a stepper motor through a ULN

Status
Not open for further replies.

malaiwah

Newbie level 3
Joined
Dec 9, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Québec
Activity points
1,322
Hi,

I'm currently experimenting electronics as a hobby.
I bought a protoboard, a PIC programmer, some PIC16F628A chips, some L7805 voltage regulators and some ULN2003AN chips. I have a small stepper motor I would like to drive using a circuit that uses (hopefully) these components.

I have read a lot of documents, but I'm still trying to figure out how to make it work.

Currently, I have fried a LED, one voltage regulator, one PIC and one ULN. It was a bad day.

I had the regulator powered on with a battery for a while, but found out a 13VDC wall wart lying around so I decided to try it. It was outputting 17VDC idle, but I thought that was because it was not a "switching" power supply and tought the regulator would be fine with it... errr.. It was not. It got hot and then outputed 12 volts out of the "regulated" side which I think fried the PIC and the LED.

So I went back to the battery setup and changed components. My PIC is running well and my LEDs are flashing in the correct pattern and duration; this part runs well.

I thought that I could drive my stepper motor (6 wires: two commons and four for sequencing) through a ULN2003AN chip but can't figure out a way to wire it. The PIC16F628A runs at 5 volts (I have a regulated 5V power bus at the right of my bread board). The stepper motor should run at 12 volts (I have a 12V power bus unregulated at the left of my bread board).

One of my tries fried the chip, I think that was like a 12V short-circuit or reverse polarity ;-) I wonder if I should have bought ULN2003 chips (not the AN variety).

I'm searching a schematic that would explain how I can connect my PIC16F628A outputs (portB) to the ULN2003AN out to the stepper motor. Something like that: https://obrazki.elektroda.pl/36_1253769551.jpg but using 4 outputs and a ULN2003AN.

Thanks a lot for any help, that would be really appreciated.
 

You are on the right track but the smoke signals say something is wrong.

Take a look at
http://www.atv-projects.com/PCB_Agitator.html
which uses a different PIC and discrete transistor drivers but it does demonstrate the principle. The transistors and the diodes are all essentially the same but in your case are inside the ULN.

The reason your wall wart damaged things is more likely to be because of:
1. Lack of decoupling capacitors at the regulator input and output,
2. It may not have been 'clean' DC, some warts have no reservoir capacitor,
3. The regulator may well get quite hot in normal use, did you have a heat sink?

17V in itself isn't enough to do damage, the 7805 is good to about 30V.

Also be very careful with the ULN connections, pin 8 must go to ground and pin 9 must go to the motor supply (12V). Pin 9 is not a supply pin like on most other devices, it is the common connection of an array of diodes to clamp excess voltages on the output pins, if you connect it to 5V it will pass current from the motors back to the PIC supply and damage it.

Brian.
 

    malaiwah

    Points: 2
    Helpful Answer Positive Rating
betwixt said:
You are on the right track but the smoke signals say something is wrong.
Definetively ;-) At least I learned some new things while doing my thing!

betwixt said:
The reason your wall wart damaged things is more likely to be because of:
1. Lack of decoupling capacitors at the regulator input and output,
2. It may not have been 'clean' DC, some warts have no reservoir capacitor,
3. The regulator may well get quite hot in normal use, did you have a heat sink?

17V in itself isn't enough to do damage, the 7805 is good to about 30V.
I did not use decoupling capacitors at the input; how should I wire it?
I used one capacitor at the output, between GND and +5V (I plugged it directly on my right 5V bus on the proto board).
I thought my 7805 where of the cheap kind and maybe they were not supposed to get that high of a voltage.
I did not think the regulator that powers my PIC would get that hot and need a heatsink; I have one in my toolbox that I could fit but thought that was overkill.

betwixt said:
Also be very careful with the ULN connections, pin 8 must go to ground and pin 9 must go to the motor supply (12V). Pin 9 is not a supply pin like on most other devices, it is the common connection of an array of diodes to clamp excess voltages on the output pins, if you connect it to 5V it will pass current from the motors back to the PIC supply and damage it.

Pin 8 was going to ground, at least on some of my firsts tests before going crazy and ... smoking the ULN..
Pin 9 always has been connected to +5V which is probably what was wrong.

Should I have resistors between the output of the PIC (port b) and the input (base) of the ULN?

Thanks a lot for your help and I will have a look a the link you mentionned.

Added after 4 minutes:

betwixt said:
Also be very careful with the ULN connections, pin 8 must go to ground and pin 9 must go to the motor supply (12V). Pin 9 is not a supply pin like on most other devices, it is the common connection of an array of diodes to clamp excess voltages on the output pins, if you connect it to 5V it will pass current from the motors back to the PIC supply and damage it.

Is the ULN2003AN the correct chip to use or did I order the wrong ULN?
The specification datasheet is not telling about the "AN" variety, only the "A" ones.
 

The 'N' is just marks the package type, it plays no part in the electrical performance.

The resistors are internal to the ULN so you can omit them as well. The PIC can connect directly to the inputs on the ULN. You can see why these devices and their big brother the ULN2803 are so popular.

I suspect the connection on pin 9 did most of the damage. Basically, any voltage slightly higher than that on the output pins is conducted to pin 9. When being used to drive inductive loads (relays, motors etc) which produce high voltage spikes it provides a mechanism to clip the spikes off before they do damage. Unfortunately, by wiring it to 5V it would have seen the 12V motor voltage as being higher and tried to dump it into the 5V rail.

As far as decoupling capacitors go, you absolutely need to use at least one. It should be about 1uF, rated at a voltage slightly higher than the voltage at the regulator input and should be wired between the input and ground pins as close to the regulator as possible. Inside the 7805 there is a stable voltage reference and an amplifier which compares that reference with the output voltage, it adjusts how much is allowed to pass through the regulator to keep the output constant. Unfortunately, the amplifier is prone to oscillating by itself if it's own supply has noise on it, adding the capacitor helps to keep it in check. You can also add a similar capacitor at the output pin as well, don't make the value too high (>100uF) as it will slow down the rise of the 5V and may prevent the PIC starting up properly.

Brian.
 

    malaiwah

    Points: 2
    Helpful Answer Positive Rating
betwixt said:
I suspect the connection on pin 9 did most of the damage. Basically, any voltage slightly higher than that on the output pins is conducted to pin 9. When being used to drive inductive loads (relays, motors etc) which produce high voltage spikes it provides a mechanism to clip the spikes off before they do damage. Unfortunately, by wiring it to 5V it would have seen the 12V motor voltage as being higher and tried to dump it into the 5V rail.

Duh. That was my mistake; I did not correctly understand the datasheet.

betwixt said:
As far as decoupling capacitors go, you absolutely need to use at least one. It should be about 1uF, rated at a voltage slightly higher than the voltage at the regulator input and should be wired between the input and ground pins as close to the regulator as possible. You can also add a similar capacitor at the output pin as well, don't make the value too high (>100uF) as it will slow down the rise of the 5V and may prevent the PIC starting up properly.

I will need to review my capacitor usage as I only had a 16V-1500uF on hand and plugged it on the 5V regulated rail. I thought bigger could not be worse ;-)

Added after 4 hours 41 minutes:

Yeah! I had the chance to take another look at my circuit at lunch time today and with your recommendations it is now working!

I'm driving the stepper motor in full or half steps, with the duration I want.

This is my first PIC circuit built from A to Z and I'm proud of the results now (even though some chips died/fried during the course of my learning!).

Thanks for your help, it is really appreciated.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top