Convert 15hz pwm signal to 50hz pwm signal, with analog circuit - Page 1
Forum section: electronics / beginners

author: olt96
author_rank: Newbie
timestamp: November 17, 2022, 03:55:57 pm
content: Hey, so I have a signal coming from a fan controller, which has a carrier frequency of 15hz.I would like to convert this to 50hz ( in order to drive a servo ). using some electrical circuit, and not a microcontroller.I thought about adding an RC filter to the PWM output, and putting that signal into an opamp acting as a comparator, set near the maximum voltage of the PWM signal. Thinking this would get me close to atleast the needed pulse width for driving servos ( 1-2 ms)It kind of works? But it doesn't really work reliably in a simulator even.another thing i tried is converting the pwm to an analog voltage, and then using a 555 timer circuit to generate a new signal based on this voltage.However this isn't reliable either.Is what I'm asking possible/ smart. I'm having half a mind to just throw a micro at it.

author: mikerj
author_rank: Super Contributor
timestamp: November 17, 2022, 04:26:48 pm
content: A small microcontroller is by far the easiest and lowest parts count solution for something like this. You could do it in pure analog or discrete digital if you want the learning exercise, but it won't be a particularly small circuit.

author: olt96
author_rank: Newbie
timestamp: November 17, 2022, 05:32:04 pm
content: Huh, I thought throwing a micro at this would be overkill, but it seems this problem isn't as simple as I thought

author: langwadt
author_rank: Super Contributor
timestamp: November 17, 2022, 05:37:46 pm
content: sure the servo won't work just fine with 15Hz ?

author: olt96
author_rank: Newbie
timestamp: November 17, 2022, 05:47:58 pm
content: yes, tested that already. As far as i know most servos need 50hz frequency, with some give ofcourse. But 15 is just too low it seems.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 17, 2022, 06:31:21 pm
content: You'll need several parts, spend some time designing it, and you won't save anything at the end, while a supercheap mcu will do this in minutes.

author: MrAl
author_rank: Super Contributor
timestamp: November 17, 2022, 06:32:33 pm
content: Quote from: olt96 on November 17, 2022, 03:55:57 pmDo you mean you need a constant 50Hz with a variable PWM duty cycle?Your idea with the 555 may not be too bad, but you probably cant use a 555 more a LM339. The 15Hz signal PWM generates a voltage, the voltage changes the PWM duty cycle of a 50Hz oscillator made with a section of the LM339.It's not too hard to generate a voltage from a PWM signal, so all you have to is design a variable duty cycle oscillator. This is done by generating a ramp, then use the ramp as one input to a comparator and the other input is the PWM converted into a voltage level. When the voltage exceeds the ramp voltage, the output of the comparator goes high.The ramp itself is generated at 50Hz with very narrow dead time.A variation on this is when the voltage goes below the ramp voltage the comparator output goes high (or low if that is needed instead).So you create two things:1. A PWM to voltage filter to convert the original PWM to a variable voltage level. Sometimes just an RC filter works.2. A ramp generator at constant frequency 50Hz with little dead time.3. A comparator to compare the new PWM voltage to the ramp voltage.As the PWM voltage varies the output pulse of the comparator varies in duty cycle.To create a ramp generator create an oscillator first and then use that to generate the ramp. You can get a pseudo ramp by using a resistor and capacitor and take the output from the capacitor. The resistor is fed by the oscillator. The oscillator has to have a very wide PWM duty cycle itself so you get a ramp that ramps up then resets quickly.The RC time constant should be relatively large so that the ramp looks somewhat straight. The voltage range will be lower but you can always adjust the input signal from the voltage converted from the original PWM signal. If you want better than that you can use a constant current generator to feed the capacitor. You probably dont need that though unless you need some super accurate PWM to PWM conversion. If you do in fact need super accurate PWM to PWM conversion, then probably better to introduce some feedback with a measurement of the output PWM in order to have the circuit compensate automatically for any error in the conversion.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 17, 2022, 06:51:12 pm
content: Try making a linear voltage-to-pwm curve with the 555...

author: MrAl
author_rank: Super Contributor
timestamp: November 17, 2022, 06:53:24 pm
content: Quote from: DavidAlfa on November 17, 2022, 06:51:12 pmThat may not be good enough. See reply #6.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 17, 2022, 07:00:48 pm
content: I know. I was being ironic.

author: Ian.M
author_rank: Super Contributor
timestamp: November 17, 2022, 07:30:50 pm
content: Quote from: mikerj on November 17, 2022, 04:26:48 pmOnly those poor souls with a strong negative aptitude for embedded programming, and no friends they can bribe with beer or cookies etc. to code it for them, should consider an analog or discrete digital domain solution. For the rest of us, yes, its a slightly interesting circuit challenge, but building it for real without a MCU is uneconomic.Quote from: MrAl on November 17, 2022, 06:32:33 pmGreat idea, except a 'Futaba' RC servo control signal is *NOT* a 50Hz 0% to 100% duty cycle PWM. Its a repeating 1ms - 2ms high-going pulse, at a nominal 20ms (50Hz) repetition rate. A 1520us pulse will center Futaba analog servos and a 1500ms pulse will center JRC ones + the mechanical limits are very unlikely to be at exactly 1ms and 2ms, with considerable variation between brands.https://www.servocity.com/servo-faqs/#how-do-i-control-a-servohas a good explanation of the signalling.Therefore the above needs modifying. (1) there needs to be some means of adjusting the offset and gain of the PWM-derived control voltage so its range can be mapped onto the specific servo's usable pulse width range, without driving it hard into its mechanical limits, and (2) the ramp generator needs a *LOT* of dead time, approx. 18ms of it to form most of the gap between RC servo pulses.As Mike has already noted, the *EASY* way to do this is to use whatever sub-1$ low pin count 8 bit MCU you are already familiar with, and have the hardware and software development toolchain for, preferably with at least one and ideally both hardware input capture and output compare modules, to offload measuring the input PWM pulsewidth and timing the output servo pulse, so your main loop only has to manage updating one from the other with the desired mapping, but its not excessively difficult to bit-bang either the pulse width measurement or the output pulse generation or even both if you are a glutton for punishment.If you don't have the experience and toolchain, but can code, throw an Arduino Nano at the problem, and we'll help you 'make it stick'!

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 17, 2022, 07:40:35 pm
content: Be brave and do it in TTL/CMOS: Will only take few Time bases, Counters, comparators and latches

author: olt96
author_rank: Newbie
timestamp: November 17, 2022, 07:48:33 pm
content: Thanks for all the advice gents. I don't really have any small micros lying around, so i'll just slap an old arduino micro i have and call it a day. I'm a programmer by trade so it shouldn't be too difficult.

author: MrAl
author_rank: Super Contributor
timestamp: November 18, 2022, 11:50:01 am
content: Quote from: Ian.M on November 17, 2022, 07:30:50 pmOk great, but if someone tells me their device works at 50Hz i take it that their device works at 50Hz, so good you noticed the problem.I agreed long ago that a small uC chip is the best route for this. I did it with a tiny 8 pin Microchip uC several years ago. Dont remember what protocol that one used now though it was at least 6 years ago probably more like 10.

author: MrAl
author_rank: Super Contributor
timestamp: November 18, 2022, 11:50:51 am
content: Quote from: olt96 on November 17, 2022, 07:48:33 pmThat's much better and Arduinos are easy to program.Good luck with it.

author: David Hess
author_rank: Super Contributor
timestamp: November 18, 2022, 12:16:09 pm
content: 1. Convert the incoming 15 Hz PWM to a voltage with averaging, RC filter.2. Apply voltage to integrating error amplifier, one operational amplifier.3. Apply output of error amplifier to 50 Hz PWM generator, conceivably one operational amplifier, but more likely two.4. Convert the outgoing 50 Hz PWM to a voltage with averaging, RC filter.5. Apply the voltage to the error amplifier.Now the error amplifier controls the output such that the output duty cycle matches the input duty cycle despite variation in frequency. Further, the PWM generator can be crude because feedback controls the duty cycle.

author: Ian.M
author_rank: Super Contributor
timestamp: November 18, 2022, 12:50:14 pm
content: Quote from: MrAl on November 18, 2022, 11:50:01 amI only noticed the potential problem because I also was wrangling RC servo signals with 8 bit PICs a decade ago and still remember the pain.If you were active on the Microchip forums back then we probably participated in some of the same threads on the subject.

author: MrAl
author_rank: Super Contributor
timestamp: November 19, 2022, 03:46:29 pm
content: Quote from: Ian.M on November 18, 2022, 12:50:14 pmOh yes maybe, i did visit that forum quite often back then.I cant remember exactly what i did now when i did my own servo controller. It was so long ago now.