Logging Period From Timer


tomtar

Recommended Posts

My programing skills are close to zero hence i believe the below issue i have is straight forward for advanced users.

 

 

I would like to logg RPM through my LabJack using a hall sensor.

 

I have based my RPM measurement setup on timer setup example:  U3_Timers_Counters_Sequence.zip

 

My hall sensor gives voltage change as expected.

 

I can display the variable and convert to RPM through: (1 / period[0] * 1000000) * 60

 

The problem i have is that i do not know how to log the output of my hall sensor or to be precise i do not know how to log the period of the timer.

 

I have created a virtual channel: speed that converts the period to rpm so i can display the speed on my results page, but the graph i have do not display the v.channel.speed and also i do not have the option to logg the v.channel.speed.

 

I can manually add the v.channel.speed to logging data set but data points are not exported to file.

 

Can someone please help out with my issue?

 

I have attached my DQF project file.

 

Thanks in advance.

 

Tom

 

 

 

 

Flow test_1.ctl

Link to comment
Share on other sites

You need to get your data into channels.  And I mean real channels, not V channels.

 

1) rename the global variables period and counter to periodRaw and counterRaw (in StartUp)

2) create three new channels, one called period, one called counter, and one called RPM.  They are all Device Type Test, A to D, with a Timing of 0.

3) in your read sequence, change lines 6 and 7 from @period and @counter to @periodRaw and @counterRaw

4) insert before line 8 (your delay()):

 

period.addValue(periodRaw)

counter.addValue(counterRaw)

RPM.addValue(1/periodRaw*1000000*60)

 

Then you can log the channels you created in #2.

Link to comment
Share on other sites

Thank you for help. All is working fine.

 

To get it to work i had to restart the DAQ F.

 

Few more questions:

  1. Is there a way of refreshing the entire code/setup without close/open of the DAQ F?
     
  2. How to display zero value on a RPM variable when period is = 0? Currently NaN is displayed when period = 0

    Because of the conversion from period to RPM when period equals zero the RPM varaiable includes zero in denominator and i presume this is the reason why it displays "NaN"

    I have tried putting into an period channel event an IF statement but this doesnt work:
    if (periodRaw[0] = 0)
    periodRaw = 1
    end if
    

    I have also tried putting the same IF statement directly into the read sequence but this also doesn't work
     

    while (1)
       AddRequest(ID,LJ_ioGET_TIMER,1, 0, 0, 0)  // Request a read from Timer1.
       AddRequest(ID,LJ_ioGET_COUNTER,1) // Request a read from Counter1.
       AddRequest(ID,LJ_ioPUT_TIMER_VALUE,1,0) // Reset Timer1.  This will make it return 0 until a new edge is detected.
       GoOne(ID)
       GetResult(ID,LJ_ioGET_TIMER,1,@periodRaw) // Get Timer1 read.
       GetResult(ID,LJ_ioGET_COUNTER,1,@counterRaw) // Get Counter1 read.
       period.addValue(periodRaw) 
       counter.addValue(counterRaw)
       RPM.addValue(1/periodRaw*1000000*60)
         if (periodRaw[0] = 0)
         periodRaw = 1
         end if
       delay(1)
    endwhile
    
    

Besides giving me the solution can you please add few comments why the above attampts did not work?

 

Thankyou.

Link to comment
Share on other sites

1. the problem was that you had global variable counter and period which didn't go away and overrode the channel.  You can use clearGlobals() to delete all global variables and avoid a restart.

2. yes, you have a divide by 0.  Change the expression from 1/periodRaw*1000000*60 to:

 

iif(periodRaw > 0, 1/periodRaw*1000000*60, 0)

 

The if() you made doesn't work because its after the addValue() command where you do the division.  It would work if you moved it before the RPM.addvalue() line. 

Link to comment
Share on other sites

The solution given by you obviously works. Thanks

 

Before reading your post i have found a different solution in help which also works and looks like this:

 

(1*(period !=0)/(period+(period ==0))*1000000)*60

 

 

 

I came to another challange:

 

How to record the RPM which are set up as test channel with timing 0 together with real channels with timing of 0.5?

 

I know the issue is caused by timing. My real channels have timing of 0.5 and the test channel is set to 0.

 

When logging all real channels together with the RPM test channel the RPM value does not appear in logging set.

 

When logging the RPM (test channel) separately all data are recorded at 1sec time interval.

 

How can i fix this issue?

 

I have tried exporting timing from real channel through below event in one of my RealChannels but than the RPM testChannel values are shuttered with some other numbers.

 

RPM= insertTime(RPM[0], realChannel.time[0], 0)

Link to comment
Share on other sites

Yup, that will work too, but isn't as clean to read.

 

As for your other question you have two options:

1) continue on your path of using insertTime(), but then change the Align Threshold in your logging set to something bigger, probably 0.5 or more.  You need insertTime() because otherwise you get a constant time stamp

2) move your code out of a sequence and into the event of one of your real channels at timing 0.5  Drop the while loop of course.  This will result in 0.5 second updates and all the data will align.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.