razzle888
Is there a way in OpenPLC in LD mode to map say an analog input to represent another set of units ie like time?  I am wanting to wire in a potentiometer to an AI point on Arduino Uno and use this as an adjustable timer to use this variable time set on a timer? Example, 10K single turn pot to represent 0-10 seconds for the timer in my LD.
Reply 0 0
thiagoralves
You can do this, but you will have to make a few calculations. The entire analog range of any board on OpenPLC is 0-65535. So if you want your pot to change a timer from 0 to 10 seconds, you will have to convert the UINT from the analog input to REAL, then make the calculations so that 65535.0 represents 10.0 (essentially in this case you just need to divide it by 6553.5), and then convert the final REAL result to TIME to feed that into a timer.
Reply 0 0
razzle888
Thanks, that is what I bascially did looking at examples of scaling inputs.  In simulation mode everything was working as expected.  When I wired up the potentiometer to the AI point, downloaded the program and went to debug when the pot went to about half range, the raw units displayed started going negative halfway of the expected range of 65535.  What am I doing wrong?  The pot being used is 10K ohm single turn.
Reply 0 0
thiagoralves
Use UINT instead of INT
Reply 0 0
razzle888
That worked.  Thank you very much.
Reply 0 0
eliott8791
Hello everyone! sorry for my English, I have the same problem,
but I don't understand how to do it, could you help me and give a practical example,
explaining how to adjust the T#3sec with a 10k potentiometer
22.png
Reply 0 0
thiagoralves
A potentiometer on an analog input (%IW0 for example) will give you a numeric reading from 0 to 65535. Using some math you can convert that value to 0 - 3 seconds. Once you have that value in seconds stored in a REAL variable (use REAL so you can make use of fractions of a second, like 1.23 seconds) then you can simply convert the REAL variable to TIME using the REAL_TO_TIME block, and feed that to your timers.
Reply 0 0
fg71
If the max value for your analog signal is 65535 you could calculate the time with this formula.
 
time = (actual value / max value) * max time.
 
ex.
time = (32767.5 / 65535) * 3 = 1.5 seconds
 
You do the calculation, next you convert real to time
 
In other words when the Potentiometer is 50 % it will output 1.5 seconds
Reply 0 0
Reply