I am working on a project where I am trying to get an input signal filtered according to its frequency. I checked the signal before it went into my DSP algorithm to see where the problem was and I found that the frequency was remaining the same no matter if I put in 30Hz 120Hz or 58kHz. This leads me to think I have a problem with the sampling rate. Does that sound like it is the actual issue? Or am I barking up the wrong tree?

I was just using the readADC command to read in the data

void setup()          //Setup Function to intialise ADC and Serial Communication
DDRC=0x00;            //PORTC as INPUT
DDRD=0xFF;            //PORTD is OUTPUT
  • 3
    How exactly are you sampling the signal? It would help if you can show the circuit and source code. Jul 2, 2014 at 22:10
  • 2
    post your entire code Jul 13, 2014 at 12:50
  • 1
    Could you trim down your program to a short program that demonstrates the issue, and then post the complete program? I see you posted a "setup()" routine, but a complete Arduino program also has a "loop()" routine.
    – David Cary
    Nov 10, 2014 at 15:22

1 Answer 1


I am not sure how you are sampling the frequency because you have not shown us your code.

At work we use a ATMega328P to sample frequency. This is done in 2 different ways:

  1. We use the pin that counts (using an internal counter) every time it transitions (ie from low to high and from high to low). After 1 second that counter is read and then that counter is cleared. With the number read in, it is divided by 2 to get the frequency.
  2. We use another pin that counts every time it transitions from low to high. From memory the counter is not very large so we count the number of times it overflows. When the 1 second interrupt fires we multiply out the number of overflows by the counters capacity. Lastly the remainder from the counter is added to the result to get the frequency. Again the counter is cleared.

The above examples use the AVR's internal counters. A less efficient way of getting the frequency is to have an interrupt to count the number of times a pin changes. Again this can be read and reset at one second intervals. This slows the overall execution of the program down when very high frequencies ( > 40K Hz) are being presented on the input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.