NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Member
grahamwebb
Posts: 134
0 Kudos

Interfacing LabVIEW 2009 with PIC microcontrolller

I would like to quickly setup an asynchronous duplex RS232 (or USB) communication between LabVIEW 2009 and a PIC16F8xx. Before I get stuck in, does anyone know if there are any reference code templates or examples available for either LabVIEW, assembly or c code (using the CCS compiler) to speed up the development?  

 

Many thanks

Graham 

Proven Zealot
muks
Posts: 7,208
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller

Trusted Enthusiast
Coq_Rouge
Posts: 2,187
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller

Can you tell us more about what you plan to do. I have used this approach many times. And I can give you some tip. If you are new to this perhaps a RS 232 link is the best. But this will depend on the data rate



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Member
grahamwebb
Posts: 134
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller

Hi, It's a fairly generic application (which is why I started a new thread!) My PIC is generating a PWM output, I'd like LabVIEW to send commands to modify the pulse shape. My commands are simply one character (a, f or p) to represent the parameter to change, followed by an int. So f100 is change frequency to 100. I've sorted the write functions out using an event structure, but I'd like to now add a serial read so I can echo back from the PIC to help with the assembly code writing. I haven't used event structures much with VISA functions. I'd like an interrupt style read.
Trusted Enthusiast
Coq_Rouge
Posts: 2,187
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller


grahamwebb wrote:
Hi, It's a fairly generic application (which is why I started a new thread!) My PIC is generating a PWM output, I'd like LabVIEW to send commands to modify the pulse shape. My commands are simply one character (a, f or p) to represent the parameter to change, followed by an int. So f100 is change frequency to 100. I've sorted the write functions out using an event structure, but I'd like to now add a serial read so I can echo back from the PIC to help with the assembly code writing. I haven't used event structures much with VISA functions. I'd like an interrupt style read.

I could not run your code, since a VI is missing and I do not have your hardware. But that is OK. You had some labview no-no that I correct in your code. Also be careful with using globals and locals in your code. They may slow down your code. Global and locale variables are not pointers but a copy of the original data. A few global/locale with short strings and some values will not hurt you much. But large arrays and complex clusters will do.

Also have you considered using C and not assembly code. It will make things simpler for you. The last thing is KISS (Keep It Simple Stupid). That is a phrase I learned in my time in the army. What is mean is that then you try to do things in a fancy but overcomplicated way. You will quite often fail. As an example if you send the code f100 to your microcontroller you must decode the 100 value into binary number. So why not send the vales as one or more binary bytes that the microcontroller do understand directly. But beware of the endian format.



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Member
grahamwebb
Posts: 134
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller

Thanks for your help. I meant to keep the range of values within a byte but now realise the padding is unnecessary (attached missing vi.).

 

At the moment the PIC is just adding one to the first ascii character and returning it. It looks ok on the oscilloscope but the read is still not working.

Trusted Enthusiast
Coq_Rouge
Posts: 2,187
0 Kudos

Re: Interfacing LabVIEW 2009 with PIC microcontrolller

You might perhaps be aware of this. But you can not connect your PIC directly to you serial port. You need a RS232 level converter. A very common circuit for this purpose is a MAX232 type circuit. Just Google max232 and you will find info. Also you must set the Enable termination char input to false, as it true by default. As a tip. Then I program in Labview I Always go to help in the toolbar, and then select Show context help. Do not be afraid to use the "detailed help" option in the context help


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)