Pages: 1 2 [3] 4 5 ... 9   Go Down
Author Topic: Is this work for frequency counter  (Read 5246 times)
0 Members and 1 Guest are viewing this topic.
Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

here is a "peak detector":
http://www.falstad.com/circuit/e-555monostable.html
(it works better than my RC-plan) :-)

but u need the negative part of ur AC signal... so u dont need any rectification, because of the horizontal capacitor...

for a 3.2kHz signal the horizontal capacitor should be 100nF and the vertical cap should be 150nF...

-arne
« Last Edit: May 03, 2010, 04:08:53 pm by RIDDICK » Logged

-Arne

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You also need to ensure the voltage on the Arduino input pin does not exceed 5 volts. There are many ways to do that, for example using a transistor (Grumpy_Mike explained this your “DC to the Arduino” thread) or you could use an opto-isolater.

oh
that's great, i am going to try this
let see what we can see

Quote
here is a "peak detector":
http://www.falstad.com/circuit/e-555monostable.html
(it works better than my RC-plan)

but u need the negative part of uc AC signal... so u dont need any rectification, because of the horizontal capacitor...

for a 3.2kHz signal the horizontal capacitor should be 100nF and the vertical cap should be 150nF...

-arne

Thanks for your advise, but i don't know about 555 timer, it is kind of difficult smiley-sad
i will try it anyway, thanks
let see what it can show me smiley
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

u could try this, too:
http://arduino.cc/en/Reference/AttachInterrupt
the short peak should trigger the interrupt safely...
then u just measure the time between the interrupt calls...

but looking for a peak should be good, too:
Code:
const uint8_t pin = 5; // digital pin #5
void setup() {
  Serial.begin(115200);
  pinMode(pin,INPUT);
  digitalWrite(pin,HIGH); // pullup
}
void loop() {
  uint32_t sts = micros(); // start time stamp
  const uint32_t c = 1000; // wait for 1000 pulses
  for (uint32_t i=c; i>0; i--)
    pulseIn(pin,HIGH);
  uint32_t ets = micros(); // end time stamp
  Serial.println(c*1e-3/(ets-sts)); // output kHz
}

this circuit should be good in order to protect ur arduino:
AC signal ---- diode anode
diode cathode ---- 100k resistor lead A
100k resistor lead B ----- NPN transistor base
NPN transistor emitter ---- arduino ground
NPN transistor collector ----- resistor 1k lead A
resistor 1k lead B ------ arduino pin #5

dont forget this:
external circuit signal ground ----- arduino ground
(but make sure that this doesnt cause a short circuit (e. g. when the external circuit uses USB 5V as ground and USB ground as -5V power supply)... :-)

-arne
« Last Edit: May 03, 2010, 04:29:22 pm by RIDDICK » Logged

-Arne

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

oh
this
Code:
Serial.println(c*1e-3/(ets-sts));
should be this (because ets-sts r _u_secs)
Code:
Serial.println(c*1e3/(ets-sts));

:-)

-arne
Logged

-Arne

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HELP!! smiley-sad
this code below still could not show the frequency. it keeps showing a number, god knows where it comes from. the number is around 45.19

whether there is sensor connecting to the analog or not

Code:
int analogPin = 1; //sensor input is analog pin 1
int val = 0 ;
long timeStart, timeStop;
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


void setup() {
  pinMode(analogPin, INPUT);
   lcd.begin(16, 2);
  Serial.begin(9600);
  
}

void loop()
{
  
val = analogRead(1);     {
      if (pulseIn(val, HIGH)); {
        // wait until pin goes high
       timeStart = micros();
        // wait until input goes low again
        while (pulseIn(val, LOW) ); {
        // take the actual time in microseconds
        timeStop = micros();
        // the timedifference is the the time between two rising
        // edges of the input pin (= 1 period)
        int timeStart1 = timeStop-timeStart;
        // normally the result is > 0, otherwise the
        // function micros() had an overflow (every 70 min)
        // the discard this measuring (or correct the value)
        if (timeStart1 > 0) {
          // calculate frequency
          // 1000000 microseconds/second, f = 1/t
          double f = 1000000.0/timeStart1;
          // report the measured frequency
          lcd.println(f);
          delay(1000);  
          lcd.clear();
         }
      }
      }
}
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop()
{
val = analogRead(1);     [glow]{[/glow]
What's this curly brace for?
Code:
     if (pulseIn(val, HIGH))[glow]; {[/glow]
Are you sure you want that semicolon there?
Code:
       // wait until pin goes high
       timeStart = micros();
        // wait until input goes low again
        while (pulseIn(val, LOW) )[glow];[/glow] {
What about this one?

The pulseIn function returns a value. The value is how long it took the pulse to go HIGH or LOW. You will get misleading results if you do not use that time.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul
i have cancelled all the ";"
however, it still keeps showing me a number
it is much larger, around 30-900
what did i do wrong smiley-sad ?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i have cancelled all the ";"
Well, that probably wasn't the greatest idea.

Post your current code.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here it is
thanks
Code:
int analogPin = 1; //sensor input is analog pin 1
int val = 0 ;
long timeStart, timeStop;
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);


void setup() {
  pinMode(analogPin, INPUT);
   lcd.begin(16, 2);
  Serial.begin(9600);
  
}

void loop()
{
  
val = analogRead(1);  
      if (pulseIn(val, HIGH)){
        // wait until pin goes high
       timeStart = micros();
        // wait until input goes low again
        while (pulseIn(val, LOW) ) {
        // take the actual time in microseconds
        timeStop = micros();
        // the timedifference is the the time between two rising
        // edges of the input pin (= 1 period)
        int timeStart1 = timeStop-timeStart;
        // normally the result is > 0, otherwise the
        // function micros() had an overflow (every 70 min)
        // the discard this measuring (or correct the value)
        if (timeStart1 > 0) {
          // calculate frequency
          // 1000000 microseconds/second, f = 1/t
          double f = 1000000.0/timeStart1;
          // report the measured frequency
          lcd.println(f);
          delay(1000);  
          lcd.clear();
         }
      }
      }
}

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please read this:
http://arduino.cc/en/Reference/PulseIn

The first argument to pulseIn is the pin to measure, not some value read from that pin.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The first argument to pulseIn is the pin to measure, not some value read from that pin.

umm
so i am just giving a pulse to the pin, not reading it?

how can i read pulse  smiley-sad ?
« Last Edit: May 10, 2010, 03:40:25 am by max88poon » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where is the pulse coming into the Arduino? To some pin, presumably. Pass that pin number to pulseIn.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where is the pulse coming into the Arduino? To some pin, presumably. Pass that pin number to pulseIn

i think that is digital 8 or 9
when i took out the digital 8 and 9, the screen show me nothing
but how to pass the pin ?
there should be no pulse in the first place, due to the fact that i didn't connect the sensor output to the arduino
however, it keeps showing a number , i don't know what the pulse is

i am sorry about that Paul, that i was off, it's because i gotta be out of the school, i am home now, and thanks, please keep talking to me smiley-sad

could some one guide me to do the program?
i very appreciate it, it is my final project, i may not get a pass if i couldn't do it smiley-sad
« Last Edit: May 10, 2010, 06:43:36 am by max88poon » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah
hey guys, i found something
there is nothing shown, if the arduino analog 0 is connected to the LCD analog 0
if i took out the analog input, the number is coming out again.
someone know what is happening smiley-sad ?

could anyone help me checked the program, is it correct that
the frequency can be determinated from the analog pin 1 ?
and the pin 1 is connected to the sensor.

Thanks everyone smiley
Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if the arduino analog 0 is connected to the LCD analog 0

What sort of LCD are you using that has an analogue input?

Quote
the frequency can be determinated from the analog pin 1 ?
Analogue pin 1 (what's wrong with analogue pin zero?) can be used with "pulseIn", but you have to number it as a digital pin in your sketch.
It's digital pin 15.
« Last Edit: May 10, 2010, 07:07:07 am by GrooveFlotilla » Logged

Per Arduino ad Astra

Pages: 1 2 [3] 4 5 ... 9   Go Up
Jump to: