PDA

View Full Version : Device Resets / erratic operation - 16F88



turbokinetic
- 7th April 2009, 04:33
Hey new member here! I've been building and programming "toys" for a while now and have not had issue anything like this before. I'm working on a controller for a car's load-levelling rear suspension. It uses a PIC16F88, reading a position sensor (0-5V signal) and controlling a solenoid valve and relay, as well as an indicator lamp, and an on-board LED.

The circuit works well on the bench, driving test lights, however when connected to the acutal hardware it is to control, I get sporadic resets, lockups, and garbled operation.

The problem happens when the relay turns off. I have checked and double-checked the MCLR pin (turned off in configuration, and set to output and LOW in program), all unused pins are output and LOW. The outputs are simple NPN switching transistors, biased through a 330R resistor. The relay coil has a diode to block inductive kickback, as well as a .1uF capacitor across its incoming wires.

The solenoid valve output is constructed the same, and it does not cause any resets, in spite of the fact it is a much higher current load.

The power supply is a 7805 regulator, with a 1000uF cap on the input side, a 1000uF cap on the output side, and the chip has a .01uF cap directly across the +5V and Gnd pins.

If I replace the relay with a resistive load, the problem goes away. I've replaced the output transistor, back-EMF diode, PIC chip, and all filter capacitors, and the rests and lockups continue.

I've built several other 16F88 based controllers that drive relays using the same configuration of transistor, and nothing like this has happened.

Ahy ideas?!?

Thanks in advance!
David

[email protected]

Archangel
- 7th April 2009, 05:48
I have some ideas,
I would like to see the schematic and your code configs, also part # of the snubber diode. I am thinking . . . Diode too slow . . . Not hooked up right . . . brown out PIC due to reverse EMF, remember the back voltage from that relay coil and motor is several hundred volts, also make sure the PIC is properly bypassed on it's power pins with .01uf and a 10uf, you may need to run separate power lines from the battery for the load and PIC circuits.

turbokinetic
- 7th April 2009, 16:30
I have some ideas,
I would like to see the schematic and your code configs, also part # of the snubber diode. I am thinking . . . Diode too slow . . . Not hooked up right . . . brown out PIC due to reverse EMF, remember the back voltage from that relay coil and motor is several hundred volts, also make sure the PIC is properly bypassed on it's power pins with .01uf and a 10uf, you may need to run separate power lines from the battery for the load and PIC circuits.

Diode is 1N4007. I was indeed wondering about diode speed, since these are the cheapies from Radio Shack. I also put a small cap between the transistor base and ground, to slow down the fall time of the output and reduce the back EMF, too.

Forgot to mention - motor has built-in supression, however the resets occur even with the motor disconnected and only the relay coil active.

PIC is bypassed well, with ceramic cap directly under socket, and electrolytic at the voltage regulator.

I did some further experimintation yesterday, and found out that the relay will cause a reset, even when not connected to the circuit. In other words, with the control wire from the board to the relay coil neg terminal unhooked, if I touch a ground wire to the relay coil (click the relay), the controller will sometimes reset. This is without the motor connected to the relay.

I then took a "snap-on ferrite choke" and wrapped the harnss to the control board through this choke, and the problem is gone.

Here is the schematic (sorry for the hand-drawn schematic - I am not a professional designer by any means!)

http://68.209.87.173/Temp/LoadLevel.GIF

The power supply works by taking ignition key switched power through the indicator lamp, through a diode and into the 7805 regulator. This is enough to start the CPU. The first thing the program does is turn on the power hold-up output (pin 10 on CPU) so that it will maintain power when the indicating lamp is grounded by the indicating lamp output. The program monitors voltage at the indicating lamp circuit to know when the car's ignition is on or off, and powers off the power hold-up circuit several minutes after the car is switched off.

I bypassed this and had the circuit connected to stay on constant, and the resets continued so I don't think it is in my power control circuit.

I think the capacitor added to the base of the relay drive (not shown) and the ferrite choke have it fixed hopefully!

Thanks,
David

mister_e
- 7th April 2009, 20:51
Few observations.

Diode should go in parallel with your Relay coil (pin 86/85). Something like
http://terpconnect.umd.edu/~toh/ElectroSim/Relay.GIF

It's a good idea to keep the relay as far as possible of the PIC, and not a bad idea to place a 0.1uF + something like 22-47uF close to your relay +12V line. Some also place a small capacitor across the relay coil, and some suggest to install a capacitor across the relay contact (kinda snubber), worth a try.

There's something funky on your design about NPN-PNP connection (at pin 10)

How do you supply the Pos sensor? From your voltage regulator or from the 12V line?

I would suggest you to tie all unused pin to gnd, and set them as input.

Mode switch... i find the resistor setting a bit non standard.

1000uF at the regulator output may screw up most 7805 regulator. You want to keep this value lower than this. Check the datasheet for the brand you're using. Usually 10 - 22uF tantalum + 0.1 uF ceramic do the trick.

HTH

mister_e
- 7th April 2009, 20:52
Not a bad idea to use a LC filter at the input, those car alternator do pretty good stuff on the +12v line ;)

turbokinetic
- 8th April 2009, 02:06
Few observations.

Diode should go in parallel with your Relay coil (pin 86/85). Something like
http://terpconnect.umd.edu/~toh/ElectroSim/Relay.GIF

It's a good idea to keep the relay as far as possible of the PIC, and not a bad idea to place a 0.1uF + something like 22-47uF close to your relay +12V line. Some also place a small capacitor across the relay coil, and some suggest to install a capacitor across the relay contact (kinda snubber), worth a try.

There's something funky on your design about NPN-PNP connection (at pin 10)

How do you supply the Pos sensor? From your voltage regulator or from the 12V line?

I would suggest you to tie all unused pin to gnd, and set them as input.

Mode switch... i find the resistor setting a bit non standard.

1000uF at the regulator output may screw up most 7805 regulator. You want to keep this value lower than this. Check the datasheet for the brand you're using. Usually 10 - 22uF tantalum + 0.1 uF ceramic do the trick.

HTH

Thanks for the help!!! The diode, I mis-drew in the picture I posted. The circuit was build on-the-fly, with only the basic IO drawn up before hand. I drew that in haste to post here and that is not correct. The diode is actually connected with banded end to B+, and other end to the coil neg terminal. Then I found out, there is a second diode built into the relay its self! The relay is at least 18" from the control module, in a socket that is part of the harness.

The NPN - PNP connection allows the PIC to switch +12V on the high side, to keep the power to the circuit on, after the power path from ignition switched 12V throuth the indicator lamp is no longer available. I use the signal through the light bulb to tell it when the ignition is turned ON, as well as being able to ground the lightbulb and cause it to illuminate. It looks odd but it works, and was buildable with components I had here.

The reason I have such large input capacitor (before regulator) is that the circuit needs to stay up during engine cranking (possible B+ pulling down to less than 6V during starter inrush). I learned that trick on my headlights controllers I built for my other 2 cars! The large cap on the 5V side is only because.... that is what I had on hand. :)

The position sensor is a throttle position sensor from a Rochester MPFI throttle body. It is a potentiometer only and requires clean regulated 5V supply and "clean ground" to give any sort of accuracy.

It has a 3 wire sheilded cable in the harness, with ground coming off the board near the CPU ground, and +5V coming off near the CPU's +5V pin. The sensor is actually very accurate and does not vary significantly when the car's voltage changes or the CPU actuates outputs. I'm actually really happy with that part of the system!

The mode switch resistors are that way because - once again they are what I had on-hand. It's just a pull-up resistor and a resistor to help protect the CPU if somehow +12V gets on the switch circuit.

I've not had any resets since the choke was put on the harness, but I really like your idea of the snubber cap on the relay. Motor is supposedly internally suppressed, but it couldn't hurt to add a freewheeling diode to the motor too. If there is any reason to go into the system again, that will get done!

Thanks again,
David

Archangel
- 8th April 2009, 19:34
Not a bad idea to use a LC filter at the input, those car alternator do pretty good stuff on the +12v line ;)

Especially if a diode starts going away!

Archangel
- 8th April 2009, 19:39
The NPN - PNP connection allows the PIC to switch +12V on the high side, to keep the power to the circuit on, after the power path from ignition switched 12V throuth the indicator lamp is no longer available. I use the signal through the light bulb to tell it when the ignition is turned ON, as well as being able to ground the lightbulb and cause it to illuminate.
I used a Bosch relay on a 71 chevy to power an HEI ignition and the relay would hold down to 3volts which was low enough to allow engine to run when switched off due to receiving power through the alternator light, had to kill engine in reverse gear, where the backup lights would load it enough to cutoff relay.

turbokinetic
- 9th April 2009, 01:52
I used a Bosch relay on a 71 chevy to power an HEI ignition and the relay would hold down to 3volts which was low enough to allow engine to run when switched off due to receiving power through the alternator light, had to kill engine in reverse gear, where the backup lights would load it enough to cutoff relay.

LOL! I had the exact same thing happen on my 72 Nova. When I converted it to EFI, the ECM, ignition, and everything else was powered by a relay that wouldn't drop out until the alternator was unplugged. Fixed that by installing a diode in the alternator warning lamp wire.

It was kind of nerve-wracking because the engine was a newly rebuilt one I had put together, and wired everything up. The first time I turned the key, it started instantly, and the transmission started spewing oil profusely from a forgotten cooler line, and I couldn't shut it off!!!!

David

turbokinetic
- 11th April 2009, 03:08
Well - after all the fuss and mess; the real cause was after all..... a bad resistor. I had intended to use 1K resistors for the the transistor bias resistors on the relay, valve, and lamp driver circuits. They did all come from the same package.

The resistor for the relay driver was a 1R (1 ohm) resistor instead of 1K (1000 ohms) and was badly overloading the output on the PIC, causing it to malfunction. I finally determined there was a serious issue when I felt the PIC chip, and the 5V regulator both getting VERY WARM when the relay output was active.

After changing the resistor, the circuit works fine, without any extra choke coils or capacitors, and nothing gets warm.

The resistor was correctly marked as a 1R resistor (by color bands) but was in a package with 1K resistors so (like a dummy) I did not look closely at it before soldering it in.

Live and learn. Thanks again for the ideas, I really appreciate it and am glad to have found a place to discuss these projects!

Later,
David