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