Go Down

Topic: Read pulse Wind sensor (Read 1 time) previous topic - next topic

sirus

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!

MarkT

#1
May 16, 2012, 01:02 am Last Edit: May 16, 2012, 01:04 am by MarkT Reason: 1
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?
[ I won't respond to messages, use the forum please ]

sirus

#2
May 16, 2012, 01:34 am Last Edit: May 16, 2012, 01:36 am by sirus Reason: 1
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!

sirus

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!

MarkT

Code: [Select]

volatile int count = 0 ;


and in the ISR do:
Code: [Select]

  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: [Select]

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: [Select]

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 ...
}
[ I won't respond to messages, use the forum please ]

terryking228

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.
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

sirus

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

sirus

#7
May 25, 2012, 01:14 am Last Edit: May 25, 2012, 01:53 am by sirus Reason: 1
Ok i've found something about my problem!
here is it:
Code: [Select]

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!

pwillard


sirus

#9
May 25, 2012, 07:12 pm Last Edit: May 26, 2012, 10:01 pm by sirus Reason: 1
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???

Go Up