Increment / decrement a value with digital signals

Gnook

Member
Join Date
Jan 2007
Location
Wales(UK)
Posts
20
Hello,
This is probably a no brainer but I am having a mental block. I want to adjust a word value up/down based on two inputs, the adjustment needs to be smooth rather than simply adding a fixed value, basically like an integrator.
Any idea's to clear the fog?
By the way the code will run in an Siemens S7300 CPU (313C), I have Step 7 Pro so I can work with LAD, STL, FBD and SCL or graph.
Thanks Gnook.
 
Either, I just want to see the basic principle, specifically in my app I will be working on an analogue output later so 0-27648 would cover it. I would like to have an adjustable timebase as the integration time will ultimately be dependant on line speed and could be driven by another reference value in the future.
 
How about two different instructions
Instruction 1
X = X + 1
Instruction 2
X = X - 1
each with a transitional contact from the input or input in series with a timer pulse.
 
use the add/subtract integer instruction with a oneshot in front with limits defined.

for the timebase you could use the cpu clockbits if the range suits.
 
I've tried simple add/subtract options but the result is undesirable, either the increment value seems to be to large and or the cycle time seems to slow/fast. I was hoping to stumble on something that would work like a nice smooth wave generator with the output looking like the result of a nice PID loop. I think I need to be able to adjust the value in a way that the increment starts very small and increases as the input stays on. Lets say when the input goes on my initial response is to add so X=X+1 then wait 100mS add 1 again if the input is still high after a further 100mS I want to add 1.2 then wait 100mS and so on. I am trying to control a web accumulator loop so a loop length is constratined over a single sensor point but to keep the web feed smooth I need to make small incremental speed changes quite frequently.
 
So when your INPUT is set, start a timer with a preset of greater than the length of time you expect the INPUT to ever be set (in ms).

New rung, if INPUT is set, and the timer .ACC is greater than 200, fire a ONS and ADD .2 to the variable containing the amount to add to the control value.

New rung, if the INPUT is set, and the timer .ACC is greater than 300, fire a ONS and ADD .2 to the variable containing the amount to add to the control value.

Repeat as many times as necessary.

When the INPUT goes reset, MOV a 1 back to the variable containing the amount to add.

Will that work for you?

Bill
 
Here are a couple of ideas, untested and done in a big hurry, that may get you started or get the old grey matter going.
hope they help.

Function.jpg Timers.jpg
 
I would like to have an adjustable timebase as the integration time will ultimately be dependant on line speed and could be driven by another reference value in the future.

If I understood it, you need to ramp the output value proportionally to the web speed. One possibility is to keep the integration interval constant and use a speed integrator.

In a timed block define a float web_q = actual_speed / max_speed * constant and a float web_accumulator. Every cycle add web_q to web_accumulator. Once web_accumulator exceeds 1 or other predetermined value, add or subtract to the output counter and reset web_accumulator.

This will give a smooth ramp on the output with the ramp speed as a function of actual web speed.
 
Thank you to MasterBlaster, BobB and ydtech, between the three responses you stimulated a bit of thinking and I have implemented an interim solution that works as below:

Let’s say that when input_1 is 0/low I need to increase the speed smoothly and when input_2 is 1/high I need to decrease the speed. I wrote code based on the following to achieve this:

The value to be adjusted is called ‘Val’
Start loop 1:
When I_1=0 run a timer for 50mS
When time is elapses multiply ‘Val’ by 1.01 and reset timer
Return to start loop 1

This increments the speed by 1% every 50mS until I_1 is true.

As the speed is now slightly higher than line speed I have another loop;

Start loop 2:
When I_2=1 run a timer for 50mS
When time is elapses multiply ‘Val’ by 0.99 and reset timer
Return to start loop 2

This serves to decrement the speed by 1% until I_2 is false.

Although quite rough it works at the moment; I think I can refine this further and am open to suggestions. I am passing the time constant as a variable into a function block and using the IEC TON SFB inside my FB as the timer. When I have polished my code up a bit I’ll post it but I’m off now until Jan 04/2010 so it won’t be up until then as I can’t test in real life.

Merry Christmas to you all and thank you for the advice, best regards,
Gnook.
 
Looks like you're using dead-band control. You'll have to, unless you really want to keep ramping the speed slightly above and slightly below the set-point all day long.

Anyhow, you can use a single timer running continuously. Like this:

Start timer
When timer is done
If I_1 = 0 increment Val
If I_2 = 1 decrement Val
// Otherwise do nothing
Restart timer
 
All the ones I have worked on had analog or something that gave a signal from empty to full accumulator
You will fight this thing forever with just digital limit switches
 

Similar Topics

Hi, I have a stand alone inspection unit with no PLC but I can send 24v input signals to the machine PLC to show a good read and a bad read when...
Replies
9
Views
774
All Looking for a way to use a momentary relay closure and the digital inputs to increase or decrease the speed of a Powerflex VFD. I looked...
Replies
3
Views
2,796
hi guys, i am new plc programming learner. i stucked in one of the excercise problem of speed control of servo motor using increment/decrement...
Replies
3
Views
3,810
I am trying to create a panelview 900 screen with a increment button,decrement button and numeric entry setpoint. I am having trouble coming up...
Replies
10
Views
6,674
Hi, Am I being daft (again)? I want to increment a tag (Integer) by 1 each time a button on the HMI is pressed. Before the button press, the...
Replies
22
Views
2,305
Back
Top Bottom