Capturing PWM signals (freq 1-160Khz, with varying duty cycle) and then generating the same PWM signals

Hi,

I want to caputre a PWM signals having varying duty cycle (0-50% & range from 1-160KHz) from function generator and then generate the same PWM signals into two (inverting and non inverting) with varying duty cycle . Also there must be a deadband & duty cycle configurable settings in the code while generating the signals so that i can read it again on the oscilloscope. Please suggest the code accordingly.

Except for whatever “deadband” means in this context, The problem sounds much like the button example:

https://docs.arduino.cc/built-in-examples/digital/Button/

It has sample code in your ide to do half your problem, and is easily extensible to do the other half.

1 Like

No, It's not like a Push-button. It's a PWM signals generated from function generator with a range from 0 - 160Khz.

Is it PWM or square?
Is the duty fixed at 50% ?

1 Like

PWM signals. Duty cycle with variable duty cycle. Duty cycle is not fixed

Supposing the signal was at 1Hz. In what way does it differ from an on-off signal that could be simulated by someone pushing a button?

Yes but here the freq which i will play coming from Function generator has a range upto160Khz.

A 10% duty at 160kHz is only 625ns, that's only 10 cycles for a 16MHz micro. Which Arduino were you planning on using?

1 Like

Would you like me to move your topic to a forum section where you can discuss payment for this service?

1 Like

DaveX's idea wasn't a bad one.
The output of the function generator is basically the same as the output from a push button that is operated rapidly.

I've tested 'Button' with a function generator, and it works quite well.

Here's an oscilloscope trace showing 'Button' working with a 20kHz input signal:

Unfortunately it won't work at 160kHz, but when DaveX made the suggestion you had not told us the frequency range.

You have edited your first post since DaveX's post to mention the frequency.

Good suggestion DaveX.

1 Like

Aurdino UNO evaluation board

Sorry about this not to inform fully about the specs. But now i guess i have mentioned everything here. If more information is required then i can explain it further. Please suggest accordingly

If you have any other suggestion instead of using Arduino Evaluation Board please let me know

If you have any other suggestion for 0 - 160Khz freq range please let me know. Thanks

For an Uno, there are some direct port reading and writing tricks that could increase the speed.

Why don't you try the button code to demonstrate the logic of the inverse and deadband behavior you want at lower speeds, and then we could see about optimizing speed.

I dropped the Button.ino code into a Wokwi simulator with a scope and a PWM generator and got to 33333Hz before running up against scope limitations.

Here's a hack:

What do you mean by this:

I imagine you want some break-before make logic between the inverted signals, and the constraints that would add, as well as the resolution of the duty cycles would help indicate if it is feasible on an Uno.

Button, modified to write to two pins, to use fastDigitalWrite, and ordering the writes to break before make, with a possible delay between the two seems like it would meet the specs as far as you have described.

A PWM signal is exactly like a push button. Digital, on or off, with variable on and off timings.

1 Like

I agree with you. Just to specify the clear application where i will use it as PWM signal. I elaborated more clearly as PWM signal usage

So, you need to measure the frequency of the input signal, and then generate another one with the same frequency but different duty cycle, right?

Start by creating a program that calculates the time between one rising edge and the next one, you should be able to find examples (button one is not far away). Then based on that period calculate the time needed for your falling edge.

Have you tried generating 160 kHz PWM with that board? If so, you will notice that due to hardware limitations, the PWM resolution is very poor at such high frequencies.

1 Like

Hi you were right about the poor resolution of the PWM signals at 160Khz. I would like to ask whether any other version of Arduino can provide the 160Khz good resolution of PWM signals. Please suggest accordingly.