change pulse width of a signal - Page 1
Forum section: electronics / projects

author: Etesla
author_rank: Regular Contributor
timestamp: February 04, 2017, 10:57:55 pm
content: I was wondering if anyone knew of a way to take a square wave of 'any' frequency (200 - 20000 hz range) with a 50% duty cycle and change the duty cycle to something like 2 -7%. This lower duty cycle should hold for any of the frequency's within the range, and the input frequency would be variable within the range (its an audio signal).My first thoughts were to feed the audio signal which should have a maximum magnitude of about 7V peak to peak into something like a ucc37322 to get a square wave of consistent magnitude out at the same frequency with a 50% duty cycle I think. Then I thought I should run that through an op amp configured as an integrator to get a triangle wave of the same frequency out. Then run the triangle wave through a schmitt trigger with pots where the resistors would be so I could have a variable cutoff values to cut the triangle wave off at different voltages resulting in a square wave output of the same frequency as the sin wave audio input at a variable duty cycle.Some things to note:I am relatively new to electronics and am not sure on all of my logic and terminology.The audio input to the circuit would be from a guitar fed through an op amp (lm386 probably), so the audio I am trying to represent is "simple". Not voices or a whole band or anything like that.Thanks!

author: Marco
author_rank: Super Contributor
timestamp: February 04, 2017, 11:17:04 pm
content: Would be easiest to just do it with a micro :pThe triangle wave would have variable amplitude based on frequency, so you wouldn't get a consistent duty cycle. You could have a peak detector to detect the amplitude of the triangle wave and then divide that with a pot to set the trigger level for the triangle wave. Although the frequency range and thus the amplitude range and noise/offset errors might become a limitation.

author: timb
author_rank: Super Contributor
timestamp: February 04, 2017, 11:25:54 pm
content: You could convert the square wave to a triangle wave, then run it into the inverting input of an op-amp or comparator. Let's say your square (now triangle) wave is 0-5V; if you apply 2.5VDC to the non-inverting input of the comparator it will output a 50% duty cycle square wave at whatever frequency the input triangle wave is. Now if you raise the voltage on the inverting input the duty cycle will increase (up to 100% at 5V); or it go down (0% at 0V) if the voltage is lowered.That's how I'd do it, anyway.

author: danadak
author_rank: Super Contributor
timestamp: February 04, 2017, 11:29:04 pm
content: First link both a generator and a scope.Here is a sound card oscilloscope, freebee. You need to protectsound card inputs, so google "sound card input protection", a numberof hits. Its is also a function generator, you might need to use OpAmpscaling on sound card output so you can offset it for use in digitalcircuit work.https://www.zeitnitz.eu/scope_enhttp://www.zelscope.com/Regards, Dana.

author: StillTrying
author_rank: Super Contributor
timestamp: February 04, 2017, 11:38:36 pm
content: I was trying to do similar some time ago, a 556 looked OK, I was getting up to 2Mhz out of it and pulse widths down to 350ns at the higher frequencies, 20Khz should be no problem. The values of R3 and the MS pot are the values for the CMOS versions with 100k x3 inside them.

author: Etesla
author_rank: Regular Contributor
timestamp: February 05, 2017, 12:18:23 am
content: WOW! I had no idea I would get responses so quickly! Thank you all!Marco, I thought about trying to use a micro controller, but my experience with micro's is pretty limited. Just some arduino stuff here and there. I have tried making a frequency counter with arduino before, but to no avail as my code only seemed to work at very low frequency's.... Thanks for the warning about the amplitude being dependent of frequency. That would have been a nasty surprise when the time came to breadboard this.StillTrying, I really like the idea of trying to do this with two 555's since I have like a million of them lying around. I will definitely try out the circuit you posted. It looks easy enough to test out.Timb, I think I understand you method but am unsure if what Macro was saying about the square wave having a variable amplitude with frequency will make it unusable....Thanks again!

author: tautech
author_rank: Super Contributor
timestamp: February 05, 2017, 12:28:27 am
content: Seems like nobody remembers how to use a 4047 monostable.

author: eblc1388
author_rank: Frequent Contributor
timestamp: February 05, 2017, 12:59:59 am
content: Quote from: tautech on February 05, 2017, 12:28:27 amWoh, I never know a monostable can produce constant duty cycle output with varying output frequencies.Care to show us how it can be done?

author: Paul Moir
author_rank: Frequent Contributor
timestamp: February 05, 2017, 01:06:41 am
content: If the input range were not so great, say 10:1 or less then a PLL (phase locked loop) frequency multiplier could work. Digitally divide your input signal by 2 to get a true 50% input duty cycle to the PLL, then multiply it by 20. Take the 20x oscillator output from the PLL and generate one pulse in twenty with say a pair of 4017. I think that should give you a fixed 5% duty cycle?PLLs are kind of neat but they take some time to lock which might be a problem for you, and would really only work in the 200Hz to 2KHz range. That said, you suggested that the input signal might be a guitar? If so why would it need to go over 2KHz? In fact, you'll likely need do do some pretty heavy filtering on it to get the "note" you're looking for. The output of an electric guitar has a lot of harmonics; check youtube for "guitar oscilloscope" to see what I mean. Otherwise it would sound like a tuning fork.A micro is probably easier. I can't help but think compensating your triangle wave generator would be easier too.(tautech - I think he's looking for something that will put out a fixed duty cycle but variable frequency with the input dependant on frequency)

author: tautech
author_rank: Super Contributor
timestamp: February 05, 2017, 01:12:20 am
content: Quote from: eblc1388 on February 05, 2017, 12:59:59 amhttp://www.ti.com/lit/ds/symlink/cd4047b.pdfTable P2.

author: tautech
author_rank: Super Contributor
timestamp: February 05, 2017, 01:18:25 am
content: Quote from: Paul Moir on February 05, 2017, 01:06:41 amMaybe then a 4046 would be better.

author: Etesla
author_rank: Regular Contributor
timestamp: February 05, 2017, 01:24:48 am
content: Tautech, I think you nailed it. The 4047 in monostable mode with my input square wave does look extremely promising as limiting the on time of each pulse is really what I'm aiming for (I just thought adjusting the duty cycle would be an easier approximate way to do this). If I understand correctly from the data sheet, connecting a cap and resistor of correct values to pins 1,2,&3 and putting my square wave to pin 8 with pin 9 pulled low and 4 pulled high will result in output pulses of my on time determined by the cap and resistor at the frequency of my input square wave? Sounds exactly like what I need. Does anyone have any actual experience with this chip in monostable mode?Paul Moir, You are completely right about not needing to go over say 2 khz. Im relatively new to audio and my scope of frequency is not as attuned as yours perhaps isI just took some scope shots of my guitars output and the harmonics didn't appear visually to be that large a part of the waveform, but I'm sure your right and I will hear the difference.

author: Paul Moir
author_rank: Frequent Contributor
timestamp: February 05, 2017, 01:33:18 am
content: Quote from: tautech on February 05, 2017, 01:18:25 amThen again, maybe not! Looks like you've got superior situational awareness.

author: Etesla
author_rank: Regular Contributor
timestamp: February 05, 2017, 01:44:09 am
content: LOL I didn't see that comment until paul pointed it out. Very impressive.

author: StillTrying
author_rank: Super Contributor
timestamp: February 05, 2017, 01:49:40 am
content: Quote from: Etesla on February 05, 2017, 12:18:23 amWell I know it worked in practice almost exactly as in the simulation because I did it! - I'll find a pic in a minute.If you're wanting to get the whole 200:20khz, 100:1 on the one pot range I think you'd need a reverse log pot to get a smooth increase in freq with clockwise rotation.If you're using bipolar 555s with internal 5ks you'll need to lower R3 to about 2k and the M/S pot to about 1k.Ed: Even at the curved flattening top of the charge curve I could still set quite a large MS ratio, until about 2Mhz.

author: Etesla
author_rank: Regular Contributor
timestamp: February 05, 2017, 01:55:06 am
content: Still trying, I think I may have misunderstood your original post... What I was aiming for was to be able to change the duty cycle / on time of a square wave input while maintaining the frequency, not creating a square wave of a specific frequency with a variable duty cycle, although this sort of diy function generator was a thing of interest to me just a few weeks ago before I bought one. Still gonna build it out though!

author: StillTrying
author_rank: Super Contributor
timestamp: February 05, 2017, 02:12:17 am
content: Quote from: Etesla on February 05, 2017, 01:55:06 amI've had the HC4046's data sheet open for 2 days, and currently going through thisCMOS Phase-Locked-Loop Applications (Rev. B) - Texas Instrumentswww.ti.com/lit/an/scha003b/scha003b.pdfBut I still don't think it's going to be easy if,youdon't have control of the frequency of the incoming signal.

author: Brumby
author_rank: Unknown
timestamp: February 05, 2017, 02:12:57 am
content: I am truly impressed with the variety of approaches offered here.MCUs... comparators... PLLs... Lots of effort when the hard work has already been done. We have the operational frequency reference with a choice of some nice positive or negative going edges for triggering. Just create a new pulse of whatever width you want from the trigger. Simple.4047 in monostable mode could not have been better designed for this application; the 555/556 solution is a classic - and you could probably put together a 2 transistor monostable flip flop to do the job.

author: eblc1388
author_rank: Frequent Contributor
timestamp: February 05, 2017, 02:37:53 am
content: I wonder why some people have trouble understand the difference between constant pulse width and constant duty cycle of a varying frequency signal?The suggestion of converting the square wave into a triangular wave would work if there are active AGC control about the amplitute of the triangular wave, like in the following circuit. However, it would take quite many cycles for the AGC to work its magic which might be too long for the original poster.An some comments about the PLL approach. I like the idea but one does not need to obtain a 50/50 duty cycle wave in order to feed into the PLL. The multiplication ratio needed is x40 as a binary division is done first. By the way, one can only get divide-by-seventeen using two 4017s, but the resultant 5.9% duty cycle fits the OP requirement.

author: Paul Moir
author_rank: Frequent Contributor
timestamp: February 05, 2017, 02:43:22 am
content: Because Post #11 sentence 2 redefines the acceptable solution to include a fixed pulse width.

author: eblc1388
author_rank: Frequent Contributor
timestamp: February 05, 2017, 03:06:14 am
content: Quote from: Paul Moir on February 05, 2017, 02:43:22 amTotally missed that vital point. My apology to the forum.

author: tautech
author_rank: Super Contributor
timestamp: February 05, 2017, 03:11:48 am
content: The VCO portion or a 4046 is a neat bit of kit too when needed.I did think a 4013 as a resetting oneshot might work too for the OP but sometimes you need to gang a few of these various logic IC's together to get the result you seek.Plain good old Glue Logic.Old logic IC's these may be, but sometimes the simplest and easiest for someone that can't program yet like me.Stock upon them before they're no longer available.

author: tautech
author_rank: Super Contributor
timestamp: February 05, 2017, 03:18:27 am
content: Quote from: Etesla on February 05, 2017, 01:24:48 amGot a breadboard, a frequency source and a scope ?This site can be handy for checking the functionality of many logic blocks but maybe not this time for the OP.https://tams.informatik.uni-hamburg.de/applets/hades/webdemos/index.html

author: David Hess
author_rank: Super Contributor
timestamp: February 05, 2017, 04:26:17 am
content: Start from the output and work back. If the output precision duty cycle square wave has a constant peak-to-peak amplitude, then its average is proportional to its duty cycle. So integrate the output to provide a feedback signal to control the slope of a ramp generator which is triggered and reset by the source frequency. A fixed comparator provides the precision duty cycle output. Easy peasy.Triggered Ramp Generator to (current source driven ramp generator with reset)Fixed Level Comparator to (comparator)Precision Output Generator to (analog switch or CMOS gate)Integrator back to (operational integrator)Triggered Ramp GeneratorIf the frequency operates over a limited range, then just convert the input to a triangle wave and have the feedback go to the comparator instead. In this case the wide frequency range will cause problems because at the high end, the triangle amplitude would be small increasing noise.

author: Marco
author_rank: Super Contributor
timestamp: February 05, 2017, 08:22:35 am
content: How about charging a capacitor with current x while the input is high and then discharging it with a variably current y>x when the input is low. Output is high while discharging, goes low when it meets a threshold and the discharging is stopped. Circuit shouldn't be too hard.

author: Etesla
author_rank: Regular Contributor
timestamp: February 05, 2017, 03:01:33 pm
content: David Hess, I like your idea. I am completely new to ramp generators, but it looks like I can make on from a 555 that would work. Im not sure why you still need to integrate the signal for feedback, and I'm not sure how that feedback would "control the slope"... Im assuming this is to eliminate the problem of high frequencies potentially having either a very very small on-time or no on time at all (because the capacitor will not have charged to the comparators "trigger" voltage.), and or the low frequencies completely charging the capacitor giving a larger than desired duty cycle...Overall I just ordered a few 4047's as they seemed to be built for my task in monostable mode. I will experiment with most of your methods until those chips get here, and will post on this topic with my results if I find anything interesting.Thank you all for your help!

author: David Hess
author_rank: Super Contributor
timestamp: February 05, 2017, 03:51:39 pm
content: Using feedback is just an easy way to maintain a precise duty cycle while the frequency changes. It is sometimes used to "true up" a source to have a 50% duty cycle without dividing by 2. There is a Linear Technology application note which uses it but I was not able to find it.