|For a hardware evaluation project I'm working on, I want to create a device that can be controlled via LabVIEW.|
LabVIEW can talk to instruments using serial out of the box, and it knows how to talk Standard Commands for Programmable Instruments (SCPI).
In this blog I make a LabVIEW Virtual Instrument that turns PWM signals on and off.
We'll create a LabVIEW control panel that can toggle PWM output of a Hercules microcontroller.
In the previous blogs we enabled our Hercules LaunchPad USB and made firmware that knows how to interpret SCPI.
Our LabVIEW program has to be able to connect to our USB port and send SCPI commands.
We'll use a toggle button to switch PWM on and off.
Requirements of the LabVIEW design:
- connect to a COM port and talk serial
- Send the right SCPI commands to the COM port, depending on the position of the toggle switch.
There's an example program in LabVIEW that gets us 70% of what we need: examples\Instrument IO\Serial\Simple Serial.vi.
That one can connect to our LaunchPad over USB and send the SCPI command *IDN? (we've used this program earlier on in our tests).
We can use the complete program - we just need to replace the constant string '*IDN?' with either PWM1:STATe ON or PWM1:STATe OFF depending on the state of our toggle switch.
That isn't hard. The first thing we do is place a boolean control on our canvas. I selected a switch that gives a good indication of On/Off. I named it PWM.
Then, in the Block Diagram,I added a Case block, and wired the switch to that.
I also added two constant string items, one containing PWM1:STATe ON,the other PWM1:STATe OFF.
I wired the two strings to the case statement as inputs. The output of the case statement is routed to where the original *IDN? data was flowing.
In the case block, for the False state, I routed the OFF input to the output. For the True state, I routed the ON input. And that's it.
To test the program, set the toggle in the desired position and run your LabVIEW program.
The PWM output will switch on or off based on that.
I've attached the LabVIEW project to this blog. The firmware for the Hercules LaunchPad is available in the previous one.
Give it a try!
Hercules SCPI.zip 33.9 KB