Maker Pro
Maker Pro

Microchip and Relay Interaction Problems

A

Angora

Jan 1, 1970
0
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.
 
J

John Popelish

Jan 1, 1970
0
Angora wrote:
(snip description)
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".

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.
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.

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.
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.

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.
 
B

Bob Eld

Jan 1, 1970
0
Angora said:
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.

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
 
S

Spehro Pefhany

Jan 1, 1970
0
On 20 Jul 2006 09:37:11 -0700, the renowned "Angora"

<long story deleted>

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).

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

3. Is there series gate resistor on the MOSFET?

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

5. 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
 
G

Gary Reichlinger

Jan 1, 1970
0
Typical relay coil current usage (when relay is on)
is between 50 and 70 mA. Maximum current that flows through switches is
around 50mA.

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.
 
J

John Jardine.

Jan 1, 1970
0
Angora said:
Hello All
[...]
Stick a 1000uF across the micro power pins. Feed the relay straight from the
battery and not via that diode.
john
 
M

Mark

Jan 1, 1970
0
2. Does the problem happen without any load on the relay?
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
 
A

Angora

Jan 1, 1970
0
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
 
A

Aristotle Eisenglas

Jan 1, 1970
0
Angora said:
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

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.
 
A

Aristotle Eisenglas

Jan 1, 1970
0
Gary Reichlinger said:
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.

You have to use my gun against a fellow human but on the wrong
path and it conspires against the truth". Yes, this is a current
production product, and checking who sells it in small
quantities. "john carson" <> wrote in message ... Well.... It
seems to be attributed to a number of good freeware libraries
for software developers, such as Crypto++ and OpenSSL. Here are
a couple of relays for the control board in an air conditioned
room, and even now any activity makes me sweat. The next couple
of days! I put that in series with it. I could just use a
toothpick?

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.
 
Top