Pages: [1]   Go Down
Author Topic: Read pulse Wind sensor  (Read 1211 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody!I would like to have your help for one more time...!I want to read wind sensor's value as pulse with the Arduino Mega 2560.Is there a way that i could find where this interrupt triggers?
I don't know lots of things about this so i want your light about it...

Someone told me that something like that will be done from the ISR!But some information more please about it???

In other word i want something like this below:
For some time e.g 1sec ..., i want to read pulses!Did you know a way that i should do something like that??

Thanks a lot!
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10520
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you want to time the width of pulses or count them ?

Also you are aware that the interrupt pin mapping is different on the Mega from the regular Arduinos?
« Last Edit: May 15, 2012, 06:04:06 pm by MarkT » Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually both of them!But the counting ist the most important for me!
Is there something which corresponding to this situation?How you got something in your mind about it??


Thanks!
« Last Edit: May 15, 2012, 06:36:15 pm by sirus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello every body!I've done a question!At least is there something which counting pulses in ISR of Arduino Mega?
An example or something that someone have done it??Please i want your help...

Thanks!
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10520
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
volatile int count = 0 ;

and in the ISR do:
Code:
  count ++ ;

When reading this variable outside the ISR you'll have to read it twice and check it hasn't changed inbetween since a variable of more than one byte will not be updated atomically, something like
Code:
int readCount ()
{
  int first = count ;
  int second = count ;
  while (first != second)
  {
    first = second ;
    second = count ;
  }
  return first ;
}

Or you can disable interrupts around the read of the variable.

Then to prevent problems with setting it to zero, you can always use  the difference between successive readings:
Code:
int lastCount = 0 ;
void loop ()
{
  ...
  ...
  int this_count = readCount () ;
  int count_since_last = this_count - last_count ;
  last_count = this_count ;
  ... use count_since_last ...
}
Logged

[ I won't respond to messages, use the forum please ]

Topsham, Vermont USA
Offline Offline
Edison Member
*
Karma: 24
Posts: 1766
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some information on an anemometer that I've used is here: http://www.nrgsystems.com/sitecore/content/Products/1901.aspx

It's information on frequency VS wind speed may be close for what you have, or maybe off by 2:1 depending on how many pulses per revolution.
Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any example or something which someone had done it, in order to solve my problem?I want only to count pulses by providing signal on input with a function generator!

In every second i want to count pulses!!That's only...!

Thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok i've found something about my problem!
here is it:
Code:
unsigned int count;
unsigned int getCount() {
   TCCR1B= 0 ; // Gate Off / Counter Tn stopped
   count = TCNT1;
   TCNT1 = 0;
   bitSet(TCCR1B ,CS12); // Counter Clock source is external pin
   bitSet(TCCR1B ,CS11); // Clock on rising edge
   bitSet(TCCR1B ,CS10); // you can clear this bit for falling edge
   return count;
}
void setup()
{
   Serial.begin(9600);
   digitalWrite(5, HIGH);

   // hardware counter setup (see ATmega data sheet for details)
   TCCR1A=0; // reset timer/counter control register A
   getCount(); // this will start the clock
}
void loop()
{
   delay(1000);
   Serial.println(getCount());
}
I  want to count pulses every minute.I run this code in Arduino and with a function generator from pc i tried to send signals with different frequence.The problem is that when i change the frequence the Arduino could not response to up and down to the number of pulses.I'm very confused.Could you help me with this code please??

Thanks in advance!
« Last Edit: May 24, 2012, 06:53:49 pm by sirus » Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 18
Posts: 1628
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not use this link for some guidance...

http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 42
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm newbie and as i understand from this link, you count only frequency.That's not my problem...

My problem is that when i change the frequency with a function generator, then propably should change the number of pulses per seconds too.

Thanks a lot!
Any idea please???
« Last Edit: May 26, 2012, 03:01:23 pm by sirus » Logged

Pages: [1]   Go Up
Jump to: