Neuron S103 and fast input (or counter)
-
Hi,
for an application, I'm evaluating the possibility to catch fast pulse input signals.
In CODESYS I need to count them by a native internal counter or via interrupt routine.
Could someone help me? -
Reading the counters would be your best bet; I'm not sure if interrupts are supported in the current CODESYS implementation.
-
@tomas_knot said in Neuron S103 and fast input (or counter):
Reading the counters would be your best bet; I'm not sure if interrupts are supported in the current CODESYS implementation.
Ok,
have you some examples? Is there a possibility to reset the counter and read it again in subsequentially step? -
Hi Mike,
There are examples of reading the counters from group 1 in the demo application. For subsequent groups, use the 'RegistersToUdint' function from the library and map the two registers containing the counter of interest.
If you need to reset the counter whilst there are still pulses of interest occurring then there is always going to be a window of lost counts between the last read of the counter and when the reset occurs. The way to solve this problem is to keep a 'soft' counter and update it from the Neurons counter.
The Neurons counter is 32 bit and will roll over from 16#FFFFFFFF to 16#0, so in your application you can determine the change in counts by subtracting the last counts from the current counts and adding the result to a 'soft' counter, when you wish to reset just zero out the soft counter. As long as you are running fast enough that the counter hasn't increased by 16#7FFFFFFF between updates then unsigned arithmetic will handle the rollover situation.
At initialisation you need to read the counter value and then use it as the 'last count'. Be careful as you need to ensure modbus is running and you have a good value before initialising.
If you need your counter to be non-volatile then you will have to take care of that too.
regards David
-
thank you