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.

[AVR] AVR ATmega8 hangs on some microswitch inputs

Status
Not open for further replies.

abdi110

Member level 2
Joined
Mar 5, 2015
Messages
52
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
382
My circuit takes some microswitches as inputs and based on them sends some data on the serial port. After few hours it hangs randomly.
I think it is because of the inputs since I connected the switches directly to the AVR port.
Should I use opto coupler for example to solve this issue? Could anyone please give a solution for this?
 

allsey87

Member level 4
Joined
Sep 27, 2010
Messages
70
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,288
Activity points
1,902
Optocoupler is not at all necessary. The standard way to do this is to set the AVR to pull up the pins connected to the micro-switches, and have the micro-switches complete the circuit to ground when closed (assuming they are normally open). It might be worth adding a capacitor (perhaps 10uF) between the AVR pins and ground to denounce them.
 

abdi110

Member level 2
Joined
Mar 5, 2015
Messages
52
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
382
Thanks I pulled up the pins by internal pull ups. I will try the capacitors too.
My question is that if the microswitches cause hanging as I guess?

- - - Updated - - -

I also used 100nF capacitors before but I will try 10uF as you advised
 
Last edited:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,707
Helped
4,340
Reputation
8,689
Reaction score
4,303
Trophy points
1,393
Activity points
130,466
Hi,

the input pullup is about 150k (read datasheet). this gives a time constant of 150k x 100nF = 15ms. But only on rising edge.
The falling isfast, because there is no current limitng resistor. Maybe connect a 1k in sereies to ech switch.

For further discussion please attach a schematic.

***
Microswitches never cause a hanging microcontroller.

In many cases "hanging" is a software problem, or a PCB layout/wiring problem.
Like connection of RESET pin. Missing or wrong or wrongly wired supply capacitors. Missing ground plane.

Klaus
 

allsey87

Member level 4
Joined
Sep 27, 2010
Messages
70
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,288
Activity points
1,902
As KlausST said, the hanging is most likely a software problem so it would be good to see the code as well. At this point we don't even know whether you are polling the switches or using interrupts...
 

abdi110

Member level 2
Joined
Mar 5, 2015
Messages
52
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
382
Thanks KlausST
I attached the schematic. 1433172157361.jpg

- - - Updated - - -

Dear allsey87 I use polling
 

abdi110

Member level 2
Joined
Mar 5, 2015
Messages
52
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
382
As i mentioned the software works properly for 2 or 3 hours but randomly with changing in microswitches it goes to hang situation therfore i think the software has no problem. I think as you mentioned the problem is because of bouncing so in order to solve that i should use a capacitor with an external pull up resistor.

- - - Updated - - -

Maybe it is better to say that in case of changing switches status there are some unwanted noise which enter the circuit and make the system to hang. Not the bounce of switch.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,707
Helped
4,340
Reputation
8,689
Reaction score
4,303
Trophy points
1,393
Activity points
130,466
Hi,
in order to solve that i should use a capacitor with an external pull up resistor
internal pullup, but external series resistor.

Maybe it is better to say that in case of changing switches status there are some unwanted noise which enter the circuit and make the system to hang. Not the bounce of switch.
Therefore the RC at the inputs.
As said before: You need to read carefully the design considerations in the datasheet about RESET connection, VCC bypassing, clock connections and so on....

Klaus
 

allsey87

Member level 4
Joined
Sep 27, 2010
Messages
70
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,288
Activity points
1,902
It's hard to make any conclusions without seeing the code, but this sort of problem normally comes about because of a bad pointer or an overflowing buffer. You might also be crashing into your stack after awhile which could cause things to hang.

Anyway, further discussion is pointless until you post your code and tell us the exact AVR part that you are using.
 

abdi110

Member level 2
Joined
Mar 5, 2015
Messages
52
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
382
Hi,

internal pullup, but external series resistor.


Therefore the RC at the inputs.


Klaus

So you mean a series resistor for example 33 ohms in series with the AVR pin plus a capacitor between input and GND?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top