Interrupts Killing Arduino?

I have been rewriting / converting some software originally written and compiled using Bascom AVR to now run on Arduino.
This is for a shooting range target turning timer.
Switch 1 selects the event.
Switch 2 selects the timing for the event. Multiple times are selectable for each event.
Switch 3 starts the timing.
Switch 4 stops the timing if required.
Once the event and time has been selected the start switch is pushed.
The target is faced toward the shooter for the time period selected and turned away when the timer reaches zero.
All pretty simple.

The hardware consists of :
1 x Arduino micro
4 x NO Push Button switches
1 x 20 x 2 LCD
1 x Relay Output (represented at this stage with an LED).

The First switch selects
All was going well until I implemented the timing function for Interrupts using the TimeOne library.
This was all working OK initially and I was getting the timer to stop after a predetermined time.

Next minute the LCD goes blank.
The PC reports the USB device has malfunctioned.
Have disconnected Arduino from USB and power cycled the Arduino. Nothing. LCD still blank.
The PC still reports the USB device has malfunctioned when plugged back in.
Restarted PC - Same result.
Have then attached my AVRISP MKII. Still nogo.

Have then plugged in a Pro Micro I had.
PC is happy. Recompiled for the Pro Micro. Uploaded and....
Now I have a dead Pro Micro as well

I hope someone out there knows what is going on. I am baffled.
Starting to think Arduinos are garbage and I should have stuck with bare AVR's and Bascom AVR.

Please post a schematic that shows how you have everything wired. It's fine to make a hand drawn diagram and post a picture of it.

Drawing attached.

OP's drawing:

It appears you're going for pulldowns on the pushbuttons. Compare yours to S1 in this schematic

Oops, sorry, Drawing was wrong. Correct one attached.

mrpenguin:
Have then attached my AVRISP MKII. Still nogo.

What exactly do you mean by "nogo"?

Does the problem still occur if you disconnect all the external wiring and the LCD from the Arduino board?

Yes, Arduino on its own attached via USB or AVRISP is still nogo.

Image from reply #4

Does "nogo" mean that you can't upload? In that case does your OS (which one) recognise the when connected via USB.

Looking at the schematic, my main question would be how the micro it was powered just before it failed? External power? USB? You state that the led represents the relay. Does it represent it or was there physically a relay connected instead of the led? If the latter,

  • relay or relay board?
  • which voltage?
  • how was it powered?

Due to the USB stack running on the same chip as your sketch with this board, it is possible for code in your sketch to break the USB functionality of the Pro Micro. I would not expect broken USB code to cause the error you're getting, but I have experienced some pretty unexpected behavior from ATmega32U4 boards running buggy code so I suppose it's possible.

Luckily, the upload code (bootloader) is stored in a separate section of memory and can not be broken by the sketch code. The only tricky thing is that the bootloader has to be activated at just the right time during the upload. Normally this is done by some special code that runs in the background of your sketch code recognizing a 1200 baud connection as the signal to reset the microcontroller and start the bootloader. However, in your current situation, that system wont work so you'll need to manually reset the board to activate the bootloader. In the case of the Pro Micro this means connecting a wire between the reset and ground pins since it doesn't have a reset button. You need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button. The way to get the timing right is to watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

press and release the reset button.

sterretje:
Image from reply #4

Does "nogo" mean that you can't upload? In that case does your OS (which one) recognise the when connected via USB.

Looking at the schematic, my main question would be how the micro it was powered just before it failed? External power? USB? You state that the led represents the relay. Does it represent it or was there physically a relay connected instead of the led? If the latter,

  • relay or relay board?
  • which voltage?
  • how was it powered?

No relay just an LED.
Arduino powered by external 5V.

FYI, I am an electronics TECH (59 years old who owns a successful repair shop so not a newbie.
Never had issues using AVR's (been using since 2000 with Bascom AVR).
This is my first foray into Arduino.

Many thanks Pert.
The Micro is back up and running.
Haven’t sorted the Pro micro yet.

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

You're welcome. I'm glad to hear the Micro is working now.