Author Topic: Duty Cycle detection  (Read 13096 times)

0 Members and 2 Guests are viewing this topic.

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Duty Cycle detection
« on: October 12, 2017, 08:10:58 am »
I need to detect whether the duty cycle from a circuit drops below a certain value.
Frequency: 2kHz
Amplitude: TTL (0 to 5V)
Step response: an hour or more (it is a very slow system)
Requirement: detect whether the duty cycle is lower then a adjustable value, most likely less then around 70%.
Hysteresis is required, say about 5 to 10%.

When the duty cycle drops below the preset value a TTL output needs to be triggered. When the duty cycle recovers above the preset value+hysteresis the TTL output needs to be reset. Changes in duty cycle take several hours. However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.

A circuit with a flipflop and 2 comparators is my preference. And I want a hardware solution, no software with microcontroller: the circuit has to be universally used without need for software. at a later stage this circuit wil be used in a controller for further processing.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6221
  • Country: de
Re: Duty Cycle detection
« Reply #1 on: October 12, 2017, 08:32:35 am »
Some kind of monostable, where decision point is if the monostable or your PWM pulse times out first. A 4538 might do it, but a counter/timer would be more stable.
 
The following users thanked this post: 84750Erik

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4700
  • Country: au
  • Question Everything... Except This Statement
Re: Duty Cycle detection
« Reply #2 on: October 12, 2017, 08:36:01 am »
the circuit your describing is a missing pulse detector, e.g. using the good old 555 timer,
 
The following users thanked this post: 84750Erik

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: Duty Cycle detection
« Reply #3 on: October 12, 2017, 09:23:19 am »
Quote
A circuit with a flipflop and 2 comparators is my preference. And I want a hardware solution, no software with micro-controller: the circuit has to be universally used without need for software. at a later stage this circuit will be used in a controller for further processing.


A controller can "appear" as a universal part with proper software and HW design.

This can be easily done with a PSOC or for that matter just about most low end controllers. Solution
would be 1 chip.

What is the accuracy and resolution of the duty cycle measurement/decision you want to male ?


Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 
The following users thanked this post: 84750Erik

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3320
  • Country: gb
Re: Duty Cycle detection
« Reply #4 on: October 12, 2017, 10:59:06 am »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?
 
The following users thanked this post: 84750Erik

Online David Hess

  • Super Contributor
  • ***
  • Posts: 17117
  • Country: us
  • DavidH
Re: Duty Cycle detection
« Reply #5 on: October 12, 2017, 01:40:02 pm »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?

If the frequency is not stable then this is what I would do.  The input levels to the filter and the comparator need to either be stable or ratiometric which means truing up the TTL signal.  Note that TTL is *not* 0 to 5 volts.
 
The following users thanked this post: 84750Erik

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #6 on: October 12, 2017, 06:12:23 pm »
Hi Mike, it is not pwm but you come closest to what I need.

555 is out because trigger points cannot be set (resistors are internal); I received a circuit to be tested in LTSpice, could not get duty cycle detection at a higher then 50% trigger point. I need to detect from 80% downward.

A 1st degree low pass into the negative of a comparator (339 or 393), and on the positive the reference voltage. Hysteresis with resistor in positive feedback. And a buffer (I use a spare CD4093 lying around) before the LP filter.

Just tested it out, works perfect for my needs.
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #7 on: October 12, 2017, 06:14:18 pm »
555: unable to set trigger point beyond 50% duty cycle. I may miss something, but I tested a circuit on LTspice. Maybe you have a better schematic?
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #8 on: October 12, 2017, 06:16:24 pm »
Quote
A circuit with a flipflop and 2 comparators is my preference. And I want a hardware solution, no software with micro-controller: the circuit has to be universally used without need for software. at a later stage this circuit will be used in a controller for further processing.


A controller can "appear" as a universal part with proper software and HW design.

This can be easily done with a PSOC or for that matter just about most low end controllers. Solution
would be 1 chip.

What is the accuracy and resolution of the duty cycle measurement/decision you want to male ?


Regards, Dana.
No controller and I mean it: hardware solution is cheaper, faster, less current consumption and I can connect my circuit to any kind of controller later on to process the result.
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2129
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Duty Cycle detection
« Reply #9 on: October 12, 2017, 06:19:20 pm »
+1 for MikerJ

Just use a low pass filter and a comparator.
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 
The following users thanked this post: 84750Erik

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #10 on: October 12, 2017, 06:19:52 pm »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?

If the frequency is not stable then this is what I would do.  The input levels to the filter and the comparator need to either be stable or ratiometric which means truing up the TTL signal.  Note that TTL is *not* 0 to 5 volts.
Fully agree, I am sorry, I should have specificied: 0 to 5V. Filter and comparator fed by buffer (I used spare CD4093 lying around), just been testing, works perfect: I can adjust trigger point from 90% down to 40% (duty cycle does not go lower), hysteresis adjustable. I did not know/realise how valuable you all are! Thank you very much!!
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #11 on: October 12, 2017, 06:25:14 pm »
Quote
A circuit with a flipflop and 2 comparators is my preference. And I want a hardware solution, no software with micro-controller: the circuit has to be universally used without need for software. at a later stage this circuit will be used in a controller for further processing.


A controller can "appear" as a universal part with proper software and HW design.

This can be easily done with a PSOC or for that matter just about most low end controllers. Solution
would be 1 chip.

What is the accuracy and resolution of the duty cycle measurement/decision you want to male ?


Regards, Dana.
Accuracy and resolution do not matter much, repeatability does.
The actual duty cycle may vary due to hardware tolerances, and variations in duty cycle will be less then 10% per day max, in a one way direction: down. Very slowly. I plan on doing measurements once an hour, get a DC voltage or even simpler: either on or off, and process that further in a controller.
 

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: Duty Cycle detection
« Reply #12 on: October 13, 2017, 12:19:01 pm »
w/o using an external xtal a PSOCs main osc is +/- 2%, so that
would govern its timing accuracy and repeat-ability in a duty cycle
measurement.

That's PSOC 4 the low end part.  This could b e done completely in HW
and toggle a pin. Only code needed would be to start the components
inside PSOC. Or use code to do measurement with PSOC via ISR or
b oth.


Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19904
  • Country: gb
  • 0999
Re: Duty Cycle detection
« Reply #13 on: October 13, 2017, 06:14:21 pm »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?

If the frequency is not stable then this is what I would do.  The input levels to the filter and the comparator need to either be stable or ratiometric which means truing up the TTL signal.  Note that TTL is *not* 0 to 5 volts.
Yes, I agree. use a comparator to get the TTL voltage to a known level, low pass filter it and use another comparator to compare it to a fixed reference voltage.

See attached.



U1 converts the signal to a definite 5V square wave. The threshold is 2V with 50mV of hysteresis. This is low pass filtered by R6 and C1. U2 compares it against 70% of the supply voltage, around 3.5V, with around 180mV of hysteresis (about 5%).

Note that this circuit might benefit from a comparator with a higher common mode input range or run of a higher supply voltage, which might require changing the values of R1 to R4. The LM393 is only specified to 1.5V below the positive rail, yet this circuit takes the inputs on U2 to nearly 3.6V.
« Last Edit: October 13, 2017, 06:24:27 pm by Hero999 »
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22374
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Duty Cycle detection
« Reply #14 on: October 13, 2017, 06:29:34 pm »
Is the frequency stable and guaranteed 2kHz +/- (margin proportional to the duty cycle threshold margin)?

If so, a missing pulse detector is a fine solution.  It's also the fastest possible solution (latency of ~1 cycle on average).

If not, an LPF + comparator is pretty good, minding that the LPF needs to roll off considerably lower than whatever the true minimum frequency is.  This of course isn't a problem over the requested duration (sub 1 hour).

Don't forget hysteresis on the comparator, to prevent false triggers from the LPF's leftover ripple when it's borderline near the threshold.

You will want to use an active filter, to keep component size and cost down.  Although if the 220k + 4.7uF shown above is acceptable, that's not too bad.  Try to avoid using electrolytic capacitors here.  Film caps are very large, but good.  Tantalum is actually quite reasonable (okay leakage, stable value, no danger of shorting out a supply!).

If very low supply consumption is desirable, you can choose some nice slow CMOS op-amps and comparators.  A comparator with response time in the 5us range sips little enough current that it can run from a battery for months, maybe even years on end.  They perform quite well, when you don't need screaming speed. :)

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: 84750Erik

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #15 on: October 13, 2017, 07:50:09 pm »
Is the frequency stable and guaranteed 2kHz +/- (margin proportional to the duty cycle threshold margin)?

If so, a missing pulse detector is a fine solution.  It's also the fastest possible solution (latency of ~1 cycle on average).

If not, an LPF + comparator is pretty good, minding that the LPF needs to roll off considerably lower than whatever the true minimum frequency is.  This of course isn't a problem over the requested duration (sub 1 hour).

Don't forget hysteresis on the comparator, to prevent false triggers from the LPF's leftover ripple when it's borderline near the threshold.

You will want to use an active filter, to keep component size and cost down.  Although if the 220k + 4.7uF shown above is acceptable, that's not too bad.  Try to avoid using electrolytic capacitors here.  Film caps are very large, but good.  Tantalum is actually quite reasonable (okay leakage, stable value, no danger of shorting out a supply!).

If very low supply consumption is desirable, you can choose some nice slow CMOS op-amps and comparators.  A comparator with response time in the 5us range sips little enough current that it can run from a battery for months, maybe even years on end.  They perform quite well, when you don't need screaming speed. :)

Tim
The pulses being detected my miss here and there, the frequency is within 5%, so I would say good enough for a comparator solution. And yes, very low power consumption is preferred (battery operation), so your information is most helpful!
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #16 on: October 13, 2017, 07:51:13 pm »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?

If the frequency is not stable then this is what I would do.  The input levels to the filter and the comparator need to either be stable or ratiometric which means truing up the TTL signal.  Note that TTL is *not* 0 to 5 volts.
Yes, I agree. use a comparator to get the TTL voltage to a known level, low pass filter it and use another comparator to compare it to a fixed reference voltage.

See attached.



U1 converts the signal to a definite 5V square wave. The threshold is 2V with 50mV of hysteresis. This is low pass filtered by R6 and C1. U2 compares it against 70% of the supply voltage, around 3.5V, with around 180mV of hysteresis (about 5%).

Note that this circuit might benefit from a comparator with a higher common mode input range or run of a higher supply voltage, which might require changing the values of R1 to R4. The LM393 is only specified to 1.5V below the positive rail, yet this circuit takes the inputs on U2 to nearly 3.6V.
This is it!!!

Thanks, will be built and fine-tuned.
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #17 on: October 13, 2017, 07:53:36 pm »
Low pass filter the PWM and use a conventional comparator with feedback for hysteresis?

If the frequency is not stable then this is what I would do.  The input levels to the filter and the comparator need to either be stable or ratiometric which means truing up the TTL signal.  Note that TTL is *not* 0 to 5 volts.
(...)

Note that this circuit might benefit from a comparator with a higher common mode input range or run of a higher supply voltage, which might require changing the values of R1 to R4. The LM393 is only specified to 1.5V below the positive rail, yet this circuit takes the inputs on U2 to nearly 3.6V.
Can you suggest a comparator per your latest sentence please?
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1767
  • Country: se
Re: Duty Cycle detection
« Reply #18 on: October 13, 2017, 09:45:10 pm »
No controller and I mean it: hardware solution is cheaper, faster, less current consumption and I can connect my circuit to any kind of controller later on to process the result.
To each their own, I won't try to convince you otherwise, but I would like to understand the reasoning behind this choice.
  • Cheaper:
    The smallest PIC (SOT23-6) with an analogue comparator costs on Digikey almost exactly as one LM393 (in single quantity). Even assuming the passives as free, it's more expensive unless a large number of unit is produced.
  • Faster:
    With the LPF solution (very nice one, Hero999!), not really. In any case, it would not seem to be an important point, given the times at play.
  • Less current:
    The resistive dividers to set the thresholds in the analogue solution draw by themselves more than the MCU, even without using sleep modes.
  • Connectivity:
    No special advantage for either solution. The PIC might be more versatile (though not much, given its limitation).

The above without taking into account a more complex layout and an increased BOM.
Of course, a negative side is that one needs to write the firmware.
Nandemo wa shiranai wa yo, shitteru koto dake.
 
The following users thanked this post: rs20

Offline Someone

  • Super Contributor
  • ***
  • Posts: 4928
  • Country: au
    • send complaints here
Re: Duty Cycle detection
« Reply #19 on: October 14, 2017, 12:24:45 am »
No controller and I mean it: hardware solution is cheaper, faster, less current consumption and I can connect my circuit to any kind of controller later on to process the result.
To each their own, I won't try to convince you otherwise, but I would like to understand the reasoning behind this choice.
I agree this seems like an ideal job for a microcontroller and a small part with appropriate sleep modes and power gating would have vanishingly tiny power consumption (the fun of having all the power gating configurable inside the chip). Microcontrollers can be used as universal type chips for all sorts of functions and delivered as a black box, the interfaces in and out would be simply TTL/CMOS here. The requirement for me that jumped out and screamed embedded micro was this one:
] Changes in duty cycle take several hours. However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.
But that seems to have been poorly explained and the OP has made it clear they're not going to think about microcontrollers.
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #20 on: October 14, 2017, 01:54:48 am »
No controller and I mean it: hardware solution is cheaper, faster, less current consumption and I can connect my circuit to any kind of controller later on to process the result.
To each their own, I won't try to convince you otherwise, but I would like to understand the reasoning behind this choice.
  • Cheaper:
    The smallest PIC (SOT23-6) with an analogue comparator costs on Digikey almost exactly as one LM393 (in single quantity). Even assuming the passives as free, it's more expensive unless a large number of unit is produced.
  • Faster:
    With the LPF solution (very nice one, Hero999!), not really. In any case, it would not seem to be an important point, given the times at play.
  • Less current:
    The resistive dividers to set the thresholds in the analogue solution draw by themselves more than the MCU, even without using sleep modes.
  • Connectivity:
    No special advantage for either solution. The PIC might be more versatile (though not much, given its limitation).

The above without taking into account a more complex layout and an increased BOM.
Of course, a negative side is that one needs to write the firmware.
You convinced  me.
I know AVR controllers (Atmega328, Arduino,..) and I have a bit of C++ experience.
Please give me some input o how to tackle this?

 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #21 on: October 14, 2017, 02:10:21 am »
(...)
I agree this seems like an ideal job for a microcontroller and a small part with appropriate sleep modes and power gating would have vanishingly tiny power consumption (the fun of having all the power gating configurable inside the chip). Microcontrollers can be used as universal type chips for all sorts of functions and delivered as a black box, the interfaces in and out would be simply TTL/CMOS here. The requirement for me that jumped out and screamed embedded micro was this one:
] Changes in duty cycle take several hours. However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.
But that seems to have been poorly explained and the OP has made it clear they're not going to think about microcontrollers.
I am truly sorry, I hope to be able to explain better: please let me know what it is that was not explained well?
And after both of the previous posts here I have been convinced to at least try and experiment with a microcontroller solution.

I had thought it would not be possible to get a digital controller to verify duty cycle from a frequency that is stable within 10% (worst case) and where the pulses do get missed from time to time, and where the drift in duty cycle is downward over a perios of days/weeks and an upward correction takes hours. And most likely my hardware schooling made me prejudiced. So, I listen to you: please let me know what and how this can be done with a controller.
 

Offline Someone

  • Super Contributor
  • ***
  • Posts: 4928
  • Country: au
    • send complaints here
Re: Duty Cycle detection
« Reply #22 on: October 14, 2017, 04:27:47 am »
However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.
This is confusing, measurement of what is once per hour? How is that timed/triggered/decided? A small microcontroller can stay in a low power mode and wake up as often as needed, then this is a simple design:

Start a timer and set an interrupt to occur on the edges of the signal being measured.
In the interrupt store the timer value and the polarity of the signal (add debouncing here if needed to clean up the edges).
Once you have 3 edges then you can calculate the duty cycle, make a decision, turn everything to low power and go back to sleep (repeat and filter if you want to reduce noise or cover missing pulses).

Some controllers will even have timer capture hardware that can do this with more determinism than a simple interrupt, but thats more accuracy than you've suggested you need. A timer at only 1MHz has 0.2% resolution for the duty cycle of a 2kHz signal. By measuring the duty cycle and the period you are now only concerned with the short term stability of the clock source and not its accuracy so the onboard low power oscillator will likely be sufficient. Even the larger Atmel parts you are already familiar with will wait in low power modes of a few uA, so lower power consumption is going to be hard to achieve with a comparator, reference, and biasing.
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #23 on: October 14, 2017, 04:34:42 am »
However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.
This is confusing, measurement of what is once per hour? How is that timed/triggered/decided?(...)
The purpose is to have a reading once an hour of the duty cycle of a sensor output. Since this sensor too has to be woken up and since it may take several seconds to stabilise then the reading of a stable and reliable measurement may take several seconds. But once the sensor output (the duty cycle) has stabilised then the reading may go ahead, say for example 5 readings are taken and then the average calculated.

The sensor output may also be passed through a low pass filter: then we just have to read an analog value.
 

Offline 84750ErikTopic starter

  • Contributor
  • Posts: 41
  • Country: be
    • My Safety
Re: Duty Cycle detection
« Reply #24 on: October 14, 2017, 04:42:09 am »
However measurements take place once an hour only, during a time adjustable between say 5 seconds and 30 seconds.
This is confusing, measurement of what is once per hour? How is that timed/triggered/decided? A small microcontroller can stay in a low power mode and wake up as often as needed, then this is a simple design:

Start a timer and set an interrupt to occur on the edges of the signal being measured.
In the interrupt store the timer value and the polarity of the signal (add debouncing here if needed to clean up the edges).
Once you have 3 edges then you can calculate the duty cycle, make a decision, turn everything to low power and go back to sleep (repeat and filter if you want to reduce noise or cover missing pulses).

Some controllers will even have timer capture hardware that can do this with more determinism than a simple interrupt, but thats more accuracy than you've suggested you need. A timer at only 1MHz has 0.2% resolution for the duty cycle of a 2kHz signal. By measuring the duty cycle and the period you are now only concerned with the short term stability of the clock source and not its accuracy so the onboard low power oscillator will likely be sufficient. Even the larger Atmel parts you are already familiar with will wait in low power modes of a few uA, so lower power consumption is going to be hard to achieve with a comparator, reference, and biasing.
I am not familiar yet with interrupts. But there would be a DS3231 RTC module present.
The whole module consists of 1. the sensor module with duty cycle output 2. hard- or software to convert this duty cycle value to an analog value (or convert straight using a microcontroller) 3. a microcontroller to process this value for transmission 4. DS3231 RTC module to control the wake-up timings of the microcontroller for transmissions 5. a 464MHz HC12 transmission module 6. 6V battery, LDO voltage regulator and solar panel.

So if the duty cycle measurement can be done by this same microcontroller I am open for suggestions as you did, but please maybe a little more detailed because my programming knowledge is still lacking a lot?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf