6/5/2020 9:49 PM | |
Joined: 3/16/2015 Last visit: 10/10/2021 Posts: 1250 Rating:
|
Difficult to understand, form those snippets, what you're trying to do. Your first post gave me the impression you are doing some kind of positioning and wanted to use interrupts which is quite common. I also do not understand if you are using two HSC instructions with two counters or one counter. But I understand you have everything working the way you want and just want something "nicer" and in that case I will just describe my general observations. The use of comparison with ID1000 is fine when you have a large margin to work with because it will be affected by cycle scan and how fast the counter is counting (how fast the pulses are coming). So going by your first post, I would do the following: -I would use CTRL_HSC_EXT but I will describe the legacy one for you. -In hardware configuration for HSC1 and enable "Generate interrupt for counter value equals reference value event" and setup and create and interrupt OB. -In FC1 I call HSC instruction as you did and either in the same (FC1) or another I will have code that sets the values for NEW_RV and sets RV bit to true. The values will depend on the process and where I am positioning. First value will be starting position, then when that position is reached and the process is moving to the next stage then the value will be set to the next position. -When the counter reaches the reference value the interrupt I set in hardware configuration will be triggered and inside the interrupt I will do something which entirely depends on the process. Let's say I have a conveyor moving and I want to stop it at that position then I will have an immediate call to reset the output controlling the motor Q0.0:P which has an immediate effect and will insure greater positioning accuracy. In the network below it I will either set a global tag to indicate that position has been reached with the purpose of updating the status in my code or will directly call the block controlling motor execution. (this is tricky and can increase scan cycle if not executed efficiently). -Now back in FC1 or wherever NEW_RV is and with the help of the tag that was set in the interrupt I will move on to the next phase in the process and set NEW_RV to the next position. What is the purpose of M80.1 placed at SR.Q instruction? The attachment is form our old and missed friend William_B AttachmentInterrupt HSC S71200.pdf (345 Downloads) |
6/9/2020 4:06 AM | |
Joined: 3/16/2015 Last visit: 10/10/2021 Posts: 1250 Rating:
|
So you have the interrupt issue figured out and able to set new value and all that is working the way you want it. Excellent.
How many times you call CTRL_HSC instruction is entirely dependent on your code and how it is structured. Obviously you need to call it at least once and the question is should you call it again? Calling the instruction updates the counter (actually a counter system function) with the actual parameters that you interfaced at the instruction like NEW_CV and RV and the rest. So let's say after network 2 in FC1 and when the comparison of ID1000 is true you want the counter value to be reset to zero or any other number and the code following it will be influenced by the counter value then yes absolutely call the instruction again after the comparison to have the counter value take effect before the cycle scan is done. If your program requires that much precision you would know it right away. This is sometimes done in the hardware interrupt for reference value; if you want the counter to have a different value as soon as the reference value is reached you can call the instruction in the hardware interrupt OB to change NEW_CV. Or another example that applies to your first post would be setting New_RV to 20 and then in the interrupt that is triggered when Count Value= Reference Value, you would set New_RV to 50 and RV to true followed by a call to HSC_CTRL instruction. That would update the reference value the quickest. ID1000 memory is read at the beginning for the scan cycle and depending on the length of the cycle and how fast the pulses are coming there may be a difference in the value. If you suffix it with a colon and the letter P like this ID1000:P you will get the current value of the counter; the :P is causes and immediate read or write. AttachmentCTRL_HSC.mov (411 Downloads) |
Last edited by: Kal.A at: 06/09/2020 04:36:36 |
|
This contribution was helpful to
1 thankful Users |
Follow us on