ianbuckley Posted March 3, 2011 Report Posted March 3, 2011 I will be using an S7-315 for a project. I don't have a S7-300 here to try this logic. I am looking to do a simple calculation to determine a rate. I have an SFB4 timer that cycles every "UpdateRate". I count pulses from a sensor on a shaft during this duration. I just want to take 60000 * "Counts" / "UpdateRate" = "CountsPerMin". "Update Rate" is declared as TIME. "Counts" is declared as INT. I would like to return "CountsPerMin" as INT. I can't seem to do math on TIME variables in ladder, so I made some examples using MD locations and switched to STL view. It looks like I can do the following to get what I want: L "Counts" ITD L L#60000 *D L "UpdateRate" /D T "CountsPerMin" The LAD-STL conversion has transfers, loads of the same variable and NOPs mixed in, but unless I need to clear an acculumlator somewhere I don't think they are necessary. The problem is the result of /D would normally be a DINT. If "CountsPerMin" is declared as INT, will it store the result properly? Similarly, is there a way to convert DINT to INT other than manually using (address)+2? I am planning on using this as an FC with "Counts" and "UpdateRate" as inputs and "CountsPerMin" as output, so I don't see how to do just (address)+2. On a somewhat related note, is there a way to compare the value of a byte with a constant (if MB20=FF Hex, then...) ? Thanks for any insight. Ian
Groo Posted March 3, 2011 Report Posted March 3, 2011 There is no DINT to INT, you can L "DINT_WORD" and then T "INT_WORD" but it relies on you managing the data, it would transfer the lower word into "INT_WORD". Therefore you would need to program in a comparator if you were unsure that it would be in the INT range. If within the INT range then it will transfer OK and you will get the correct answer (remember the 16th bit is +/-). For the last bit L MB20 L 256 <>I JC OVER "Code for MB20 = 256 JU NEXT <== If you don't want to continue with the enxt instruction OVER: "Rest of Code" where MB20 <> 256 NEXT: "Jump destination after code for MB20 = 256
Groo Posted March 3, 2011 Report Posted March 3, 2011 (edited) S7-300 Instruction List Download the Instruction List book Edited March 3, 2011 by Groo
ianbuckley Posted March 3, 2011 Author Report Posted March 3, 2011 Thanks for the confirmation. I guess I had skipped over the part where it says T stores the information based on the destination variable declaration. Just a thought, wouldn't B#16#ff be 255? All of the byte swapping and data types get confusing going back and forth between manufacturers. Thanks, Ian
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now