LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicate LabVIEW with a pic 18f4550 via USB

Solved!
Go to solution

Greetings everyone, as title suggests, I would like to have communication with the aforementioned PIC, in order to use it as a sort of control buffer. Nothing complicated or fancy, I would like to use it as a sort of buffer, with LV doing all the calculations and heavy lifting, while the PIC only handles communication and nothing else. Specs are:

 

-I would like to control 2 stepper motors, to which I already have drivers that are binary pulse driven (1 pulse = 1 step)

-Might or might not require feedback from an analog encoder (0-5V), so for now let's assume yes

-As mentioned, nothing fancy like PID or advanced control in the PIC, just sending and receiving movement, LV will do most of the job as it's the one I'm most familiar with

-I am knowledgeable but not particularly good at C programming (not my cup of tea), but am rather adept at BASIC, my particular enviroment is Oshonsoft's PIC Simulator IDE and its recent iteration, Basic compiler.

 

I have done a substancial amount of research, but most of the info is pretty outdated, and most download links do not work anymore. I know I need to use Microchip's general purpose dll (already got it), but would like to know if someone has done something similar, or could give me a starting point. I have also read the whitepaper found here: http://www.ni.com/tutorial/4478/en/#

 

So basically, if anyone has some leads about a good starting point, tutorials I should take or any basics I am missing, they would be very welcome. Thanks a bunch.

0 Kudos
Message 1 of 9
(6,685 Views)
Solution
Accepted by topic author Daikataro

I would think it would be simpiler to use a virtual COM port device like one of the FTDI ones 

 

Then program a serial connection on your PIC and just use VISA in LabVIEW to comunicate with the PIC just like comunicating with any other serial device.

========================
=== Engineer Ambiguously ===
========================
Message 2 of 9
(6,650 Views)

Probably, yeah, but sadly, USB communication is a requisite, plus serial could be kind of slow, which is not ideal for the application. so I would rather have some more intel or tutorials on USB if anyone has some.

0 Kudos
Message 3 of 9
(6,635 Views)

@Daikataro wrote:

Probably, yeah, but sadly, USB communication is a requisite, plus serial could be kind of slow, which is not ideal for the application. so I would rather have some more intel or tutorials on USB if anyone has some.


If the 18f4550 doesn't have onboard usb to serial emulation (or a driver for it), I would put a small FTDI chip on there to go from TTL Serial to USB.

 

Why?

1) For prototyping/development you can use an FTDI TTL cable and connect directly to the pins of your PIC

2) When you do the electronics, you could easily choose to switch between the FTDI chip and an RS-232 communications port (with a transceiver).

 

Serial (by USB) is more than fast enough unless you need to stream vast amounts of data. This is how things like Arduinos work.

 

If you *really* want to go through the hassle of writing your own USB driver and communicating to it from LabVIEW - you can do this using VISA RAW. There is an excellent guide on that somewhere in the forums. Of course, you'll also need to learn about how to write the USB interface for your PIC.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 4 of 9
(6,614 Views)

Indeed FTDI USB to Serial adaptors can easily run 115200 baud and higher.

 

I can not imagine a PIC being able to transmit and receive data faster than that anyway.


========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 9
(6,604 Views)

Thanks a lot for your intel, I will definitely take a look at the usb to serial option, if I can't get it to work via USB native. I have made some progress, but am currently stranded, here are my 2 alternatives:

 

-I already (sort of) have the USB driver written, concretely, the programming language for PIC I'm proficient with enables the development of USB functionality on a relatively simple way, via using the HIDTerminal ActiveX control included in Windows, so my PIC is now recognized as a generic USB device. I am able to programatically alter stuff like PID and VID, manufacturer name, etc. After some reading I decided to use the VISA driver wizard, to develop a driver that is recognized by LV. So far so good, the device is now recognized as a USB VISA RAW resource by MAX, and I can even give it an alias. However, when I run the USB RAW example bundled in LV, I get a −1073807299 Invalid buffer mask specified error when trying to read from device, and a general I/O error when trying to write to it. Any idea on what could be causing this?

 

-My second choice, the HIDTerminal ActiveX control is of course, an ActiveX resource, which presumably can be called by LV and used in the program. I have taken a look at the PowerPoint example (attached), but I have no idea where the generic HID control is located. Does anyone know how to interact with it?

 

I think I'm getting close, and if I could solve either of those problems, any could be the solution to the problem.

0 Kudos
Message 6 of 9
(6,595 Views)

So, seemingly no adittional feedback on this one then? Either way, due to time constraints, I have opted for the easy way out (for now) and implemented a simple RS232 command/response architecture, kind of like a lite version of the LIFA one, using a Pololu USB to Serial adapter. Still open to suggestions and info for using custom USB Hardware in LabVIEW, for future projects and simple curiosity.

0 Kudos
Message 7 of 9
(6,536 Views)

I did say that there was a very good guide on the forums somewhere on using USB RAW with VISA, did you try searching for it?

 

http://forums.ni.com/t5/LabVIEW/Nugget-1-of-n-GEtting-started-with-USB-communication-via-VISA/td-p/7...


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 9
(6,519 Views)

Yeah, actually I did read thru a fair bit of that threat, but sadly couldn't find what I was looking for and, even more sadly, responders mostly agree that the speed increase wasn't worth the significant effort on their part, which makes USB even less viable now, for this specific project at least.

 

I have been thinking of starting some sort of think tank thread, on creating custom USB devices for LV from a pic, starting with generic HID windows and switching those to NI VISA drivers via the wizard, would anyone be on board? Fair warning, the stuff you would need is:

 

PIC 18F4550

Programmer

Barebones stuff to connect PIC to USB port

PIC 18 Simulator IDE or PIC18 BASIC compiler, only if you want to make changes to the firmware in the pic

 

I can provide the .hex from the basic program I loaded to the pic that was recognized by VISA, but of course mods would take time if only one was switching them.

0 Kudos
Message 9 of 9
(6,495 Views)