• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Neuron S103 and fast input (or counter)

    CODESYS
    3
    5
    2235
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mikeardy last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • T
        TomasKnot last edited by

        Reading the counters would be your best bet; I'm not sure if interrupts are supported in the current CODESYS implementation.

        1 Reply Last reply Reply Quote 0
        • M
          mikeardy last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • D
            DavidCozens last edited by

            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

            1 Reply Last reply Reply Quote 0
            • M
              mikeardy last edited by

              thank you

              1 Reply Last reply Reply Quote 0
              • First post
                Last post