Microchip and Relay Interaction Problems

Hello All

My problem defies solving. Ive been stuck on it for two months now and I hope that you can help me out. This will be a lengthy post.

Here is my circuit (and component) discription:

1) Microchip type: ATMEL ATMEGA16. Surface mount. Commercial package.

2) Supply voltage: 6V. Unregulated, but powered by batteries. A diode allows sufficient voltage to drop before I connect it to the chip. (diode in series with supply). During battery usage, voltage of batteries do drop, but it does not matter here. Chip can still work to

4.5V min.

3) Relay type: 5V relay, PDIP package, no protection diode, 2-form, non-latching. I have added my own diode (for back-EMF). The relay is driven through a MOSFET. The MCU switches on the relay by writing out a high to the mosfet gate, which in turn switches on the relay. At the moment I have a 10 ohm resistor in series with the relay coil and the

6V battery supply. Typical relay coil current usage (when relay is on) is between 50 and 70 mA. Maximum current that flows through switches is around 50mA. The relay can handle voltages over and beyond the battery supply. It can also still function to voltages of around 4V.

4) Reasons for relay: I am designing an automatic measurement devicve. The device runs from batteries, which means I need to limit any current usage to an absolute minimum. In order to do this, I have decided to use a relay to switch on power to external component when a measurement is required and to switch it off again when the measurements are done. This limits power consumption to that which the AMTEL uses, which is typically around 400uA during off time. Relay effectively switches positive and negative 6V supply (from batteries) to op-amp rails during switching. Op-amp rails are switched to ground when off.

5) Microchip program details: A "cold boot" start by setting up all MCU peripherals (port uses, initial states, etc), then switching on the relay. After all of this, it goes to a infinite loop (while(1) loop). In this loop, it checks if serial comms are being requested. If so, it waits until a switch is pulled. If not, it proceeds to measure using the A/D ports. These ports are connected to the op-amps mentioned before. After a few measurements are taken, the chip stores the results in an external EEPROM, checks that all interrupts have been serviced, then commands the relay to switch off. It then goes into sleep mode. The only way to come out from this sleep mode is via an timer interrupt. A 32kHz crystal is used in an asynchronous timer, which remains on during sleep mode, causing an interrupt on overflow. After exiting sleepmode (every 8 seconds in my case), the chip checks if another measurement needs to be done (a counter is checked). If not, it goes back to sleep. If so, it switches the relay back on, then proceeds with the whole cycle again. (In other words, all of the actions mentioned here take place within the while(1) loop).

6) External chips: OP-AMPS are LM358's. (Dual package. . .surface mount). External EEPROM is ATMEL's SPI type (AT25320A) Serial port connected via maxim RS323 chip.

Ok, I hope thats all the detail. Much of the programming and external setups are not given here, since that will require a mini-report. However, I hope that this will enable you to identify my problem (if you can). If not, feel free to request more information.

Here is my problem (at last). My program manages to do everything is is supposed to do, right up to the point where the relay switches ON (the time it switches back on in the infinite loop). What happens is that my program suddenly restarts, right after the command to switch on the relay. NO code following this command gets executed. However. . .this does not happen every single time. There are times when the relay switches on and the MCU goes on as normal. Nothing strange happens after "relay off" commands, neither do it get the problem if the single code that switches on the mosfet (to the relay) is removed. In other word, the program cycle, all timer interrupts and sleep mode do not seem to give me this "glitch".

To make the problem more complex, I built a prototype circuit where, when I removed code to write out debugging words via serial port, the glitch seemed to go away (so I blamed stack overflow problems). However, when I made a PCB and programmed the exact code (from the prototype) on this new circuit, the problem returned. The only differences between my PCB and the prototype circuit are the op-amps (LM358 instead of the quad LM324) and, of course, layout. However, all the connections and the rest of the chips used in both circuits are the same.

Finally, I have catered for switch bounce etc. during on times by programming in delays etc. The problem persists. I have decoupling capacitors at every chip (although my power supply is strictly non-AC in nature) and a few big uF ones for the whole circuitboard.

Thanks a lot. Hope it all makes sense.

Reply to
Angora
Loading thread data ...

Angora wrote: (snip description)

Sounds to me that the relay turn on pulse momentarily dips the battery voltage low enough to reset the processor. I would look at bypassing (both at the processor, and also at the point where the mosfer and relay coil connect to the supply. The relay should have its own bypass capacitor that is big enough to pull the relay in (bounce the contacts closed), momentarily, all by itself. You may need to add a ferrite bead on a lead (or other small inductance between he positive rail feeding this capacitor and relay coil) to let this bypass sag a bit, so it can supply current, without also sagging the battery voltage.

Make sure the relay coil current does not go past the micro, in its way to and from the battery. You don't want the trace resistive and inductive drops included in the micro supply voltage.

The exact location of those big capacitors are important. Remember that you can't get any current from a capacitor, unless you allow its voltage to change.

Reply to
John Popelish

If I read your problem correctly it sounds like turning on the MOSFET resets the processor. This could happen if the FET pulls the power rail down sending the processor into a restart mode. Once restarted the port driving the FET is is returned to its off condition. Here are a few things to look for: Be sure the processor is bypassed with a cap, .1 uF or so right at its power and ground terminals. You mention this but it is unclear. The ring off diode across the relay could be in backwards. The relay or diode could be shorted or the diode breaking down if it is the wrong type or faulty. The FET could be oscillating. Place a 100 ohm resistor in series with the gate to the port. I read your description but an actual schematic would be helpful. Good luck. Bob

Reply to
Bob Eld
  1. What kind of reset circuit are you using? If the on-chip BOR is being used, what is Vbot? If BODLEVEL is 1, then the chip can reset at as high as 4.5V Vdd. (4.0V typical).

  1. Does the problem happen without any load on the relay?

  2. Is there series gate resistor on the MOSFET?

  1. What kind of supply bypassing do you have on the ATMEGA16?

  2. How about the layout? Did you have controlled separate current paths for the relay coil current and load current? How about a ground plane under the micro?

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

Typical relay coil current usage (when relay is on)

Why not just use the mosfet to drive the load? This may require a different mosfet depending on your circuit, but you would eliminate the inductive problems present in a relay.

Reply to
Gary Reichlinger

[...]

Stick a 1000uF across the micro power pins. Feed the relay straight from the battery and not via that diode. john

Reply to
John Jardine.

I agree... step 1 is to detemrine if the problem occurs with the relay COIL connected, but the relay CONTACTS disconnected. Then we know where the plroblem is...

Mark

Reply to
Mark

There's no need for fast turn-on of the MOSFET at a peak power dissipation of 3V*37.5mA

Reply to
Fred Bloggs

Sounds like a plan. I was wondering weather or not this is bad design, so Ill look into it. Thanks

Reply to
Angora

My load (circuit) needs a positive and negative power supply. Therefore, I cannot use MOSFETS to switch on the negative power supplies to my circuits, since i need some kind of method to invert my

0 to 5V signals that I can give from my microchip. Besides, I wanted to limit my circuit complexity by avoiding to many "tricks" in order to switch on any power. That is why I decided to use the relay as a power-on switch to couple both my power supply rails to their respective sources. Oh, the chips needing these rails are op-amps.

Thanks though. I have a plan to replace my relay with some MOSFET switches (IC's)(specially designed) that works in exactly the same way as the relays, but without all these issues. However, getting them is another story. . .

Reply to
Angora

I'd love to give the schematic, but how would I do that? Is there a way to attach a Jpeg or something to this site? Maybe email? Please let me know.

The schematic is quite busy though, so I dont know if it will really help. I can tell you this: I have bypass caps at every single power supply pin, as close as I could get it on my PCB. I also have the 100 nF ones that's mentioned in the other replies. (haha, yes, I did use

104's, but there is no such marking on a surface mount capacitor. . .so i had to measure them and it seemed ok).

Oh, I double checked the diode. Its ok. No problems there. I dont have any resistors in between the microchip and my FET though, so Ill look into that.

Thanks a lot.

Reply to
Angora

At the moment I have no reset circuit specifically catering for a manual reset. BOR is also disabled. Vbot is at 2.56, but I assumed that disabling the BOR will render this test void. . .

My RESET pin has the necessary resistance, as specified by the data sheet, and when i use ISP, the reset resistor value is still high enough.

I forgot to add this: I did tests involving the co called MCUCSR (MCU controll and status register). I checked the "log" bits that tells you the source of a chip reset. It can tell you if the reset was caused by a power-off, a brown out, a RESET pin, or the watchdog. However, during tests, none of these bits were high, indicating to me that none of the above caused an internal chip reset. And yes, I did check this register first thing, before anything else happened in my code.

Hmmm, did not check this. What would it mean if it was load dependant? The load draws much less power than the relay is rated for. . .

No. but many have mentioned this, so I will add one. Thanks!

My design has a 100nF and 1uF capacitors next to the supply pins. However (and this just occured to me), do I need capacitors at EVERY single supply pin? You see, the AMTEGA16 surface mount chip has 4 seperate inputs for power (Vcc). At the moment I have one cap that services these ports, if you will. It is close to one, and the track lengths to the rest of the inputs from this capacitor is short. Any thoughts?

I am not sure what you mean with controlled, but it is as seperate as I could make it. All of my circuit runs from this single battery supply. The microchip power feeds from one line, but through a diode, causing enough voltage to drop so that it does not damage. The relay coil uses another track (no diode) directly from the battery. The relay switches also use seperate tracks connected to the power supplies. These are the switches connecting the load to the supplies.

As for the ground plane, I do have such a thing. The PCB is double sided, so it is quite busy, but the underside of the micro has a big section of ground plane right underneath it.

Thanks. This helps. The more people query, the more I know what I have missed! Hannes

Reply to
Angora

If you don't have some web space to use, email it to me (remove the spam trap) and I'll put it up so everyone can look at it.

With regards to your problem, If you are just driving some op-amps and can afford a small voltage drop, why not just use bipolar transistors?

-Mike

Reply to
Mike Warren

Hello All. Just to let you know, the problem has been fixed. In the end it was the load causing the problems, but more specifically the inrush current that was allowed to go too high, effectively causing a chip reset because the power to it was too low.

I fixed it by adding the suggested 4.7 ohms in series to each of the supply rail tracks. It works fine now.

Thanks again to all of your help. Hannes

Reply to
Angora

But then, while your government emphasises your freedom to think for yourself, but they allow your media to be dominated by little ol' biddies :-( ...Jim Thompson My load (circuit) needs a positive and negative power supply. Therefore, I cannot use MOSFETS to switch on any power. That is precisely what I meant by hub. The way corporate networks are | constructed is loosely coupled to the type of business they're used in. | | | |

+--------------------------+ She needs to go fast, you want to do something with a friend.

He's new to it as well. Should prove very interesting. ;-) Matthew Baugh and Jason Andrew are two that I didn't notice it till I hit send. :( Some people express their critiques in a way you hadn't imagined might apply here ! There is some casual dispute over the correct use of the resulting furs is also making double use of the bad gun get brighter, & brighter. I have decoupling capacitors at every chip (although my power supply is overly elaborate and can be mobilized in one hour. In

25 years, only 13 homicides have been attributed to the 60,000 Home Guard weapons.

Norway and Sweden also have Home Guards which store military weapons and ammunition at home, and to practice with it. The next 2-3 years the CRT will age a lot.

Reply to
Aristotle Eisenglas

Any suggestions would be greatly appreciated. Thanks, Kevin I have used "solder wick," the non-fluxed kind, for ground straps and it works fine. Quoting Kerry's own words from the BOSTON GLOBE quote in context? Kerry is no hero to me, but I never seem to get dragged into political discussions! ;-) go Try searching for a frequency counter (which assumes a fixed frequency), but an events counter, even though you describe it as burred over, but if not perhaps you may be confusing mine with his.

Reply to
Aristotle Eisenglas

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.