From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating multiple timed "square waves" for digital control via user input or excel file

 Hi Everyone,

 

So (in the attached code) I previously had success setting on/off timing for valve relays via digital output using true/false case structures and wait time. Now we want to have more complex patterns for water valve spray timing and this does not seem feasible with the methods I have been using. 

 

The desired timing output would be to have two separate phases of repeating on/off timing followed by a wait/dwell time, the length of each part being either adjustable by the user or read in by a file of some type. So, the 1st phase might be on for a half second, 1 second off, then wait 3 seconds, repeating the entire thing for ~30 seconds. 2nd phase would be something similar and would happen when the first phase is done. Since we want so much variability, simply generating two square waves won't work to my knowledge. 

 

If we were to go the file input route, I'm thinking it would just be a list of timings that would be used to generate output to the daq assist. I'll attach an example file later on when I get it. 

 

Some data acquisition will be running in the background, but that can just run in the main loop. 

 

The concept isn't that difficult, I'm just not sure where to move forward with having 4 adjustable inputs that need to loop like that

0 Kudos
Message 1 of 3
(2,383 Views)

Someone more experienced than I will probably see this and say "Oh, that's a Frebroz Code", but it sounds to me like you may want to consider a Completely Flexible (Recursive) System, which will have a defined Grammar and a Parser.  Let me try to explain (warning -- I'm neither an Engineer nor a Computer Scientist, so my terminology may be really wrong ...).

 

The basic Building Block, it seems to me, is a Pulse, defined as having an On-Time and an Off-Time.  I'm going to use the convention Pn (where "n" is a number) to mean a Pulse, perhaps saved (in LabVIEW) as a Cluster of OnTime and OffTime).

 

You define as many pulses, P1, P2, P3, etc. as you need.

 

Next, consider a Sequence, Sn, which can be one of the following forms:

  • Sn = Pn, the sequence consists of a single pulse, Pn (i.e. P1, P17, etc.)
  • Sn = Sa + Sb (Sequence Sa followed by Sequence Sb)
  • Sn = 5*Sa (a repetition of Sequence Sa 5 times)

The second two rules allow you to create a sequence of different Pulses (since a single Pulse is also a Sequence) and trains of Pulses/Sequences.  You need to be a little careful not to define a sequence in terms of itself, but a general structure like this could easily define (any?) finite Sequence that you might need, and also would allow (given the Sequences and their Definitions) an "interesting exercise" to write code that would take such a definition and produce the resulting Pulse Train.

 

Here's an example:

  • P1 = 1 second on, 1 second off
  • P2 = 2 seconds on, 2 seconds off
  • S1 = 5 * P1 + 2 * P2, a train of 5 P1 pulses followed by 2 P2 Pulses
  • D1 = Delay 1 (I forgot to add this, above), Delay 10 seconds
  • S2 = S1 + D1 (Do sequence S1, then D1, wait 10 seconds).
  • S3 = 10000000 * S2, a very long series of S2 sequences

You could easily put this in an Excel Spreadsheet or a Text File, read and parse it, then execute whatever sequence you specify.

 

Bob Schor

0 Kudos
Message 2 of 3
(2,342 Views)

Thanks for the in depth reply, Bob.

 

So we do have an excel sheet of on/off time with respect to elapsed time. Could the 0(off) / 1(on) column be read into labview along with the time column to create a waveform that would then output a signal to the digital output? Generating the on/off timing in Excel like this and reading in the columns may be the easiest solution. I will mess with the waveform generator and see what I can do. 

0 Kudos
Message 3 of 3
(2,329 Views)