# 0 - 5Volt Fader

## Recommended Posts

this time i have to make a program which can go from a certain setpoint to 5Volts automaticly

here the deal

i have 5v power supply

with a potentiometer i can alter the current from 0-5volt ( my setpoint )

when i flip a switch the setpoint has to move to 5V regardles of were it is at the moment.

if you guys don't get my drift. here a site with an electronic device. i have to use the same concept. exept i have to make it with Daqfactory

`http://www.voti.nl/fader/index_1.html`

it's supposed to be a fader from 0-5 volt

btw i tried to use the while loop to read the input value. and according to that adjust the output. but some how i couldn't get it tot work.

```while(1)
if (inputvalue &lt;=5)
then(Digout +1)
endif
wait(1)
endwhile
```

remember i'm still a noob so i'm not good at this

##### Share on other sites

I'm not really sure exactly what you are trying to do. But first, and I only mention it because if I don't say it, you may never know, but 0-5volt is voltage not current. Current is typical in units of Amps and a power supply that allows you to vary the current is a completely different beast.

OK, that said, you have just a regular variable power supply with a pot to adjust the voltage on the PS. You want to be able to set the power supply to 5 volts from within DAQFactory no matter what the pot says?

If so, this is actually a bit trickier then you'd think. You have to look at the Pot and see what it is doing. If its just a simple voltage divider on the output, then you could use a relay to bypass it. If its controlling some internal circuitry, you have to figure out how it works. It could be grounding the circuitry to set it to 5V or doing the opposite. That's why its tricky, and if done wrong you could blow the power supply.

What you may want to do is keep the power supply set at 5V all the time, and then put your own bypassable pot downstream of the powersupply. Truthfully, I'm the software guy, so perhaps others can contribute here about how best to implement the hardware side.

So, moving on to my area: what do you want the software to do? Do you want it to control the voltage all round (if so you can use an I/O module)? What determines what voltage to output?

As for your code:

1) Pretty much any time you want to monitor an input you should use an event as I showed you in your previous enquiry.

2) There is no "then" statement in DAQFactory

3) "(Digout + 1)" is not a valid statement either since it doesn't say where to put the value digout+1. "Digout = Digout + 1" is valid, or "Digout = 1"

4) There are only very rare reasons to use wait(). You should use delay() instead in general.

5) The indenting should look more like this:

```while (1)
if (Inputvalue &lt;= 5)
Digout = 1
endif
delay(1)
endwhile
```

##### Share on other sites

So, moving on to my area: what do you want the software to do? Do you want it to control the voltage all round (if so you can use an I/O module)? What determines what voltage to output?

the voltage has to move to 5v on its own in a certain time frame that can be user set.

so first i need to make smth like a counter or smth that i can use to simulate a certain time. so a loop would be nice that i could somehow start counting and then f.e. 1000 counts = 5 min just for example.

when i have that i have to make smth that goes from beginpoint (being the pot) to a 5 volt output over a period of time that the user can set. f.e. beginpoint = 3V. in 5 min the voltage should 5V without me doing anything exept giving it a time value.

hope this helps a bit

i'm new to all this. i'm an electricien not a programmer or anything but thanks for al the help

##### Share on other sites

OK, well here's a sequence that slopes a D to A output over a fixed amount of time and at a certain update rate:

```Var.TotalTime = 300  // total change time in seconds
Var.UpdateTime = 1   // how often to change output
Var.InitialVoltage = 1 // starting voltage
Var.EndVoltage = 5 // ending voltage
// note that the above could be set elsewhere, for example with a screen component

private.starttime = SysTime()
while (SysTime() &lt; Private.starttime + Var.TotalTime)
Output = Var.InitialVoltage + (SysTime() - private.starttime) / Var.TotalTime * (Var.EndVoltage - Var.InitialVoltage)
delay(Var.UpdateTime)
endwhile
Output = Var.EndVoltage // make sure we are at end since last step could be missed```

So, in the meat of the loop, we first record the time we start the transition. Then, while the totaltime has not elapsed we loop. On each iteration we set the output channel. The formula is made up of several parts. The (SysTime()-private.starttime) / Var.TotalTime returns a number between 0 and 1 where 0 is the start and 1 means the total time has elapsed. We then multiply this by the total voltage change and add that to the initial voltage. After setting, we delay for the update interval and then loop. When the loop quits, we set the output to the target voltage to ensure we got the last step. This is because depending on the timing of the loop the final output setting might not occur within the loop.

##### Share on other sites

ok thnx but i have another question. you might think its a stupid question but i could find it exacly what it means

in private.starttime. what does the private stand for?

and if i could set the var. values in a screen component how could i do that. i mean what expressions do i need to enter then?

##### Share on other sites

The private means the variable is only visible from within the sequence. This is done to avoid cluttering the global namespace. Basically that just means it is done to keep from having too many different names accessible globally. With DAQFactory 5.30 this becomes even more of an issue for reasons I'll skip for now. Anyhow, in general if you just need a variable in a single sequence you should use a private, and if you want to change it elsewhere you should use a global (var.) variable.

Var. variables can be used any place you would use an output channel, so, for example, you could create a Variable Value component and then open its properties, click on "Analog Out" button in the bottom right and enter "Var.TotalTime". What this button does is set the Action of the component (on the Action tab of the properties) to "Set To" and the set to channel to the Var.TotalTime variable. The SetTo action prompts the user for a new value and then sets the variable to that value.

If you have not done so already, you may want to go through the Guided Tour in the help / manual. And for more info on variables, and the scripting code, review the chapter on sequences.

##### Share on other sites

******* this is hard to make. i read through everything. did the guided tour ..again. i don't understand anything of it. your sequence might work exept i have no idea on how to make it work. i tried similer easier thing and all i get is a C1005 error. is it possible to make it with a different program but easier?

thnx for the help

##### Share on other sites

Did you remember to create the output channel?

I've attached a sample showing it working. I didn't know whether you had a U12, UE9, or U3, so I made the Output just a test channel. Hopefully you can build from my sample.

As for it being hard, well data acquisition is not super easy, and anyone or anything that is making it really easy is probably hiding things from you that you should understand otherwise you may be trusting results and actions that aren't correct. My favorite example of this is with the discovery of the ozone hole. When the ozone hole was discovered, there was already people measuring ozone for years who never saw the hole. When the announcement was made, they went back and discovered that the programmer, who had made it "easy" for the scientists had made it so values below 50 were marked invalid, thus throwing away all the real data that showed there was a hole.

As for other programs that might be easier, well only if you happen to find a program that does exactly what you want. LabView will be much harder, any programming language (VB, C, etc) will be as well. The problem is that everyone needs to do things differently. The first versions of DAQFactory had very limited scripting and tried to avoid programming, but we quickly discovered that then DAQFactory only worked for a very small subset of people who happen to need the features we offered. We thought about simply adding more features, but then the program just gets combursome with menu options. The only way to allow the flexibility to do all the different things people want to do, you have to use some scripting.

Unlike LabView, and low level programming languages, DAQFactory takes care of a lot for you. Plus you can use a lot of the non-programming features and just supplement it with some scripting for your unique application.

And then of course, you can always post here when you have problems and get a quick answer

risesample.ctl

##### Share on other sites

**** dude you rock. it worked. i could even measure the analog output and saw the needle rise. now al i need is so that i can make the startvoltage also user set and i'm done. i nearly smashed the laptop i'm using.

i'm gonna try to hook up the pot. otherwise you'll be hearing from me

at least i knew what i forgot

the D to A output

the startup sequence

thnx a bunch

##### Share on other sites

The start voltage is user set. Its called "Var.Initialvoltage"

Or did you mean the voltage when the application is started? If so, use a registry variable. So, right now, you have in the startup sequence:

Output = 0

Output = Registry.StartVoltage

Then create another variable value component that changes the Registry.StartVoltage variable. Then, when you change this variable and restart, the output will be set to that value.

Note that Registry variables default to 0.

##### Share on other sites

what does a registry variable do? what the difference

and i put this variable in there, won't it interfere with the initial start voltage

i mean if the initial voltage = 1 and the registry variable = 1.34. won't these to get in the way of each other? cause they both need to do the same thing.

or do i need to replace initial voltage variable with the new one?

##### Share on other sites

I think we're confusing the term initial voltage. There are two initial voltages really:

1) When the program starts, it initializes the output to a starting voltage. This is the one to use the registry with.

2) When the ramping loop starts, it has an initial voltage to ramp from. This is stored in Var.InitialVoltage and is set by one of the screen components I made in that sample, so is already user settable.

My previous post with the registry assumed you were trying to solve #1 since #2 is already implemented.

A registry variable is a variable that instead of being stored in memory is stored in the windows registry. Because of this, it persists even if you reboot your computer. Its limited to integers and strings so actually I should have added a multiplier in to allow for non-integer starting voltages. I only suggested using the registry variable in the startup sequences to set the initial voltage on the analog output.

##### Share on other sites

Azeotech

hi

uhmm... i wanted to use a pot as initial voltage right? wel i can't get it going i added a channel called input. so can i go like this

`input = var.initialvoltage`

it should now see var.initialvoltage as pot right. wel i can get it to show on the page with the variable value displays.

any idea on how i can fix this

never mind this post. already got it. i just change the Var.InitialVoltage by my input channel. and it worked

but thnx anyway

##### Share on other sites

not quite done yet. the boss wants a delay at start.

i replace the start button by 2 switches start and stop. now the boss wants that when i flip the switch the output channel has to got to the value the input (pot) has and then wait a number of seconds before it starts it rise

i tried to put a delay the switch like this

```if (start[0] == 1 &amp;&amp; stop[1] == 0)
delay(var.DelayedStart)
beginseq(rise)
endif```

but then it still stays a 0 volts and when Var.DelayedStart is over it jumps to StartVoltage and starts it rise

i tried adding this line in front of the delay but same result

` input = output`

i can't put the delay in the while loop cause it then keeps waiting when the loop is running

i read smth about the command continue/break. could i use this in here.

##### Share on other sites

Is the code you just sent in the channel event? If so, you really shouldn't put a delay() inside a channel event because it will cause the polling loop to slow down. Instead you should have this:

```if ((start[0] == 1) &amp;&amp; (stop[1] == 0))
beginseq(rise)
endif```

Note how I put parenthesis around each separate section of the if. It amounts to the same things, but I strongly recommend always doing this for two reasons:

1) its easier to read

2) unless you have memorized the priorities of operators, its better to use parenthesis to force the compiler to evaluate things the way you want.

Now in the rise sequence put:

```output = input[0]
delay(2)
while(1)
...
endwhile```

In that first line we set the output to the pot setting recorded on the input. Then we delay 2 seconds, then we go into the loop.

Another point: notice that I put [0] after input. [0] means take the most recent value. If you don't put [0], the entire history of input is returned. In this case it doesn't really matter because the "output =" part will automatically take the most recent value, but this time there are three reasons why you should do [0]:

1) once again, its clearer to someone reading the code what you mean. This becomes more important as your code gets more complex.

2) doing [0] allows DAQFactory to optimize memory as it just retreives the most recent value. Without it, it has to retreive the entire history, and then only when it does the = does it get trimmed down to the most recent value. This is a big problem if your histories are large.

3) once again, unless you have memorized all the spots where DAQFactory automatically takes the most recent value (and I haven't even memorized that!) you may not get what you expect.

##### Share on other sites

thnx it worked. but i have another question. i sure do have alot of question huh

i'm using the u12. but can i use it standalone. so i mean load the program in the u12 to run on its own?

and i can't seem to get a 2d-graph working anymore. it doesn't show any traces anymore. and i can't adjust te scale anymore. any idea on how that's possible

and can i use a angular gauge to display time that past

i also have a ue9 at my disposal

thnx for al your help

Graphic

##### Share on other sites

No, none of the LabJack units can act as standalone systems.

The 2D graph is probably frozen. When you click on it, it probably has a purple box around it indicating it is frozen. Just right click, select Freeze/Thaw and then Thaw all axes.

Angular gauges aren't included in DF-Express, which I assume you are using. You'd have to upgrade to at least DF-Lite for \$199 to get gauges. I'm not sure what you want to display on the gauge, but a gauge can display any scaler value, so whatever you want should work.

##### Share on other sites

about the graph. de left axis keep having a scale from 70 to 180. and i can't seem to get it changed. so what the problem with that. i tried thawing the entire thing

i trierd smth with the tick of the graph. an more stuff.

i'm lost

graphic

##### Share on other sites

Is there any data in the graph? If there isn't, or only a scaler value, then the graph will scale weird because it doesn't have anything to scale. Are you sure it is thawed? There should be green lines at the top and bottom when you left-click on the graph. Are you able to autoscale the y axis and have the scale change? What is your Y expression?

#### Archived

This topic is now archived and is closed to further replies.