Pages: 1 [2]   Go Down
Author Topic: Arduino Pro and Anemometer (Reading Pulse Times)  (Read 3518 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay so I restructured my code. I thought with the high rate of interrupts going in my program there would be inconsistencies with interpreting the data.

I restructured it to go through 10 cycles and averaging the data being outputted.

I am noticing that my output in binary is inconsistent with the number of bits being outputted. Sometimes I would get 9 bits/11 bits outputted to the serial monitor. Since I am using long unsigned integers, does the arduino ignore the rest of the 32 bits if the bits are 0? or is it more likely that my bits are being cut short with an interrupt each time I'm printing out.

I'll give you an idea with what I am seeing.

Right now I am printing only my period and my difference in time on the same line.
Quote
I Want to get around
440 270
for my two printed values
Quote
In Decimal I'm Getting
6405 312
545 273
5212 276
657 328
650 325
449 313
Quote
In Binary I'm getting
111010010 100000001
110110010 11110000
110111011 100000101
110011010 11110110
110110100 100011100
110101011 100110001
111111111 101110100
110110101 110010100
110110000 101010100
Code:

Right now I am printing two variables on one line. In the end I want to be able to print three variables on one line.

Does my loop function look too long? Am I trying to output too many bits at once? Are my interrupts affecting the data outputted?

What I am trying to look for is consistency (+/- x) within the outputted data and need some advice on whats going on.
Logged

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

Here is my loop function.

Quote
void loop()
{
    Speedvalue = digitalRead(digitalSpeed);       // Read the input pin at 2
    Directionvalue = digitalRead(digitalDirection);    // Read the input pin at 3
   
    // Anemometer has to go through N rotations before calculating
    if (count >= N)
    {
        //Calculating Speed Duration
        SpeedPeriod = (millis() - SpeedTimePrevious);
        SpeedTimePrevious = millis();
       
        loopcounter++;  //Count itterations
       
        if(loopcounter==1)  //First itteration
        {
            SpeedTimeRising = SpeedTimePrevious;
        }
        if(loopcounter==2)  //Second itteration
        {
            SpeedPeriod= SpeedPeriod/N;     
            //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
            loopcounter=0;
           
        }
     
    count = 0;
   
    }
   
   
    if ((SpeedTimeRising  >  DirectionTimeRising)  && (directioncount >= ((2*N))))
    {
        DirectionTimeRising = millis();
        directioncount = 0;
        // Calculates time difference between SPEED and DIRECTION signals
        TimeDifference = (DirectionTimeRising - SpeedTimeRising)/((2*N));

        //Value of Direction
        Directionvalue = (360*TimeDifference)/SpeedPeriod; //Finds Angle of Wind Vein
        /******************************************
        //   Printing SPEED, DIRECTION, TIME   //
        *****************************************/
        Serial.print(SpeedPeriod, DEC);
        Serial.print(" ");
        Serial.print(TimeDifference, DEC);
        Serial.println();

    }
   

}
Logged

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

Did you ever get this working?

I'm just starting down this exact path now.
I do have a datasheet from Ultimeter showing their calibrations for revs per seconds to speed.

I've got the speed happening quite easily, but now to work on the direction component.
Logged

Pages: 1 [2]   Go Up
Jump to: