Post Go back to editing

Timer with ABCD comparator


Dear Team ,

I have a concern regarding the ABCD comparator and timer with stop start and reset control on Sigma Studio GUI 

I am trying to compare two sine waves ,one with some decay and the other with a normal fixed amplitude for the entire length of time.

After I feed these two inputs to an ABCD conparator,I would like the output of the Comparator to send a 1 until and unless the sample value in pin a is less than sample value in pin b but once the reverse happens I would want the timer to be stopped by the 0 output of the Comparator and hence stop counting any further samples once the decay is over . However I am not getting fruitful results .

Can anyone help 

  • FormerMember
    0 FormerMember
on Mar 19, 2021 2:19 AM in reply to KJBob

Dear Bob,Ken 

The project with level comparison still does not give me expected result for slew rate set to 2 and set to 4 

I get values of 0.708ms and 5.33 ms while the expected values are 0.3ms and 1.5 ms respectively .

Please explain why even this level comparison isn't working ...

If you can tabulate the values observed versus expected it's much helpful to verify at my end as well 

  •      Hello Hermione & Ken,

         This is the tabulation I found with the level comparison.  The expected time is not exactly 5 time constants (which is a common approximation) but mathematically it's equal to  - ln(1-0.99) = 4.605  Thus I used this value to compute the theoretical or expected times for a 99% rise.

    Now, why are the times returned for the lowest slew settings (like 2 or 4) so far off?  It has to do, not with the Slew Volume Control or the measurement, but rather, the sine wave itself.  For example, with the slew # at 10 and the result reasonably accurate, the Sine oscillator plus the Slew Volume Control yields the rising sine wave shown below  (I added a DAC at the Slew Volume Control's output and scoped it):

         Here we can clearly see the rising envelope (level) of the rising sine wave -- which the Slew Volume Control provides.  It produced a good count.

         When we set the Slew # to 2, the result does not reflect the Slew setting.  Here's the output:

    This time, we don't see the action of the Slew Volume Control at all -- the trace is dominated by the sine wave itself.  Thus at the moment the sine wave reaches its first peak at about 0.33 mS, the Slew hasn't reached its 99% value -- so the thing keeps on counting.  It has to wait for the second peak at 0.7 mS.  This is what the counter measured!  (Note that the Peak Envelope block works with both positive and negative peaks -- it's a full-wave rectifier, or Absolute Value in DSP speak.  If it weren't, the result would have been even worse.)

         If we increase the Sine oscillator to 10 kHz, there's more peaks for the circuit to work with and we measure 17 counts and 0.35 mS -- a better result.  Generally, we cannot expect perfect accuracy in these measurements.  Although the DSP operates digitally, it's modeling analog signals.  An interesting example is Sample Rate Converters (SRCs) -- although they're digital in and digital out, they still have analog specs such as signal-to-noise (SNR).

         Ken's circuit slows the operation down by a factor of 1000 -- 1 S = 1 mS -- so you can see similar results on its Real-Time Displays.  'Playing' with it can be quite instructive.

         Best regards,


  • FormerMember
    0 FormerMember on Mar 20, 2021 4:00 AM in reply to KJBob

    Dear Bob,

    Appreciate your efforts ! 

    Can you provide the formula you used to calculate the expected and also tell me why this is better than the previous formula .

    Also I'd like to re-iterate here that since the circuit works well for slew rate 1 why should it fail for slew rate 2 there some logical problem with my logic in the schematic ? ...for slew set to 1 results almost match expected whereas this isn't the case of slew rate 2 or 4 in which case can I get the acceptable margin of error or a tolerance range .This would be a conclusion to all our efforts .

    Much thanks !


  •      Hello Hermione,

         The rising slew follows the equation:

    y = 1 - e^ ( -t / T)   where y is the linear gain which begins at zero and rises toward one,  t is elapsed time, and T is the time constant which is a property of the slewing which depends upon the slew number.

    We can solve this backwards and get:

    (t / T) =  - ln (1 - y)   where (t / T) represents the number of time constants we need to wait to achieve the final gain y.  For example, y = 0.99, then:

    (t / T) = - ln (1 - 0.99)   = - ln (0.01)  = 4.605 ....

    The Peak Envelope Block tracks the sine wave as it rises from zero, then holds onto its maximum value -- which will be near 1.0 for a 0 dB sine wave, or about 0.32 tor a -10 dB one.  Once the peak has passed, the sine wave slopes downward while the Peak Envelope Block's output would normally decay slowly down toward zero until the next peak occurs.  Since you've set the decay rate to zero, it never decays but instead remains at the peak value.

    With very small slew numbers, the slew completes while the sine wave is still in its first upward slope.  In this case the output of the Peak Envelope Block is the same as its input, and the count is correct.  With large slew numbers, the slewing is slow, covering many cycles of sine wave -- so the the circuit finds one of these peaks and provides a reasonably close count.  It's when the slewing time to 99% occurs between 0.25 mS (the first peak at 1 kHz) and 0.75 mS (the second peak) that you get poor results.

         There is no error in your logic -- it's just an limitation of this method generally.  If you need only to measure the slewing time of the Slew Volume Control (or similar device) where you have access to the sine wave both before and after it, you can get better results by substituting Absolute Value blocks for the Peak Envelope Blocks.  In fact, you need not use a sine wave at all -- the Slew Volume Control works with DC, so using a DC input gets rid of the hassles with the sine wave altogether.

        For the general case, for example, comparing the levels of two sine sources which may differ in frequency and phase, you really need Peak Envelope Blocks on each -- and live with the resulting errors at certain rates of rise.

         Best regards,