Shift PWM constant frequency to another.

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
Hi!

I wanted to know if there are any options to shift the frequency of a PWM signal while retaining its duty cycle. I need to lower the base frequency from 4kHz to 1kHz for my signal to be usable by a very specific PWM controlled motor driver (I couldn´t find another driver which fits my needs so this has come to be the only viable option).

I don´t care about operation values as the voltage levels of the signal can be easily manipulated, only that it works for shifting the base frequency.

Thank you very much!
 

crutschow

Joined Mar 14, 2008
34,282
What is the source of the PWM signal?
That conversion is not trivial to do with discrete parts but could readily be donc with a single-chip microcontroller.
 

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
What is the source of the PWM signal?
That conversion is not trivial to do with discrete parts but could readily be donc with a single-chip microcontroller.
It's a 24V PWM output from a PLC module (which its fixed to 4kHz), and it's destination is a 5V input signal to the driver.
 

danadak

Joined Mar 10, 2018
4,057
Basically fairly simple. Measure period and high pulse time, and
use the DC calculated from that into another PWM that has been
setup for translated frequency.

Something like this, one chip solution, PSOC. Could also be done
with many other processors.

upload_2019-10-16_21-32-25.png

Maybe 15 lines of code need to be written.


Regards, Dana.
 

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
A frequency divider circuit won't preserve the PWM duty-cycle which the TS wants.
Hi crutschow, do you recommend a paper or a design with discrete parts? Or is it highly complex? I was relieved seeing be80be's response, but yeah, it doesn't seem to preserve the duty cycle. Thanks for the help tho, be80be!

Thanks Danna, I don't have at hand any way to program microcontrollers at this time. But most likely I will need to do something like that.

Or is there an IC family who can shift the PWM base frequency?
 

Alec_t

Joined Sep 17, 2013
14,280
it's destination is a 5V input signal to the driver.
Does the output PWM duty cycle have to be an exact match for the input PWM duty cycle, or would the output duty cycle be allowed to drift in the short term but have a longer term average value matching the input duty cycle? I ask because I've cobbled together a circuit design which averages the duty-cycle ok (albeit over a limited range of input duty cycle), although from cycle to cycle there is some variation as a result of pulse integration time constants.
 

danadak

Joined Mar 10, 2018
4,057
I assume you have to handle the source PWM freq as not exact, something
you cannot predict from one PLC to another ? Which implies you have to
measure its period and duty cycle ?

What is the accuracy and resolution you want for the tracking 1 Khz ?

I think the coding here is pretty basic, I can help with that. Have you
ever done any coding ?

I am not aware of any IC that does what you want off the shelf.


Regards, Dana.
 

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
Does the output PWM duty cycle have to be an exact match for the input PWM duty cycle, or would the output duty cycle be allowed to drift in the short term but have a longer term average value matching the input duty cycle? I ask because I've cobbled together a circuit design which averages the duty-cycle ok (albeit over a limited range of input duty cycle), although from cycle to cycle there is some variation as a result of pulse integration time constants.
If it drifts for a short time then I would give it a shot. But i'm using a closed loop driver for these motors, so if the duty cycle keeps considerably oscillating while operating (> +/-1%), I guess it would defeat the purpose of using a closed loop driver. Thanks for the reply Alec_t!
 

Alec_t

Joined Sep 17, 2013
14,280
if the duty cycle keeps considerably oscillating while operating (> +/-1%), I guess it would defeat the purpose of using a closed loop driver.
The variation is greater than 1%, so that would rule out using my circuit for your application. I think most analogue solutions would have the same problem, so a digital approach like Danadak's looks more promising.
 

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
I assume you have to handle the source PWM freq as not exact, something
you cannot predict from one PLC to another ? Which implies you have to
measure its period and duty cycle ?

What is the accuracy and resolution you want for the tracking 1 Khz ?

I think the coding here is pretty basic, I can help with that. Have you
ever done any coding ?

I am not aware of any IC that does what you want off the shelf.


Regards, Dana.
Thanks for the reply Danna, the problem is that the PLC program must not be touched and the replacement driver we could manage to find only accepts maximum 2kHz input frequency for the PWM signal to analyze and 1kHz is recommended, while the PLC generates this PWM signal with a fixed 4kHz counter module.

In the accuaracy a +/-1% is desired (but negotiable), but a 10bit resolution is preffered.

I've programmed in some high-level languages, however I don't have much microcontroller experience (C/Assembly) so any help would be greatly appreciated. Could you recommend a microcontroller that could achieve this?
 

Thread Starter

Tsuo97

Joined Oct 16, 2019
6
The variation is greater than 1%, so that would rule out using my circuit for your application. I think most analogue solutions would have the same problem, so a digital approach like Danadak's looks more promising.
Thanks, Alec_t. I'm gonna give a shot to the digital solution. I appreciate your contributions!
 

danadak

Joined Mar 10, 2018
4,057
The basic approach here can use pretty much any micro. I happen to
be partial to PSOC because it has a lot of analog capability in addition
to ARM core and all the programmable logic fabric it has.

Achieving << 1% should be easy as long as you use an xtal on processor
and I would say 16 bit PWM resolution. The prior project I posted already
would easily do the job with some additional coding. The board is < $ 15
for debug/development. If you have to make many of these there is a $4
bootloader board you can move the finished project into.

There is a latency to the solution, basically the gate time used for the fre-
quency/duty cycle measurement. If 100 mS is gate then that is ~ the delay
from a DC change to update in final 1 Khz PWM. That means freq accuracy
is 10 Hz resolution. You can trade gate time for res, a 10 mS gate time
would mean 100 Hz resolution.


Regards, Dana.
 
Last edited:

Alec_t

Joined Sep 17, 2013
14,280
Do you really need the gate time to be that long? I'm no programmer but I would have thought both duty cycle and period (if that's needed) could be measured in a single PWM cycle, using an interrupt handler. So the latency would be little more than 250uS. Or am I missing something?
 

KeithWalker

Joined Jul 10, 2017
3,063
This is a fairly simple problem to solve. See the diagram below. The PWM signal is integrated to give a DC level that is proportional to the duty cycle. This is used to select the intersection point of a 1 KHz sawtooth waveform in a comparator. The output is a 1 KHz PWM signal with the same duty cycle as the input.

PWMfreq.jpg
 

danadak

Joined Mar 10, 2018
4,057
Do you really need the gate time to be that long? I'm no programmer but I would have thought both duty cycle and period (if that's needed) could be measured in a single PWM cycle, using an interrupt handler. So the latency would be little more than 250uS. Or am I missing something?
You have to measure frequency and duty cycle first, so the gate (resolution of measurement)
controls the latency to update. In other words if the source changes its not until measurement
is finished that results can be reflected in destination PWM update.

Regards, Dana.
 
Top