01-03-2015 09:43 AM
Hey guys,
I'm working on a research project conducted by an ENT surgeon, and as the lead engineer, my role is to design the control system being used in surgery. I've already got everything under control from a hardware perspective, but I'm having a difficult time getting Labview to play nice with my control sensor.
Cliffnotes:
Here's the product data sheet for the sensor (page 7+):
http://www.allsensors.com/datasheets/DS-0300_Rev_C.pdf
Since the myRio DAQ only supports true/false inputs, I tried storing the initilization sequence in a boolean array and then just using a shift register to index through it - but still no luck. I think part of the problem is that the DAQ is running faster than the sensor can sample, and I don't know how to send out discrete signals (or at the very minimum match the output rate to the sensor sampling rate so it appears as discrete pulses).
Thanks for the help!
01-03-2015 10:13 AM
First thing I notice when opening your data sheet is: I2C Standard Interface / SPI Interface Option
Have you looked at using either of these interfaces? Both are supported on the myRIO device.
Something you'll want to avoid doing is using the term DAQ with the myRIO. DAQ and RIO architecture are quite a bit different.
If you want to index an array, why are you using shift registers? Can you share that piece of your code? I'd expect you to either be using auto-indexed tunnels or using the iteration terminal along with Index Array to be indexing the array. It's likely that you're violating data flow and only sending a single result. Keep in mind, loops that aren't set to output arrays will only send the last data point upon completion. If you're wiring the value from the array into the shift register, you're only sending the last value out. Shift registers are used to send data from one iteration of a loop to the next iteration of the loop. They won't output their value beyond the loop until the loop is finished and will only share the last data point.
01-03-2015 10:18 AM
To be honest, I'm very new to Labview (and literally am brute forcing a lot of the constructs I've learned in either C or Matlab). I'd prefer not to put up any code just yet, as I'm legally signed to an NDA until our patent goes through. I think I could create a seperate Vi solely for the point of working with the sensor and be in the clear, but I'll ask just to be safe.
Can you help me understand how to use either of those interfaces? I'm by trade an analogue guy, and only bought a digital sensor because I couldn't find any analogue ones with the resolution I needed.
Thanks a lot, as I said, total newb to LabView.
01-03-2015 11:23 AM
Don't get yourself in trouble with the NDA. That's simply not worth it.
When you installed the software that came with the myRIO, you should have installed API to handle the I2C and SPI communications.
Here's a couple of links to get you started:
myRIO Project Essentials Guide: http://www.ni.com/white-paper/14621/en/
myRIO Specs: http://www.ni.com/pdf/manuals/376047a.pdf
The first link has a decent sized document to take you through some starter projects. This includes a project with both SPI and I2C and shows how to wire a device to your myRIO to create this connection.
The second link has a pinout on page 4 to show you what all of the pins on your myRIO are identified as. This is another way to know how to connect a SPI/I2C interface to your device.
To get an idea of what your code looks like, try making an example that's not related to your hardware at all. Just use LabVIEW without ANY hardware. On the Block Diagram, I want you to make an Array Constant with ten elements. I want you to use a loop with shift registers, as you currently are, to output values to an indicator every 0.5 seconds. This example is enough to get an idea of what your code looks like without sharing anything that should violate your NDA.
Is it safe to assume you have the SSP? Most new LabVIEW users have a new license of LabVIEW. If so, you should take advantage of the free courses available. These at least get you started with converting your C knowledge into LabVIEW knowledge. Once you spend some time learning how to translate what you already know into the new language, you'll code MUCH faster.
01-03-2015 03:16 PM
That pinout diagram actually helps a lot, I had no idea the myRio had dedicated i/o for the SDA and SCL lines.
I've got a couple of things going on right now, but I'll upload the example by today evening.
Thanks again for your help!
01-03-2015 04:03 PM
Attached is the Vi you asked for.
Out of curiosity, is there a more clever way to set the loop frequency than just using a time delay? I feel like my solution is super brute force.
01-03-2015 04:27 PM
Here's how I would do the task given just LabVIEW. Others may come and offer something even more efficient.
Here's some things I want you to take into account when you code based on what I saw in your code.
1) If the array is going to be the same for every iteration, build it once and wire it into your loop. Rebuilding it in each iteration is wasted computation.
2) If you have a stop condition, wire that as a stop option. Otherwise, the code will never stop running. In this case, do we want to keep cyling through the numbers? We could accomplish the same task using the Quotient/Remainder function to create a circular buffer. I suspect you were doing this to ensure the Shift Register always started in range. You could have initialized this by wiring a constant into the left Shift Register.
There's lots of ways to work with timing. You found one. You can use the Elapsed TImer Express VI. In these applications, I'm a fan of the Wait (ms) function I used in the code I have attached. If you're working with Event Structures, you can use the timeout case to setup timing. But, that's more advanced than we should be looking at just yet (and really is mostly useless for your end application). You can also used a Timed Loop.
Keep in mind these timings are all at the mercy of Windows so there WILL be jitter. When you work with the myRIO, Timed Loops are much more accurate and are the way I'd handle timing on your RT side. On the FPGA side, Timed Loops become "Single Cycle Timed Loops." These are a topic you can find quite a bit about by using a quick Google search. They essentially use more FPGA fabric to optimize a task and run it within the period you define.
I want you to hit Ctrl+H and get into the habit of keeping that open while you code. That way, it'll describe functionality when you hover over things so you can start to get a better idea of how things work. Pay attention to the cursor. It will give you hints about what can be done. As an example, it looks like you didn't know you could use the iteration terminal to wire into anything else. You used the Shift Register to gain this same functionality.
01-03-2015 05:40 PM
I realized I asked you to extract the element, not count. In case the elements aren't in numerical order, I added a second loop to run in parallel so you can see how to do that as well.
01-03-2015 06:20 PM
So I think I've figured out how to pull out the values from an array, how does this look for indexing the bus master address?
01-03-2015 07:17 PM
As long as you're aware you're only displaying the index in that code just to do so. You don't actually need to do that to take advantage of auto-indexed tunnels.
When you have that auto-indexed tunnel, it does exactly what it sounds like. It starts from 0 and increments until it reaches the last element. Then, it ends the For Loop. If you put one at the end of a loop, it builds an array the size of the number of iterations you run.
Are you starting to get a better idea of how to work your way through an array?