LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pwm generation without special hardware and Labview 5.1

Hello:
     I would like to generate three independent PWM signals with Labview (1 second of period). The duty cycle would be controlled by the output of a PID controller (programmed in Labview too).
     I'm using Labview 5.1. It's runing on a windows 95 AMD k6 PC. I don't have any special hardware. I have a digital I/O board in a EISA Slot. I can obtain an output bit using the  outport.vi function.  So I could write 8 bits at the same time, three of them would be the three output PWM's that I need.
    So, here is what I thought:
    1) I have three PID's outputs.  
    2) The output of each PID would be used to control the cuty cycle pf each PWM
    3)  The output would be written by the outport.vi function
¿Is the general scheme possible to program? How can I program the PWM? I understand this Labview doesn't work with interruptas, and I couldn't write a resettable counter. I need the PWM to be present at any moment, no matter what the main program is doing. In Assembler I did achieve that by working with independent counters and interruptions (when the counter reaches the count, it interrupts the main program, writes the output bit and returns to the main program). But I couldn't find a way to do something similar in Labview 5.1.
¿Is there a way to program a PWM with the hardware I have?
Thank you vey much,
    fgf
    
0 Kudos
Message 1 of 7
(5,825 Views)

Is the digital IO board you have a NI board?

With a 1 second period, you could just try write the PWM logic in a while loop.  Depending on the other things you have going on, you might be able to get ok performace with just a software controlled PWM.  Pretty simple logic that even LV 5.1 can do...Smiley Happy

SteveA
CLD

-------------------------------------
FPGA/RT/PDA/TP/DSC
-------------------------------------
0 Kudos
Message 2 of 7
(5,821 Views)

Thank you, StevenA, for the answer.

   I understand that when Labview enters a While loop, it stops doing anything else until the while is finished.

   I imagine a while loop which count depends on the duty cycle. So, for example. Lets start with a output of 0. If the count is less than a number representing the duty cycle, the ouput remains the same. When the counter reaches the count, it switches the output, for example, to 1. it has to start counting again, to reach the number representing the time T*(1-D) (T=period, D =duty cycle).

But, as I see, the software would have to do this countinously. How can I do this in a "parallel" way with the principal program. One thing I tried to do was to program a resettable counter with count ticks, or something like that, but I couldn't do that. ¿Where am I wrong?

 I know may be I should think a little more, but, is there an example showing how to do the PWM with the while loop? ¿Where can I find the Vi code for that example?

   Thank you very much, again,

      fgf

0 Kudos
Message 3 of 7
(5,811 Views)

fgf,

code up this PWM in LV 5.1

setup your divider and loop rate to achieve the desired frequency.   If you set your divider to 500, then a duty cycle of 250 would be 50% duty.  Give it a try.

Message Edited by StevenA on 07-08-2008 07:56 PM

Message Edited by StevenA on 07-08-2008 07:58 PM
SteveA
CLD

-------------------------------------
FPGA/RT/PDA/TP/DSC
-------------------------------------
0 Kudos
Message 4 of 7
(5,798 Views)


fgf wrote:
How can I do this in a "parallel" way with the principal program.


you could put the above pwm generator in a parallel loop to your main program.  Pass the duty cycle value from your PID control loop to the PWM loop with a local variable.
 
If by chance you can run the PWM loop and the PID control loop at the same rate, then put everything in the same loop.  This would however, give you less flexability in changing the frequency of the PWM.
SteveA
CLD

-------------------------------------
FPGA/RT/PDA/TP/DSC
-------------------------------------
0 Kudos
Message 5 of 7
(5,793 Views)
fgf, did this work for your application?
SteveA
CLD

-------------------------------------
FPGA/RT/PDA/TP/DSC
-------------------------------------
0 Kudos
Message 6 of 7
(5,750 Views)
Thank you very much, StevenA for your fast answer. I'm sorry I didn't write you before. I couldn't try your solution yet because it was a complicated week at work. I will tell you what happen when I test it (i'm afraid this verb tense was wrong, sorry for my english).
Regards,
    fgf
0 Kudos
Message 7 of 7
(5,735 Views)