Solved: Frequency counter, processor locks up after a while (Arduino UNO)

Board: UNO R2
Sketch: Frequency Counter sketch for Atmega328 by Nick Gammon (Gammon Forum : Electronics : Microprocessors : Timers and counters)
Compiler: Arduino 1.0.5

Test setup: 555 timer on breadboard, 5V source, output from 555 timer to pin 5 on UNO, shared ground from breadboard to POWER GND on UNO

Problem: The UNO is displaying the frequency in the serial monitor for a while, then the TX LED goes steady lit. By "a while" I mean from a few seconds to less than a minute.

I tried a different sketch from FreqMeasure Library, for Measuring Frequencies in the 0.1 to 1000 Hz range, or RPM Tachometer Applications, and the same problem.

I am wondering if the breadboard setup is too noisy and somehow affects the UNO? The wires to the UNO are 3-4" long.

I have not found other posts with this problem (google search), so if anyone have a suggestion, please share!

Can you take a photo of your setup?

Are you using the first sketch on my page? I don't think there is anything in the program that should cause it to fail after a minute.

Hi Nick, pic attached.

Some additional info, frequency is about 2600 Hz, Breadboard has a stable supply 5V, UNO is powered via USB.

I am using the sketch marked “Frequency Counter sketch for Atmega328”

Yes, my camera does that every now and then. Takes very blurry photos. I blame the camera. :wink:

I set up a test with that sketch (the first one on my page) at 2600 Hz from the function generator. It seems to be working fine after a few minutes. My wire is a few inches long (about 20 cm).

I am guessing this is something electrical. What is the voltage range out of your 555 circuit? It should be in the range 0 to +5V.

This is what I got:

Frequency Counter
Frequency: 0 Hz.
Frequency: 0 Hz.

...

Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2604 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2602 Hz.
Frequency: 2604 Hz.
...
Frequency: 2602 Hz.
Frequency: 2602 Hz.

I got hundreds of lines like the above. Still going OK after 5 minutes.

I changed my setup a bit, took the voltage from the UNO POWER 5V to the 555 timer. So now there is only one power source…

I cannot confirm the range of the output from the 555, I have no scope.

The funny thing is that if I run the code without the 555 attached, the same problem arises… Also, the Tx light does not light up until I open the serial monitor (which resets the UNO). Weird.

I modified the code a bit to include a loop count value with each print. Sample of output:
Frequency Counter
F: 2652, 1
F: 2654, 2
F: 2652, 3
F: 2652, 4
.
.
.
F: 2654, 19
F: 2654, 20
F: 2654, 21
F: 2654, 22
F: 2654, 23
F: 2656, 24

It stopped at 24, disconnecting and connecting power does not start the serial transmission (No Tx light). Opening the Serial Monitor resets the UNO and print statements are transmitted.

Next output, stops at 38, and Tx light steady on.:
F: 2664, 34
F: 2664, 35
F: 2664, 36
F: 2664, 37
F: 2664, 38

555 timer disconnected:
Frequency Counter
F: 0, 1
F: 0, 2
F: 0, 3
F: 0, 4
F: 0, 5
F: 0, 6
F: 0, 7
F: 0, ← Stopped here

I discovered that input 5 is very sensitive, I had a 4" wire connected and sticking up like an antenna, and by holding my hand there, it showed 60 Hz, our net frequency here in Canada.

So I suspect the whole problem is noise.

maybe I should place a capacitor on the input…

All inputs do that. With no specific load connected they "float" and return all sorts of readings.

I think the problem is solved. I powered the UNO from a powered USB hub. By disconnecting the hub and connecting the UNO directly to the laptop, no more locked processor.

This was an eye-opener, I have all kinds of stuff connected to the hub, an external USB hard-disk as well which is my backup disk. Maybe I should get a better quality hub …

Thanks for your effort, Nick.

Maybe I should get a better quality hub ...

Yes, the mind boggles. :slight_smile:

Thanks for your effort, Nick.

You are welcome.