S7 Scale of Analogs

barryoc

Lifetime Supporting Member
Join Date
Nov 2009
Location
Kilkenny
Posts
148
Season Greetings Folks,

I'm starting to learn some stl for siemens plc's. As a bit of learning i'm going to try the following.

Create a DB with the required information for 8 analog inputs. (Start address of analogs, No. of analogs, Hi Limit, Lo Limit etc)

Create a function that will loop through the 8 analogs, calling the parameters from the db and return the scaled value for each one back to the DB.

Has anyone done this before or is it even possible? This is just for learning so any pointers would be appreciated.

Regards,
Barry.
 
Cheers Turbo,

Its actually where the idea stemmed from. Reckon i'm going to get a good few days working this out:).

A couple of questions. Will there be a need for blk_mov, I don't think so? Is there anything extra that needs to be considered regarding PIW address' or anything else?

Thanks,
Barry.
 
The pointer has to be a double word.

The address has to be changed to pointer format

i.e.

If the address is PIW800 you would maybe have dataword that has the value 800, load it to the accumulator then SLD3 (converts to pointer), then transfer to a double word store.

here is an example I'm using in my code

Code:
     L     #ioA1_Set.Address           // Convert PIW Address to Pointer Format
      SLD   3
      T     #tA1_Address

      L     PIW [#tA1_Address]          // Get current data
      T     #tA1_Raw_Input

      CALL  "FC SCALE"                  // Scaling Function for Analogues
       IN     :=#tA1_Raw_Input
       HI_LIM :=#ioA1_Set.HiLimit
       LO_LIM :=#ioA1_Set.LoLimit
       BIPOLAR:=#ioA1_Set.BiPol
       RET_VAL:=#tA1_RET
       OUT    :=#tA1_Scaled
 
I'm worried now - I don't remember doing any of that!

I just used FC105 scale (Or is it 106) and got the PIW number after i dragged the analogue card in from the hardware catalogue!

Then I set the destination as a real value in a datablock.

Of course, I am a bit dim and like doing things in ladder!!!!!

Better check at work tomorrow.

PS - I've only ever used block move when 6 different addresses for data was called when interfacing with Modbus, and the DB would have been overwritten.
 
Last edited:
Markie you should read OP again. He just wants to make it trough DB that has parameters.

He could for example make db, with x number of UDT analog_in that has described hi_alarm, low_alarm etc. With that he could have one variable in that db that gives number of analog inputs and could easily just loop them trough with function that never needs to be modified.

After that he could just use values in that db. For example by:

Code:
 AIn.FillTemp.HiAlarm   SomeOtherCondition    DoSomething
---|/|----------------------||--------------------()
 
Last edited:
I'm worried now - I don't remember doing any of that!

I just used FC105 scale (Or is it 106) and got the PIW number after i dragged the analogue card in from the hardware catalogue!

Then I set the destination as a real value in a datablock.

Of course, I am a bit dim and like doing things in ladder!!!!!

Better check at work tomorrow.

PS - I've only ever used block move when 6 different addresses for data was called when interfacing with Modbus, and the DB would have been overwritten.


alternatives

1. Directly addressed

Code:
      CALL  "FC SCALE"                  // Scaling Function for Analogues
       IN     :=PIW800
       HI_LIM :=100.0
       LO_LIM :=0.0
       BIPOLAR:=M1.0
       RET_VAL:=MW200
       OUT    :=MD202


2. Indirectly addressed

Code:
      L 800           // Adress 800
      SLD 3           // Change to Pointer
      T #Temp_DWord   // Temp Variable assigned as Double Word 

      L PIW[#Temp_DWord] // Load contents of PIW pointed to by DWord
      T #Temp_Word    // Temp Variable assigned as Word 

      CALL  "FC SCALE"                  // Scaling Function for Analogues
       IN     :=#Temp_Word   // Analogue input Value
       HI_LIM :=100.0
       LO_LIM :=0.0
       BIPOLAR:=M 1.0
       RET_VAL:=#Temp_Int    // Return Value into Temp Int
       OUT    :=#Temp_FLOAT  // Value between 0.0-100.0
 
You should read OP again. He just wants to make it trough DB that has parameters.

He could for example make db, with x number of UDT analog_in that has described hi_alarm, low_alarm etc. With that he could have one variable in that db that gives number of analog inputs and could easily just loop them trough with function that never needs to be modified.

After that he could just use values in that db. For example by:

Code:
 AIn.FillTemp.HiAlarm   SomeOtherCondition    DoSomething
---|/|----------------------||--------------------()


I read it and understood. My example is a UDT in a dB passed to another block as an IO parameter.
 
Guys,

Having a bit of trouble understanding how to get this to work. I have setup UDT with the following

Hi_Limit Real
Lo_Limit Real
BiPolar Bool
Return Word
Result Real

A DB is setup as follows

0.0 NoOfAnalogs INT 2 Only 2 At moment for Testing
2.0 StartAddress INT 272 Start address of Analog Card
4.0 Array[1..2] From udt.

My fc in_out has the parameters from the UDT for the scale function.

I do a loop for offset values for the Address area in the DB and the PIW number but this is where i get stuck. How do i pass the parameters to the scale function?

Am i anywhere near achieving my goal? Some guidance would be great.

Code i've written for function so far is attached, which no doubt has plenty of errors.

Regards,
Barry
 
First network

1 Zeros #AnalogNo
2 presets Loop Count with value of "Analog Inputs".NoOfAnalogs
3 increments #AnalogNo for each loop

so #AnalogNo will equal "Analog Inputs".NoOfAnalogs which = 2

Second network

1 (#AnalogNo - 1)*16 = 16
2 SLD so pointer of 16
3 puts a pointer to DBX 4.0 into AR2 (what DB?)
4 adds what evers in accumulator 1 AR2

5 #AnalogAddress = 2
6 (#AnalogNo - 1)*#AnalogAddress = 2
7 SLD so pointer of 2
8 puts a pointer to DBX 272.0 into AR1 (what DB?)
9 adds what evers in accumulator 1 AR1
10 transfers what evers in acculator 1 into rawinput


needless to say there are definately a few errors here :rolleyes:


I can see from your description what you are trying to do so lets see

Start Address = 272, number of analogues = 2, so I assume that these addresses are continuous, i.e. PIW272 and PIW274.

Code:
      L     "Analog Inputs".StartAddress
      T     #AnalogAddress

      L     "Analog Inputs".NoOfAnalogs
META: T     #Count   //Temp For Number Of Loops
  
      L     #AnalogAddress
      SLD3
      T     #AnalogAddressDW // DWORD Temp

      L     PIW[#AnalogAddressDW]
      T     #RawInput

      CALL "SCALE" 
           IN                       := #RawInput
           HI_LIM                   := #Analogs.hi_limit
           LO_LIM                   := #Analogs.lo_limit
           BIPOLAR                  := #Analogs.BiPolar
           RET_VAL                  := #Analogs.Return
           OUT                      := #Analogs.Result

      L    #AnalogAddress
      +    2
      T     #AnalogAddress

      L     #Count
LOOP  META
 
Thank You Peter,

Wow thats a small bit of code. As a novice in stl i think i am over complicating everything.

Just one question, when i enter analog.hi_limit into the scale function the plc enters stop. What am i missing here?

Fault is area error when reading, Incorrect area id: 10.

A hint if possible rather than the answer, have to learn somehow.

Thanks,
Barry
 
Copy the blocks you are using to a library, archive the library and attach to a post. We need to see the data and the call to your function to analyse what is going on.
 
Looking at your attached code above it seems to me you need to gain familiarity with indirect addressing before tackling your general purpose analogue proccesing loop.
Here's some examples to implement.

Task 1:-
Create a DB with 10 integers (1,2,3,4,5,6,7,8,9,10) in it. Write a function that will calculate the sum of the integers in the DB. The function should determine the number of integers in the DB from the length of the DB and return a DINT value.

Task 2:-
As task 1 but the DB contains 10 reals (101,102,103,104,105,106,107,108,109,110), the function should return a real value.
 
Cheers LD,

Thats is a great idea. Was trying to think of way to learn STL and I obviously bit off more than I could chew.

I will post my resulting code in the New Year for everyone to comment on.

Many Thanks
 

Similar Topics

the scale occasionally stops working and displays the message "no response from modbus" on the control screen . tunaylar - load line2
Replies
2
Views
144
Hi! I'm wondering if PLCs are used for small-scale production. I've got four machines doing different things with textiles, and I'm exploring the...
Replies
16
Views
1,363
I am having an issue writing a carriage return to my scale, I can manually push the print button the the scale and then read the buffer. The scale...
Replies
4
Views
1,128
Good afternoon. 1794-ie12 module available, channel set to 4...20 mA. According to the table from the manual, we get from 0 at 4mA to 30840 at...
Replies
5
Views
2,273
Anyone have a modbus map for one of their Scale Integrators? They have lots of info on their website and state it has Modbus TCP but no Modbus...
Replies
0
Views
848
Back
Top Bottom