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

    Neuron S103 and fast input (or counter)

    Scheduled Pinned Locked Moved CODESYS
    5 Posts 3 Posters 3.0k Views
    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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post