Dear all,
I want to create a DPE (unsigned int) as part of a DP which increments itself by a rising edge of a an boolean DPE which is also part of the same DP. Of course this can be realized with a control script which runs in a separate control manager. But I asked myself if this couldn't be realized with a data point function, so it would be much easier to create new data points from the same type?! I know there the possibility to count edges with the statistical data point functions, but this has the disadvantage, that it only counts within the determined time range, couldn't be reset manually and it needs an archive config for the boolean value. A normal data point function isn't configurable with it's own value as input, because it causes a circle calculation and to use the own value as global value doesn't work because the value is read only once during initialization of the data point function. But anyway has somebody an idea how a simple counter that immediately increments itself after a rising edge with a data point function?
Thanks and best regards
Daniel
Edge counter with data point function
Search
-
daniel.ponader
- Posts: 34
- Joined: Tue Jan 10, 2012 1:40 pm
Re: Edge counter with data point function
Ok,I found a simple solution. The global values g1...gn are refreshed with ever calculation cycle, so it works fine if the counter value is defined as global value and the Boolean as parameter --> (p1)?++g1:g1
Re: Edge counter with data point function
Thanks for a nice solution!
Re: Edge counter with data point function
Hi,
I was thinking about this one but I got some issues:
- When you reset the counter, then on next trigger old value is used...
- All incrementation are delayed. You need TRUE / TRUE to have counter to 1. If you have a TRUE -> FALSE, counter is increased by 1 anyway. If you have FALSE -> TRUE nothing happens until next TRUE.
I am curious to know if you solved those issues, and if yes I would like to know your secret :cheer:
I was thinking about this one but I got some issues:
- When you reset the counter, then on next trigger old value is used...
- All incrementation are delayed. You need TRUE / TRUE to have counter to 1. If you have a TRUE -> FALSE, counter is increased by 1 anyway. If you have FALSE -> TRUE nothing happens until next TRUE.
I am curious to know if you solved those issues, and if yes I would like to know your secret :cheer:
-
daniel.ponader
- Posts: 34
- Joined: Tue Jan 10, 2012 1:40 pm
Re: Edge counter with data point function
Hello Alexandre,
in the first issue you're right, resetting of the counter is not possible...thanks for the hint. I hope to find a solution, maybe one of the ETM guys has a hint for us
But the incrementation itself works fine and only if the Boolean changes from 0-->1,important is to use the increment operator before the global variable: ++g1, not g1++! Otherwise you'll get the incremented value while the next trigger event.
Best regards
Daniel
Update: I just added a second Boolean for counter reset as parameter p2 and changed the data point function to : (p1&&!p2)?++g1:((p2)?g1=0:g1) -> so resetting of the counter works, if the p1 is false. If it's true the counter is set to 1 and it will be incremented by setting p2 again to true. This is not the ideal solution but I think it's not so bad.
Update2: with (p1&&!p2)?++g1:((p2&&!p1)?g1=0:((p2&&p1)?g1=0:g1)) the incrementation by reset events (p2: false to true) if p1 is true is avoided, but if the the counter is still set to 1 if p1 is true and p2 changes from true to false.
in the first issue you're right, resetting of the counter is not possible...thanks for the hint. I hope to find a solution, maybe one of the ETM guys has a hint for us
But the incrementation itself works fine and only if the Boolean changes from 0-->1,important is to use the increment operator before the global variable: ++g1, not g1++! Otherwise you'll get the incremented value while the next trigger event.
Best regards
Daniel
Update: I just added a second Boolean for counter reset as parameter p2 and changed the data point function to : (p1&&!p2)?++g1:((p2)?g1=0:g1) -> so resetting of the counter works, if the p1 is false. If it's true the counter is set to 1 and it will be incremented by setting p2 again to true. This is not the ideal solution but I think it's not so bad.
Update2: with (p1&&!p2)?++g1:((p2&&!p1)?g1=0:((p2&&p1)?g1=0:g1)) the incrementation by reset events (p2: false to true) if p1 is true is avoided, but if the the counter is still set to 1 if p1 is true and p2 changes from true to false.
Re: Edge counter with data point function
Ah thanks for hint. I was doing g1++ 