Hello all,
I'm coming to you for a small coding issue...
I'm working on S7 5.5 (coding a S7 300) for self training (I'm a newbies).
I explain the problem : I use the siemens routine as base time :
UN T 1
L S5T#500MS
SV T 1
NOT
BEB
L DB1.DBB 2
INC 1
T DB1.DBB 2
It generate a binary number in DB1.DBB2 (global variable).
My time set point is a byte variable in hex stored in DB1.DBB4 (global variable).
I want to generate a blinking bit that acts when this set point (for example 8 (hex) is reached).
It means 8 x 500 MS, for instance 4 secs.
The set point is a byte variable that I increase or decrease by action on push buttons. There are a max and min limit that are also adjustable.
I already tried to mask the value with xow or uw, but it seems to simple for this problem.
I tried also with mathematics funtions, but can't achieve good results...
Have anyone some ideas to solve this problem ????
Да свиданя
AWL crazy loop
-
- Posts: 3
- Joined: Wed Apr 24, 2013 6:13 pm
Re: AWL crazy loop
Hello,
I found the solution ))))
I tryed it on plcsim and it's working right....
I first determine the most significant bit in the set point. (in ex bit n°3)
Then I reverse the upper bits (in ex 1111_1000)
Then I inverse those bits (in ex 0000_0111)
Then I And Word with current clock number (in ex 0000_0111 & 0010_0010 when clock is on 34(decimal) -> result 0000_0010)
could be 0000_0111 & 0010_0011 when clock is on 35(decimal) -> result 0000_0011
Then I And Word with set point (in ex 0000_0010 & 0000_0010)
And finally I stat my blinking bit if this result is on 1.
Hereafter the tricky code
I think it's possible to optimize this code. (a bit)
I'll make it later....
I found the solution ))))
I tryed it on plcsim and it's working right....
I first determine the most significant bit in the set point. (in ex bit n°3)
Then I reverse the upper bits (in ex 1111_1000)
Then I inverse those bits (in ex 0000_0111)
Then I And Word with current clock number (in ex 0000_0111 & 0010_0010 when clock is on 34(decimal) -> result 0000_0010)
could be 0000_0111 & 0010_0011 when clock is on 35(decimal) -> result 0000_0011
Then I And Word with set point (in ex 0000_0010 & 0000_0010)
And finally I stat my blinking bit if this result is on 1.
Hereafter the tricky code
I think it's possible to optimize this code. (a bit)
I'll make it later....
code
Show
Code: Select all
// Determine the most significant bit in set point
L DB1.DBB 4 //Load time set point
T DB1.DBB 12 //put it in temporarly value
L W#16#1 //Load minimum value (1)
<=I
SPB FINO //If minimum value reached
L W#16#0 //load 0
T DB1.DBB 13 //Put it in MSB counter (most significant bit)
RETO: L DB1.DBB 12 //Load the time set point (temp val)
RRD 1 //rotate right double 1 bit
T DB1.DBB 12 //Put in temp val
L DB1.DBB 13 //Load MSB counter
INC 1 //add 1
T DB1.DBB 13 //save new value
L DB1.DBB 12 //Load time set point (temp val)
L W#16#1 //Load 1
>I //>????
SPB RETO //if yes, loop whenever > 1
SPA FINI //Otherwise end loop
FINO: L W#16#0 //Load 0
T DB1.DBB 13 //The 0 bit is MSB
FINI: NOP 0
//Setting up the bit mask
L B#16#FF //Load just 1 in the accu
T DB1.DBB 12 //Put them in the temp val (which is a bit mask now)
BOUL: SLW 1 //shift left word 1
T DB1.DBB 12 //store in temp value
L DB1.DBB 13 //MSB bit number
L B#16#0 //Load zero
==I //if zero
SPB ZERO //goto zero
L DB1.DBB 13 //load the MSB bit number
DEC 1 //decrement 1
T DB1.DBB 13 //store in bit number
L DB1.DBB 12 //Load bit mask
SPA BOUL //loop to bool -> until bit mask is > 0
ZERO: L DB1.DBB 12 //Load the mask (it has now 111 on the bits upper MSB)
INVI //inverse word
L W#16#FF //load only 111 on a byte
UW
T DB1.DBB 12 //The MSB and upper are now 0 and the rest is 1
L DB1.DBB 2 //Load the current time
UW //logical and
L DB1.DBB 4 //Load time set point
==I //result of UW is equal to time set point
SPBN FINU //not equal finish
S DB1.DBX 9.0 //otherwise set blink bit
FP DB1.DBX 9.1 //store flank positive
= DB1.DBX 9.2 //9.2 at one on one OB1 cycle
FINU: R DB1.DBX 9.0 //reset du bit blink
-
- Posts: 2
- Joined: Fri Jun 11, 2010 7:20 pm
Re: AWL crazy loop
Hello,
If not the time, the time started.
If the time is on, the word counter count.
So the timer works independent.
BEB= Block end conditional; that means if the status bit=1, no counting in the db-word.
BR from Polkovice.
ha
If not the time, the time started.
If the time is on, the word counter count.
So the timer works independent.
BEB= Block end conditional; that means if the status bit=1, no counting in the db-word.
BR from Polkovice.
ha