Go Down

Topic: Arduino Pro and Anemometer (Reading Pulse Times) (Read 3 times) previous topic - next topic

PaulS

#10
Mar 09, 2011, 04:14 pm Last Edit: Mar 09, 2011, 04:19 pm by PaulS Reason: 1
Code: [Select]
Speedvalue = (1492*3600000/SpeedDuration);  
1492 and 3600000 are treated as ints. 1492 is an int, but 3600000 is not. You should have a L or UL at the end, to tell the compiler to treat the value as a long or unsigned long.

Code: [Select]
int analogSpeed = 0;             //Speed bus connected to analog pin 0
int analogDirection = 1;          //Direction bus connected to analog pin 1

Speedvalue = digitalRead(analogSpeed);       // Read the input pin at 0
Directionvalue = digitalRead(analogDirection);    // Read the input pin at 1


Are you using the digital pins, so digitalRead is appropriate, or the analog pins?
If you are using digital pins, 0 and 1 are not good choices while doing serial I/O.
If you are using analog pins, you should be using the analogRead function.

DynamiK

#11
Mar 09, 2011, 08:23 pm Last Edit: Mar 09, 2011, 08:27 pm by DynamiK Reason: 1
Quote
1492 and 3600000 are treated as ints. 1492 is an int, but 3600000 is not. You should have a L or UL at the end, to tell the compiler to treat the value as a long or unsigned long.


Are you implying that I store the 1492*3600000 as 5371200000 in another UL variable and hash out my math in explicit UL variables?

Quote
Are you using the digital pins, so digitalRead is appropriate, or the analog pins?
If you are using digital pins, 0 and 1 are not good choices while doing serial I/O.
If you are using analog pins, you should be using the analogRead function.


Sorry those were poor name choices for variables. Since the input were square waves, I decided to have them be digital inputs. Originally they were supposed to be analog inputs at pins 0 and 1, but I changed it to digital pin 2 and 3 and forgot to change my comments/names.


On another note, I am trying out a debounce circuit on my input to help clean out my input. That could be a source of error when reading in my data.

DynamiK

I added a debouncing circuit (RC) to my reed switch. My voltage dropped but the results did not change at all. Anyways I thought I'd share what I was seeing on the oscilloscope and the computer.

Time between Directional signal rising


I'm getting a time that's within 700ms. (I checked over a course of 10 impulses that were printed)

Some delay was expected...but not like this...

Here are the relations that I received using the picture above





Computer DataOscilloscope Data

Speed Period: 763 ms
Time Difference: 162 ms 
Direction Period: 766 ms   
Direction: 76 degrees

Speed Period: 580 ms
Time Difference: 260 ms
Direction Period: 560 ms
Direction: 167 degrees


Again I am calculating my direction value with
Quote
Directionvalue = 360*TimeDifference/DirectionPeriod;


It makes sense that the period of the speed and the direction are the same since the rotation of the axis hits the 2 reeds at the same time.

DynamiK

#13
Mar 12, 2011, 03:08 am Last Edit: Mar 12, 2011, 03:11 am by DynamiK Reason: 1
I cleaned up the code a little bit to get rid of some redundancies in the old code.

I am noticing the following:

1. My Time Difference is always the same no matter what angle I move my anemometer.

It makes me wonder if I am even making it to that part of the code to update my software or if the program is reading my square waves correctly.

2. I have my sensor set up to a fan that gives my cups 154 rotations per minute, which give my code 308 interrupts per minute.

I read that the millis() function acts as an interrupt as well. I referr to millis() at lease 4 x in my loop function.

That mixed in with the number of interrupts I am getting, will I be able to  make it though my loop function to update my data correctly?

Another question: How much voltage does it take to trigger a rising interrupt? I have very minimal noise on my signal when it is on/off. I'm not sure if this is a problem as my timing to measure my distance between rising edges on 1 signal is off from the oscilloscope readings.

Quote

void loop()
{
Speedvalue = digitalRead(digitalSpeed);       // Read the input pin at 2
Directionvalue = digitalRead(digitalDirection);    // Read the input pin at 3

if (count >= 1)
{
   //Calculating Speed Duration
SpeedPeriod = (millis() - SpeedTimePrevious);
SpeedTimePrevious = millis();
count = 0;

}

Serial.print("Speed Period: ");
Serial.println(SpeedPeriod, DEC);

//Value of the Speed
SpeedDistance = 60000*45;                                // 4.5 ft * 60,000 ms/min * 10 scaling factor
Speedvalue = (SpeedDistance/(10*SpeedPeriod));   // Finds speed of cup rotation in ft/min
                                                       // ft * (ms/min) / ms = ft/min
                                                       //divide 10 scaling factor back out

if ((SpeedTimePrevious  >  DirectionTimeRising)  && (directioncount >= 1))
{
DirectionTimeRising = millis();
directioncount = 0;
}

// Calculates time difference between SPEED and DIRECTION signals
if (DirectionTimeRising > SpeedTimePrevious )   // Ensures that Direction must occur second
{
TimeDifference = (DirectionTimeRising - SpeedTimePrevious);
}
Serial.print("Time Difference: ");
Serial.println(TimeDifference, DEC);

//Value of Direction
Directionvalue = (360*TimeDifference)/SpeedPeriod; //Finds Angle of Wind Vein


wildbill

I am wondering whether your use of Serial.print is impacting your times. I assume that the UART will buffer the text to some extent, but since you're sending around 30 characters each iteration of the loop, you may be getting delayed by that.

Also, you might get a bit more accuracy on the speed if you collect a few more interrupts (10?) before calculating the time difference

Go Up