LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate a synchronized PWM

Hi, I am able to generate (counter out)hi,lo and pwm(f=5,D=%3)using Case statement. But,when I put it inside a while loop that also reading voltage I get a glitch on hi and lo state. And when I switch it to pwm the frequency are not synchronized (different time interval between each frequency)..I Appreciate any idea to fix it?
0 Kudos
Message 1 of 22
(4,219 Views)
Hi Alex,

Your code looks to me like you have a variable freq and duty cycle pulse train in one case. And then a few other pulse outputs in the other options. It looks like the other pulse outputs will start their pulse train but are then immediatly stopped. I assume this is how you are doing the hi/low states.

Are you putting the analog input in the while loop for the PWM? Or are you putting this entire VI within a while loop that has the analog input?

Can you post your code that has the analog input?

I see that you have a wait until next ms multiple VI in the PWM loop that is set to 1000. If the AI is inside of that loop, about how long does it take to execute? What is your sampling rate and how many samples are you reading with each DAQmxRead? If its taking too long in some cases you may see erratic loop behavior (not consistent timing).

-Sal
0 Kudos
Message 2 of 22
(4,198 Views)
Thanks for the reply Sal
Yes that how I am trying to generate hi/lo states. I am putting this entire VI within a while loop that has the analog input. What i am trying to do,i have a 2-way valve that i am sending 5V(as hi state), 0V(lo state)and PWM to open and close the valve. I want the user to be able to have access to any of these states any time by pressing the right switch. another problem i am running to when its in the pwm state i am not able to stop the while loop unless i stop the PWM first.
I did fixed the synchronized pwm by adding inverter and stop vi. but when i put it into the while loop(analog input)i can not stop the program, switch to other state, and get other error such as -200279
thanks Sal
0 Kudos
Message 3 of 22
(4,189 Views)
Hi Alexx,

You can get descriptions of the error in LabVIEW by going to Help >> Explain Error.

Here is what it said for your error:

Error -200279 occurred at an unidentified location

Possible reason(s):

Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.

Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.

---------------

Where are you getting this error? I see that in your attached code that you have some subVIs missing.

---------------

However, you mentioned another error in your block diagram:

Error -200301 occurred at an unidentified location

Possible reason(s):

Cannot update the Pulse Generation property.

The pulse generation with previous property settings must complete a full cycle before the property can be updated.

---------------------

I would suggest not having the PWM stuff in a subVI. I'm guessing that you have a while loop in your PWM subVI. So what is happening is your LabVIEW code is entering the PWM subVI and then it stays in the loop. The program will not return from the PWM subVI until the loop inside it stops. This means that the loop in the main program does not execute until the PWM subVI is done. If this takes awhile, you will lose datapoints and get errors from the analog input VI.

Here is what I suggest:

1) put both tasks in the same VI (the top level main VI)
2) have the task setup outside the while loop
3) have both task's continuous stuff (DAQmxRead and the PWM's while loop stuff) inside the same loop
4) then have both stop/clear tasks on the other side of the loop


-Sal
Message 4 of 22
(4,169 Views)
Thank you for your feedback Sal.
I got ride of the error message. I put the PWM with READmx in the same While loop and it works fine. However, I could not switch back to hi state(5 V) without stopping the READmx. I want to be able to read voltage all the time and be able to switch to low or hi. The good news is I had the program running as I would like to ...no Error message..Using state machine. You could take a look at it if you like...i Welcome any recommendation.
Again, thanks for your help.
0 Kudos
Message 5 of 22
(4,150 Views)
0 Kudos
Message 6 of 22
(4,150 Views)
Looks good!

-Sal
0 Kudos
Message 7 of 22
(4,132 Views)
Could you give me a SIMPLE PWM.Vi? I need to control the generation of a PWM signal from a 6025E Daq board so that I can control and output of between 0V to 30V. From the front panel I can select the necessary voltage.
0 Kudos
Message 8 of 22
(4,090 Views)
Alexx

I have taken a look at your code and I guess my only recommendation/question is why you setup the CO task every time?? This may not be how your HW works, but it seems like you could start your frequency generation and then when the user selects the PPM state just change the Freq and Duty Cycle. Why do you need to stop and restart the task for every case?

StuartG
0 Kudos
Message 9 of 22
(4,083 Views)
I am trying to generate a simple PWM signal. I am using a PCI 6025E DAQ card. However the PWM VI's that I have come across are very complicated. I need to generate a PWM of between 0 to 1O Volts. I need to control the PWM from the front panel. Please HELP!
0 Kudos
Message 10 of 22
(4,065 Views)