blog

Introduction to the XY-PWM Module

XY KPWM 11

What is PWM?

PWM (Pulse Width Modulation) is a common technology mainly used to control the amplitude or power output of signals. It adjusts voltage by changing the width of generated pulses—for example, increasing the duration of high-level pulses to raise the overall voltage, thereby achieving precise control of components. PWM is often used to control adjustable loads such as fans and light bulbs.

How Does PWM Work?

A PWM signal consists of periodically changing waveforms, usually including high-level and low-level parts, forming a rectangular shape. The PWM waveform remains nearly consistent across different cycles. PWM adjustment involves three key aspects:

1.Frequency: The number of cycles of a PWM signal per second, measured in Hz. For example, 500Hz means 500 cycles per second. Different electrical devices require matching frequencies to work properly.

2.Duty Cycle: The proportion of time the signal stays at high level within one full cycle. For example, a 60% duty cycle means the high level accounts for 60% of the cycle, and the low level accounts for 40%. A higher duty cycle makes the PWM voltage closer to the supply voltage. Generally, the duty cycle ratio equals the analog voltage ratio—with a 5V supply, a 60% duty cycle means the PWM simulates a 3V voltage.

3.Amplitude: The voltage range of the PWM signal, determined by the supply voltage.

07ef1294b747be0e886b0927995cf37f

How to Apply PWM?

Since PWM simulates different voltage signals, it can be used to adjust motor speed and light brightness. For example, connecting a light bulb to a PWM signal allows dimming and brightness level adjustment.

Detailed PWM Demo

This demo uses the XY-PWM module to adjust PWM signal generation for driving a fan and regulating bulb brightness. The specific effects are as follows:

XY KPWM 12

PWM in Daily Life

PWM signals are closely related to our daily lives. For example, the popular handheld small fans rarely have large gear buttons and make little noise when switching speeds—this is achieved by generating PWM signals to adjust the fan motor speed. Another example is the common dimmable lights today: most use PWM signals instead of directly changing voltage to avoid energy waste. Transformers cause heat loss, while PWM does not; additionally, PWM offers higher adjustment precision.

41fb09916e37afa724c4e7ec4f2caab4

The microcontroller generates PWM.

A microcontroller can also generate PWM signals, and it has more serial ports for greater convenience. Note that it cannot be used directly as a power supply.

This demo uses the Arduino UNO R3 as an example. Below is the detailed code for generating PWM signals. Pin 9 is used in this demo; in practical applications, you can adjust it to the required serial port pin number.

				
					const int pwmPin = 9;  // PWM output pin

int dutyCycle = 128;  // Duty cycle (0-255), 50% is 128
int frequency = 1000;  // Frequency (Hz)

void setup() {
  pinMode(pwmPin, OUTPUT);  // Set PWM pin as output
}

void loop() {
  // Set the PWM duty cycle
  analogWrite(pwmPin, dutyCycle);

  // Adjust the PWM frequency (using a delay to simulate frequency control)
  delay(1000 / frequency);  // Adjust delay according to the frequency
}
				
			

You can modify the duty cycle and frequency by following the code comments to adjust the PWM wave. 

However, if it is only used to generate PWM signals, the PWM module can be used, and the effect is the same.

FAQ

How to give a PwM signal?

PWM signals can be generated by a PWM module or microcontroller, then connected to the corresponding signal interface. They can also be connected to the driver stage of a MOSFET to simulate voltage adjustment.

What are PWM pins for?

Generally, loads that support PWM control are labeled accordingly. For example, a PWM cooling fan for computer cooling usually has four wires: VCC, GND, PWM, and SIGN. SIGN is used to send the PWM value back to the host, while the PWM pin is connected to a PWM signal wire to adjust the fan speed.

Is PWM dimming good for eyes?

When PWM is used to dim lights, it offers high precision and smooth adjustment—brightness can be adjusted gradually to avoid sudden sharp changes. Therefore, compared with traditional gear adjustment, PWM dimming is more eye-friendly.

Leave a Reply

Your email address will not be published. Required fields are marked *