I would like to know if any of the ATmega328 pins can read 180Hz at less than 200mV with the appropriate code written.
I'm testing the Nano with code shown below, using a signal generator with sin wave at 180Hz. With the serial monitor open the Nano will only start giving a reading over an output of 2.80V on PD5.
Space is going to be tight so I need to keep the PCB small. I would like to use as little components as I can and this is the first time I'm going to give it a go at making a PCB with an ATmega328. I've done one with a Tiny85's and it was really fun.
#include <FreqCounter.h>
int cnt;
unsigned long frq; //Declares an extended size variable for the measured frequency
void setup() {
Serial.begin(9600);
}
void loop() {
FreqCounter::f_comp=10;
FreqCounter::start(1000);
while (FreqCounter::f_ready == 0)
frq=FreqCounter::f_freq; //Sets the 'frq' variable as the measured frequency
Serial.println(frq);
The end result is the finished code counting the pulses
unsigned long
so say over 1 minuet at 180Hz, so that will be 180X60 = 10,800 counts?
What exactly do you mean by "read 180Hz at less than 200mV"? Do you just want to detect whether the signal is present? Or read its amplitude? Or its frequency? Or both?
Depending on what you need, there may be options that do not require an external op amp, such as:
Use the analog comparator that is built-in to the atmega328p. This will allow you to detect whether the signal is present and read its frequency, but not its amplitude. There are libraries available to control the analog comparator, e.g. see http://forum.arduino.cc/index.php/topic,158657.0.html.
Read the signal via an analog input pin, setting the analog reference to the internal 1.1V reference for greater sensitivity.
From your code, it looks like you just want the frequency, in which case suggestion (1) is the obvious solution.
From your code, it looks like you just want the frequency, in which case suggestion (1) is the obvious solution.
Straight to the point, yes.. The pules count can be worked out with this method as well?
I'll be using an OMLED or LCD screen to show Hz and counts, with a button to reset the count back to zero and and hold button.
The end result is the finished code counting the pulses using "unsigned long" so say over 1 minuet at 180Hz, so that will be 180X60 = 10,800 counts
TronSR:
The pules count can be worked out with this method as well?
Yes. Define an interrupt routine for the analog comparator that increments the pulse counter. To measure the frequency, there are a couple of approaches:
use timer 1 to define the length of the timing window (just like the frequency counter library does), then calculate the frequency from the change in the count between the start to the end of the window;
in the interrupt service routine, call micros() to get the current time. Save the time you read on one interrupt and again N interrupts later. Then the frequency is N divided by the difference between the two times. You need additional code to detect when the interrupts have stopped because there is no input signal.