AVR Resets when key is pressed

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

i have an ATMega32 and two switches connected to PD4 & PD5. I use the internal pull ups and the switches are connected otherside to GND.

Now i have some code like this:

DDRD = 0x00; // All inputs
PORTD |= (1<<PD4)|(1<<PD5); // Activate pull-ups
...
while (1) {
if (bit_is_clear(PIND, PD4) {
// Do something here
}

if (bit_is_clear(PIND, PD5) {
// Do something here too
}

delayms(10);
}

It does not matter what is done inside the if branches. I also checked with a DVM that the switched are working correct and that no short circuit is produced. I don't use any interrupts for this switch part (interrupts are used in other parts of the program, but i can enable or disable them without changing this strange switch behavior).

Any ideas?

Hava a look at my web page -> http://www.tobiscorner.at.tf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do you know the micro is reseting?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay reseting is the wrong term... lets says it's doing nothing anymore, it's hanging...

Hava a look at my web page -> http://www.tobiscorner.at.tf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So it's time to put in an LED with a huge delay between blinks and then set jump points to trace where the freeze is occuring.

If you get to stage 1 and the led blinks, remove the led_jmp and insert it into stage 2, etc..

I am assuming you are a beginner and don't have an oscilloscope or you probably wouldn't have asked us this question ;)

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, i could figure out what was wrong. The switch i used was defect. It desoldered it and tried the same program with some copper wires soldered to the switch pads and it worked. So maybe the switch was defect and produced something bad.... I don't know.

Hava a look at my web page -> http://www.tobiscorner.at.tf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A delay of 10ms isn't very long. You might be seeing the effects of a switch bouncing, which could be in the 100's of milliseconds.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The switch is a push & lever button. When i press UP the Power Line connected to the switch is shorted to GND. It was the switch that caused this problem.

Hava a look at my web page -> http://www.tobiscorner.at.tf