Charles Wagner
Charles Wagner

Reputation: 123

How can I build a timer to count the total time of when my signal is on during the simulation?

I have a boolean signal that varies between 1 and 0. How can I build a subsystem in Simulink to count the total time during the simulation that the signal is on?

I am using Matlab 2019a.

Upvotes: 0

Views: 3560

Answers (1)

Phil Goddard
Phil Goddard

Reputation: 10772

Use your signal as the enable signal of an Enabled Subsystem, where the subsystem contains a simple counter. The input to the counter needs to be the discrete sample rate (0.2 in the model shown below), the Enable block (inside the subsystem) needs to be set to hold its state when disabled (which should be the default), and the out port needs to be set to hold the output when disabled (which should be the default.)

Something similar can be constructed to count time when using a variable step solver, but the contents of the subsystem are just a bit more complex.

Simulink Model

Upvotes: 1

Related Questions