03-24-2011 04:25 AM
Hello! I have to build an application that follows these steps in the specified order:
1. Create a task that writes a digital value ('1' or '0') on digital line1 of a NI-6723;
2. Create a task that generates one clock pulse on line0 of the same board. So, after the line value of line0 has been set, a transition from '0' to '1' and, after that, from '1' back to '0' has to be made on line0.
So, I have the following pseudocode:
1. Create Task1
2. Create digital output channel "Dev1/port0/line1"
3. Write data bit ('0' or '1') on digital line1
4. Stop & clear Task1
5. Create Task2
6. Create digital output channel "Dev1/port0/line0"
7. Write data bit '0' on digital line0
8. Write data bit '1' on digital line0
9. Write data bit '0' on digital line0
10. Stop & clear Task2
After I stop & clear Task1 (Step 4), the digital line1 remains in the state that Step 3 induced. But, after I create a digital channel for line0 (Step 6), line1 gets back in the initialization state (high state - because of the weak pull-up), so when Task2 generates the clock pulse on line0, the data bit written on line1 is compromised (it will always be '1')!
My question: should I move Step 4 after Step 10? I mean stopping and clearing Task1 to be made AFTER Task2 had been stopped and cleared?
Does this ensures that line1's value remains unchanged until the end of the whole application (after Task2 completes)?
Please help me!
Solved! Go to Solution.
03-25-2011 01:17 PM
Clearing the task releases any resources associated with the device, so it is not surprising that it can go into an unknown state in between. It seems like you want one task, which will allow you to access both board lines, and then perform your different operations in series accordingly.
03-25-2011 01:36 PM
I see your point, but if I will create just one task that will write both lines simultaneously, I think there might be a problem: I've mentioned that line1 (the data line) has to be set before the clock pulse generation on line0. So, if I will try to write 1,0 on line1,line0... after that, 1,1 on line1, line0 and, finally, 1,0 on the same line1, line0 .... is there any chance that a glitch may appear when writing consecutive '1''s on line1 ?? I want to be a constant '1' (or '0', by chance) on line1 while line0 receives '0', '1' and '0' again... glitches aren't welcome anyway!! What do you think?
03-28-2011 10:47 AM
This is where the natural structure of dataflow will help a lot. Most of the VIs should have error terminals, but any wire will ensure that the previous VI will execute before the second VI. You can branch logic, and this will be where you need to be careful, because you do not want to have two parallel branches writing data to a channel at once. If you have one branch for one channel and one branch for a second channel, then there will be no problem with resources.
If you want two or more separate branches to write to the same resource, you will need to have some mechanism for ensuring that there are no current writers to the resource when the code attempts to write data. One common method is using semaphores, which is a deisgn template that ships with your LabVIEW.
04-01-2011 12:23 PM
Create a task that writes to both lines, then create a wrapper subVI that uses an uninitialized shift register to store the current value of each line and then writes to the task.(see attached screen shot)
The SubVI would have the standard task and error inputs and outputs then then two other inputs:
Action: Which sets up which channel you will update
Value; New value of the channel of interest
You can update channel 0 as often as you want and channel 1 will not change and vice versa.
Katya
04-01-2011 03:45 PM
Thank you for you help, Katya (and Big Cheese)! But I don't use LabView. I have to use LabWindows/CVI to do this job. Can you show me the functions list that I should use?
04-01-2011 04:42 PM
OK, don't know the exact calls in labwindows, the easiest thing might be to create a tast to write to the complete port.
In that case you are writing to each line for the 8 lines in the digital port at the same time.
Use is some form of a variable (U8) and associated function that can mask and update individual bits in a U8 number
I am assuming there is some form of doing a bit-wise OR or AND function to mask the bits of interest
1 Create variable (U8) = b0000000
2. Create Task1
3. Create digital output PORT "Dev1/port0"
4 Update line 1 with 1 in variable: 00000010 (This will have to be a routine you create-see crude example below)
5. Write variable to Dev1/port0
6 Update line 0 with 1 in variable: 00000011
7. Write variable to Dev1/port0
8 Update line 0 with 0 in variable: 00000010
9. Write variable to Dev1/port0
10. Stop & clear Task1
Function UpdateVariable (line; value; variable)
If line= 0 then
if value = 0 then
variable = variable AND b11111110
else
variable = variable OR b00000001
else if line=1
if value = 0 then
variable = variable AND b11111101
else
variable = variable OR b00000010
Hope that helps
Katya
04-02-2011 05:41 AM - edited 04-02-2011 05:43 AM
Thank you for your time and help, Katya! So, after I studyed your pseudo-code (and function code bellow), I understand that writing the same value ('1' in this case) to line 1 several times (3 times here) does not imply the apparition of glitches (some sort of spikes when a required output value is updated). I mean that if I set '1' first time, it will be a constant '1' even if I will write the same value on that line sever times (no interruption will appear). Please excuse my English, I'm from Romania and my language is very different than English :).