Need to make custom PWM with display screen?

Thread Starter

electronice123

Joined Oct 10, 2008
346
Hi all,

I need a PWM with adjustable freq & duty displayed on a Nextion screen. I plan on mounting two of them in a custom made enclosure.
I tried the XY-PWM1 but resolution above 1kHz is poor, the display is terrible, and there is only 1 encoder for both freq and duty.

So what I need is a PWM with the following:
-Frequency: 1Hz-15kHz with 1Hz max resolution (adjusted by its own rotary encoder)
-Duty Cycle: 1-99% with 1% max resolution (adjusted by its own rotary encoder)
-Preferred operating voltage in/out from PWM: 14V
-Freq and Duty of each PWM displayed in real time on a Nextion or similar screen
-I also want it to have a memory so when powered off then back on the freq and duty remain at their last set position

I have been in electronics for years but mostly dealt with Logic IC’s and audio transformers.
I have never made anything that used a screen so that area is totally new to me.

What is the best route to take?
Should I just hire someone on FIVRR or is this project simple enough to do on my own?
Thanks in advance.
 

BobTPH

Joined Jun 5, 2013
9,130
This project screams for a microcontroller. Without it, it might take dozens of chips. Everything you have asked for can be done be a single chip microcontroller. So the hardware is basically trivial, everything is done on the firmware.

What is your experience with micros and programming?
 

Thread Starter

electronice123

Joined Oct 10, 2008
346
This project screams for a microcontroller. Without it, it might take dozens of chips. Everything you have asked for can be done be a single chip microcontroller. So the hardware is basically trivial, everything is done on the firmware.

What is your experience with micros and programming?
I've played around with Arduinos once or twice and I think I have a dev board but I'm definitely a noob.
 

k1ng 1337

Joined Sep 11, 2020
986
Use a microcontroller with an I2C LCD display to generate a PWM signal then pass through an opamp to scale to 14V. Here is some information about PWM which can be done with Arduino Uno:

On-Time − Duration of time signal is high.

Off-Time − Duration of time signal is low.

Period − It is represented as the sum of on-time and off-time of PWM signal.

Duty Cycle − It is represented as the percentage of time signal that remains on during the period of the PWM signal.

Period- As shown in the figure, Ton denotes the on-time and Toff denotes the off-time of signal. Period is the sum of both on and off times and is calculated as shown in the following equation −
$$T_{total} = T_{on}+T_{off}$$
Duty Cycle- Duty cycle is calculated as the on-time of the period of time. Using the period calculated above, duty cycle is calculated as −
$$D = \frac{T_{on}}{T_{on}+T_{off}} = \frac{T_{on}}{T_{total}}$$
The code to make this happen is easy to learn and modify. I can help design this project but I am not a professional engineer.
 

Thread Starter

electronice123

Joined Oct 10, 2008
346
Cool,

I was just looking through my stuff and I have an Arduino UNO and a 12C LCD screen.
The only thing I don't have is the rotary encoders, but I have a lot of tactile switches.
 

k1ng 1337

Joined Sep 11, 2020
986
Cool,

I was just looking through my stuff and I have an Arduino UNO and a 12C LCD screen.
The only thing I don't have is the rotary encoders, but I have a lot of tactile switches.
Arduino Uno (ATmega328 microcontroller) has an 8 bit ADC of 256 values so you'll get 0.4% resolution at each input with a pair of potentiometers as encoding is done by the ADC.

There are many guides about changing PWM duty cycle in software but changing frequency at the same time is tricky by extending those examples. If you get stuck on this part I have a method which keeps track of time.
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
986
Here is an analog version based on the 555 timer. Use opamp to scale to 14V. Duty cycle is stable 10-90%. Frequency stability is poor because it is RC based. Use Uno to display frequency and duty cycle by reading pin 3 as a alternative to generating the PWM signal in software.

pulse-generator (1).gif
 
Last edited:

MisterBill2

Joined Jan 23, 2018
18,951
Monitoring frequency (RPM) can be done with a single pulse per revolution scheme and either a counter with a timebase or an interval timer and more software. Unfortunately, the time interval method loses resolution as the speed increases.
This is an application that could use a processor, preferred one that uses the same words for things and functions as the rest of the world. (That IS a slam against one company)
 

Thread Starter

electronice123

Joined Oct 10, 2008
346
The only thing is I need this design to implement rotary encoders. The .4% resolution would be OK but will that allow me to change in 1Hz increments?

From the research I've done scouring the web the arduino can do pwm, freq change but doing both together seems to be a problem like k1ng 1337 said.

I think for now I'm going to look at hiring an engineer as I am looking for a solid design that can be mass manufactured without needing to program it which I see is way beyond my capacity at the moment.
 

k1ng 1337

Joined Sep 11, 2020
986
The only thing is I need this design to implement rotary encoders. The .4% resolution would be OK but will that allow me to change in 1Hz increments?

From the research I've done scouring the web the arduino can do pwm, freq change but doing both together seems to be a problem like k1ng 1337 said.

I think for now I'm going to look at hiring an engineer as I am looking for a solid design that can be mass manufactured without needing to program it which I see is way beyond my capacity at the moment.
You can set the increment to whatever you want because an 8 bit ADC converts a potentiometer set at 50% to a value of 128. It then simply a matter of telling the microcontroller to scale appropriately. A 1:1 ratio would be 0 at the pot = 0Hz and 256 at the pot = 256Hz.

To generate a PWM signal without using the PWM libraries, all you need to do is turn on a digital output for a time then turn it off for a time. The time between on and off is the duty cycle and the total time is the frequency. If your microcontroller isn't doing other work this actually pretty easy to code but it sounds like you are in production so an engineer would know best.
 
Top