PID and Shift Register


Thread Starter


we have a s5 95u and i want to program the pid function can somebody help me on this area.
i also want to program a shift register using s5 but i have a difficulties on doing this. i want to use it in my experiment. in my experiment i have an input for data, for pulse and for reset. pls help me. thanks
The best way to program a shift register in S5 is to use a function block. Call a function block with a one shot bit.. in the block
conditionally shift a bit left or right with the function slb 16-1 or srb 16-1 due to scan times you must make the call a conditional call
or the register would fill automatically...

For ex..

A f20.0
jmp lable 1

Lable 1:
L fw100
slw 16-1


That is a simple Shift Reg.

have fun..

Zan Von Flue

The Handbook for the 95U is useful.

Is the link- at the bottom is Download. Look at page 250.

Make OB13. It'll be called up all 100ms(normally).
Call up your PID DB. Look at the HB, the DB has to be in a certain form!

Call OB 251

So in OB13

A DB 21 (My PID DB)

In OB1 you can work with this information.

Part 2
To shift Words (16bit) right and left is
SLW X, where X=0 to 15, this is shift left
SRW X, where X=0 to 15, this is shift Right


Martyn Sudworth

The 95U has no floating point so it's not easy (or at least not very accurate) for PID. It is possible, just rather involved.

The shift register is easy, use "SLW 1" or "SRW 1" with a jump around it when you don't ant to call it. Remember to check the value for being zero, then initiate it. Something like (this is untested), fw0 is the shift register here:

L 0
jc =m1
L 1
t fw0
m1:L FW0

This must be placed in a FB and must only be called when you want to increment the shift register. (and yes I know the M1:L FW0 doesn't
really need to reload the FW0 but I like the software obvious and clear).

Michael Griffin

To address your shift register question - the Siemens S5 does word shift operations in accumulator 1 (ACCU1). The statement list for
this is SLW (shift left), and SRW (shift right). Each of these commands requires a parameter which specifies how much to shift.
For example, to shift flag word FW10 left by 1 bit would be as follows:

L FW10 ;Load flag word FW10 into ACCU1.
SLW 1 ;Shift left by one bit.
T FW10 ;Save the result back in FW10.

Each time the above code is executed, the contents of FW10 are shifted left by 1 bit. This means you need to add more code which
decides when to call it. A fairly convenient way of doing this is to encapsulate something similar to the above in a function block (FB),
and call this function block *once* (one scan only) each time you want to shift left.

Since the S5 does shift operations in an accumulator, you are limited to shift registers of 16 bits only. However, you can overcome
this if necessary with additional statement list code by operating on several words instead of one.

Jacek Dobrowolski

As far as I remember, there's a built-in function for PID algorithm in S5
95U CPU - something like OB 251.


Jacek Dobrowolski, M. Sc. E. Eng.
Software Eng