Skip to content

Counting time between pulses

I'm trying to count pulses and the time between those pulses, but this time varies every 5 seconds by 50 ms.

My setup

  • 2152 CPU that generates pulses at different intervals. Right now I'm using the pulse with 200 ms between two pulses
  • Another 2152 CPU that has this pulse as an input. Pulse counting is done in a cycle of 1 ms on ESM1. All other processes are on ESM2

My program counts the amount of pulses per 5 minutes and the average pulse time. Once every 5 seconds the time between the pulses increases to 250 ms and then goes back to 200 ms. This creates an average pulse time that is slightly higher then 200 ms. Also the pulse count is off by 15 pulses per 5 minutes.

I have tried several things to remedy this problem, but nothing seems to work. Pulses with a longer time between pulses also have this strange offset. Even clearing the whole program except for the pulse calculation doesn't work.

Am I missing something?

Comments

  • Can you tell us how the pulses are generated?

    e.g. is it in a Program instance running in a cyclic task?

    What is the period of the cyclic task?

    Can you show us the code that generates the pulse?

    How is the signal transmitted to the other device?

  • Yes, pulse generation is done on a 1 ms cycle. Testing the pulses with another (older) controller shows the exact amount of pulses in 5 minutes. Showing these pulses in the logic analyzer shows also an exact pulse.

    The signal is sent to the other CPU via a relay.

    The code is really simple:

    IF PulsesPer5Minutes > 0 THEN
        PulsInterval_ms := TO_TIME(300000 / PulsesPer5Minutes);
    ELSE
        PulsInterval_ms := TO_TIME(0);
    END_IF;
    
    Tmr_Puls(IN := NOT Tmr_Pause.Q, PT := PulsInterval_ms, ET => Puls_Time);
    
    Tmr_Pause(IN := Tmr_Puls.Q, PT :=  TIME#0.080s, ET => Pause_Time);
    
    IF NOT Tmr_Puls.Q THEN
        Output := TRUE;
    ELSE
        Output := FALSE;
    END_IF;
    
  • How is Output connected to the I/O process data? Does it use an External reference to a Global variable, or does it use GDS Port variables?

    Are there any settings for the Update task and/or Trigger task in the Axioline F Settings window?


    If we can these settings in your project, we should be able to explain what you're seeing and suggest a solution.

  • Thank you. I added these tasks to a 1 ms cycle and now it is working.

Sign In or Register to comment.