LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Develop a PWM

Hello,

I am new with LabVIEW and need some help with two subtasks.

 

"Light emitting diods (LEDs) can only be used within a very limited range of voltages. Below this range the diode will not work at all, above the voltage, the diod will burn. So its almost a binary state: LED on or LED off. But if you want to have a dimmable LED, you have to run the LED with a PWM. PWM stands for pulse-width-modulation. You switch the LED on and off for a very short periods. Your eye is not fast enough to follow and will see a mean value. Our PWM will be much slower, so that we can see the change between on and off."

Subtask 1

The basic programm should have the following features:

  • A 'numeric control' to set the period length (during one period the LED be switched on and off one time)
  • An element where you can set the percentage of the period time the LED is switched on
  • A LED which is turned on and off by the PWM.
  • A button to stop/activate the PWM.

Subtask 2

  • Add a second PWM, which automatically alternates from 0% pulse width to 100% pulse width within about 10 seconds.

 

I have come up with two solutions but they are both wrong. The solution should be something in between my two solutions but I have no idea how to proceed.

 

Grateful for all help I can get!

Download All
0 Kudos
Message 1 of 12
(3,943 Views)

Hi.

Are you using some NI hardware or custom Hardware or on what do you want to run the PWM?

I can not open your files as I am using an older version of labVIEW, Just curious to know Smiley Happy

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 2 of 12
(3,932 Views)

I took a quick look at your VIs - the first one is probably pretty close to what you need.

 

Let me ask a couple of questions/make a couple of comments that should hint you in the right direction:

  • You're told to use a 'numeric control' to set the period length. What do you need to replace in your current VI (the first one) to make this happen?
  • If you set the LED on via a % control, what percentage should it be off? (i.e., given a fraction of time to be on, how do you calculate the time to be off?)
  • Although this isn't vital to your code (because your code as written toggles between the two states fine), you can consider placing a boolean on the shift register instead of the 1,2 value and then using "Not" to switch the value.
  • You can use that boolean value along with the "Select" node to choose the time to wait, and then wire that to the Wait (ms) node. No case structures needed!

It also says you need a button to activate the PWM. In that case, you might consider having a case structure around everything inside your While loop, and setting the button to "Switch when clicked/released" mechanical action (rather than "Toggle when ..."). Obviously, make sure the button is also inside the loop (but it looks like you'd have known that already!)

 

Edit: Notes for second task:

  • Take a look at the Ramp Pattern VI
  • Since you will know the number of steps you want beforehand, consider replacing the While loop with a For loop.
  • You won't need a % control for the second task (perhaps you also won't need a period control, but I'm not certain about the requirements for the task)

GCentral
0 Kudos
Message 3 of 12
(3,910 Views)

It is a school assignment and so far it is only a theoretical question to be solved with the  software, but eventually it will be used on NI hardware Smiley Happy

0 Kudos
Message 4 of 12
(3,908 Views)

I need two input values one for the period length and one for the percentage of the period length while the led is on.

So when the period length is 1s and 20% on then the led is 800ms off an 200ms on

 

But i don't know how to do this Smiley Frustrated

0 Kudos
Message 5 of 12
(3,864 Views)

Ok, so as I asked before:

  • You need an input value (i.e. numeric control) for the period length. What should you replace in your current first VI to make this happen?
  • You correctly identify that if you have 20% on and 1s period, your times should be 200 and 800 ms. The total time is 1s (i.e. the period that you set). If the information you have is 1s (1000ms) and 20%, how do you calculate those two (200, 800) values? You already have most of the calculation for the first value, but currently you're just duplicating it for the second value

GCentral
0 Kudos
Message 6 of 12
(3,856 Views)

So this is what I've come up with.

 

The only problem now is why the boolean is on while it has a false constant and why it is off while it has a true constant?

It should be the other way around.

0 Kudos
Message 7 of 12
(3,798 Views)

You have to understand the idea of dataflow, that data will only flow out of a structure and on to its destination once that structure is done executing. Try turning on "Highlight Execution" (the lightbulb icon in the toolbar) to see how the data moves. You have your Wait functions inside of a Case selector, so as long as the wait function is running (waiting the commanded time) the Case structure will not be complete yet. Only once the Wait finishes waiting and the Case is done executing, can the True or False constant finally pass out of the Case and into the LED indicator. So basically, you're waiting the desired "on" time, and then turning the LED on, or waiting the desired "off" time, and then turning the LED off.

0 Kudos
Message 8 of 12
(3,788 Views)

What arteitle said is what you should check - as they mentioned, your Wait function is inside the Case structure, so you're waiting before you 'release' the value of the boolean to the indicator. If you place the Wait outside of the case structure, then your Wait will occur at the same time the boolean indicator receives the new value, which might be more what you expect!

 

Also, now that you've sorted out the calculations of time (although it appears as though the % is % time Off, is that what you wanted?) take a look at the Select node I mentioned. This would allow you to remove the Case Structure entirely 🙂


GCentral
0 Kudos
Message 9 of 12
(3,764 Views)

i have the same task, can u help me with that if you are done

 

0 Kudos
Message 10 of 12
(3,334 Views)