Sign in to follow this  
cragjumper

How to both stream and log duty cycle calculations as well as raw measurement

Recommended Posts

Hi all,

I've got my U3 measuring duty cycle using Timer0 and Timer1. Since I'm streaming the data, I've set up the configuration using sequences and setup four channels to read Channel 200, 224, 201, 225. I'm confident that I have the streaming working properly and am able to log the raw data (which consists of 4 elements - the LSW,MSW of Timer 0 and LSW,MSW of TImer1) without any issues. However, I'd rather not have to calculate the duty cycle for tens of thousands of points from the raw data for every one of my log files in excel.

As such, I've been able to calculate the duty cycle within DAQFactory using both virtual channels and test channels. In my virtual channel, I've simply written the expression to calculate the duty cycle using the results of my data channels. My test channels receive the results of those same expressions from the Event tab of channels 224 and 225 using the AddValue command. So, I feel I can successfully calculate duty cycle values using two different methods. However, the issue is in trying to correctly log them.

1) From what I've read, I believe logging will not work with virtual channels, and as such must be recorded using export. However, I think export only exports the history of the channel, so if you happen to exceed the history, you'd be losing data. Is there another way to use Virtual Channels to actually log, rather than export, data?

2) When using the event tab of channel 224, I use the following expression to calculate duty cycle from the raw data for the LSW and MSW:

DutyCycle_Calc.AddValue(DutyCycle_LSW/(DutyCycle_LSW+DutyCycle_MSW)*100) where DutyCycle_Calc is my test channel.

When I use this form, nothing is logged from DutyCycle_Calc. However, if I use this expression instead:

DutyCycle_Calc.AddValue(DutyCycle_LSW[0]/(DutyCycle_LSW[0]+DutyCycle_MSW[0])*100)

I log a duty cycle value every few milliseconds but have a large number of raw data logged in between. I believe this is because the event is only being triggered when the packet from the streaming is written, and since the [0] only looks at one element of the package, only one piece of data from the packet is used to calculate a duty cycle.

Is there a way to record a calculated DutyCycle for every piece of raw data that was streamed within a packet and have it logged?

3) On an unrelated note, does the channel # of a test channel matter? Or can these be arbitrarily set? Honestly, I'm still not clear on how to use test channels properly and couldn't find any direct explanations in the DAQFactory Manual. Any pointers to references would be greatly appreciated.

If there's an easy and obvious answer to any of these questions (calculate in sequences and then somehow log the values?), I apologize, but I'd really appreciate some help either way, as I've really put a lot of time into figuring this out and haven't found a solution yet.

Cheers!

Share this post


Link to post
Share on other sites

1) no, logging sets only work on regular channels

2) Doing complex calcs on streaming data is a bit challenging in DF, you basically have to do what you are doing in the event, but cycle through the entire block that just came in so you don't miss values. To do that, you have to record the time of the last block. Its something like this:

In an AutoStart sequence:

global lastTime = systime()

// start stream sometime after this

In the event:

private theTime = systime()

private DC_LSW = DutyCycle_LSW[lastTime, theTime]

private DC_MSW = DutyCycle_MSW[lastTime, theTime]

dutyCycle_calc.addValue(DC_LSW/(DC_LSW + DC_MSW) * 100)

lastTime = theTime+0.001

BTW: that's a pretty weird calc for lsw/msw, but if it works...

This will work as long as the event is triggered more than once a second. Note, you might need to change the 0.001 to something smaller if your stream rate is > 1000hz.

3) The test channel # only matters if you have any test channels with timing other than 0, in which case they need to be unique. If they are all Timing = 0, then it does not matter. There is no direct explanations in the docs, because Test channels were designed really just for testing, but have become a great way to store calculated data in a way that works like a channel.

Share this post


Link to post
Share on other sites

Thanks for the response! I actually just saw it today - for some reason, I missed the notification that I got a reply, and happened upon my own post today while looking up another issue.

Just wanted to share what I figured out to resolve the issues that I posted those few months ago:

2) With regards to doing calculations on streamed sets of data, what worked for me was simply creating a V channel and inserting the expression (Streaming_LSW/ (Streaming_LSW+Streaming_MSW)) * 100, where Streaming_LSW and Streaming_MSW are the channels receiving the streamed LSW and MSW for the timer in duty cycle mode. This automatically calculated the duty cycle using the data in the two streamed channels. Albeit, this limits you to only the data in the history, for me that was enough since my test was short. I then simply exported the Vchannel.

As for the calc for duty cycle, I thought LSW = Signal High time, MSW = Signal Low time, hence duty cycle = high time / total time, where total time = LSW+MSW?

Share this post


Link to post
Share on other sites

Hi, yup, that's what the script says, but I was responding to the comment "BTW: that's a pretty weird calc for lsw/msw, but if it works..." from the August 14th post - I thought you were referring to my duty cycle calc.

Share this post


Link to post
Share on other sites

I don't remember what I was referring too. Probably the fact that MSW and LSW typically mean Most Significant Word and Least Significant word, as often used when describing word ordering in Modbus communications. In that case, the conversion is MSW * 65536 + LSW.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this