LM317 and PWM – Another Quick Look

With supply chains breaking due to the pandemic, some resources are becoming hard to procure. There are cases when someone’s profession or life, depends on these resources. Being a technical author and circuit designer, I realise that my junk box is helpful for making things by supplying discrete components that are otherwise hard to get currently. While looking through my junk box, I came across a set of LM317 voltage regulator modules. I think I bought them just before Flipkart acquired eBay’s India operations.

On quick inspection I found that all the modules are working fine, but some may need minor repairs due to age.

I drew this picture of the schematic of the LM317 voltage regulator module. These modules are from NSK electronics (https://www.nskelectronics.com/home.html).

W1o silicon bridge rectifier datasheet https://datasheetspdf.com/pdf-file/1216815/Multicomp/W10/1

Since this module follows the typical application circuit of LM317 voltage regulator, it is ideal for driving little lab projects or any other circuit requiring a constant voltage supply. According to datasheets, the LM317 device is an adjustable three-terminal positive-voltage regulator capable of supplying more than 1.5 A over an output voltage range of 1.25 V to 37 V. It requires only two external resistors to set the output voltage. The LM317 features a typical line regulation of 0.01% and a typical load regulation of 0.1%. It also includes current limiting, thermal overload protection, and safe operating area protection. The overload protection remains functional even if the ADJ terminal is disconnected.

Below is the functional block diagram of LM317. The op-amp with 1.25 V offset input at the ADJ terminal provides easy output voltage or current (not both at a time) programming. For voltage regulation applications, two resistors simply set the output voltage.

Because the value of VREF is constant, the value of R1 determines the amount of current that flows through R1 and R2. The value of R2 determines the IR drop from ADJ terminal to GND – higher values ​​of R2 translate to higher VOUT.

However, note that since LM317 passes its bias current to the OUT pin, the load or feedback must consume this minimum current for regulation or the output may be too high. See the Electrical Characteristics table in TI’s LM317 datasheet (REV-APRIL 2020) for the minimum load current needed to maintain regulation (https://www.ti.com/lit/ds/symlink/lm317.pdf).

This is a small addition to the reason (on paper) behind using a 240Ω resistor for the upper resistor R1. The R1 at 240Ω is a basic requirement of the LM317 when used as a voltage regulator as it requires that the internal 1.25V reference has a 100uA lighting current. The specification for minimum load current is given as 3.5 mA typical, 10 mA maximum. Note that with the 240Ω resistor as R1, you will get a current of about 5 mA flowing through the bottom resistor R2.

If you get confused by these numbers, do not panic. This is a good online LM317 voltage calculator. It is helpful while doing similar experiments http://www.reuk.co.uk/wordpress/electric-circuit/lm317-voltage-calculator/

LM317 & PWM Control

As it turns out, if the upper resistor R1 is left in its place and lower resistor R2 is replaced with a voltage source, the output voltage of the LM317 is approximately 1.25V higher than the input voltage. Therefore, if we can feed a variable voltage in from an external source, for example from a microcontroller, we should be able to control the LM317 output instead of using the traditional trimpot or potentiometer. In this session, we will combine the basic LM317 voltage regulator circuitry with a microcontroller to create a crude remote-controlled regulated dc power supply.

So now that we have chosen our voltage regulator it’s time to build the rest of the circuit around it. Adjusting the voltage regulator by an external voltage source is nice but how do we provide a variable voltage into the ADJ pin?

The easiest method is to try Arduino’s pulse width modulation (PWM) with an op-amp. Let’s build that. The figure below shows a typical setup.

You are creating an analog voltage using LM358 op-amp (IC2A) along with a resistor (R3) and a capacitor (C4) that forms an RC low pass filter (LPF). The LPF converts the PWM voltage to a constant signal. Increasing the PWM frequency should reduce the output ripple of the network. Likewise, increasing the resistor value achieves a similar outcome but increases the risetime of the RC series circuit. You could omit the op-amp, but it has some advantages. First, it lets you enhance the basic concept to some extents. Second, it offers a degree of protection for your Arduino.

This is the link of a closely related project published earlier https://www.codrey.com/electronic-circuits/pwm-to-voltage-module-v1

Not to mention, a 5V PWM signal is applied to the input of the above circuit from an Arduino Uno. There’re two default frequencies in the Arduino Uno PWM – 490 Hz and 980 Hz. I’m using the digital pin D3 with 490 Hz PWM output.

Now upload the basic PWM sketch to your Arduino Uno. And see what is going on!


int pulseOut = 3; // D3

void setup()


pinMode(pulseOut, OUTPUT);


void loop()


analogWrite(pulseOut, 0); // Minimum


analogWrite(pulseOut, 128); // Middle


analogWrite(pulseOut, 255); // Maximum




During testing I used a common 9V/1A dc adapter to power up both my Arduino & LM358 circuit while the LM317 module is powered from an ac 12V power supply. The 9V supply would work for the LM358 part but the maximum output from it will be close to 5V only. This results in a maximum output 0f 6.2V from the LM317 module (2.2V is the minimum output voltage). You can certainly change the op-amp’s power supply voltage, after configuring the op-amp to multiply the 0-5V PWM input by 10 (or so) to get higher output voltages from the LM317 module.

I used loosely picked components in my test setup because it will work and frankly it is what I had around. I will show you a refinement of this set up in another post.

As I mentioned before, the higher the frequency on your PWM signal, the lower the voltage ripple at the output of the LPF circuit. If you use the default frequency of the D3 digital PWM pin (~490Hz), it is too low for a decent setup. You need to increase this PWM frequency to kHz level to achieve a more consistent output voltage. You can do this by changing the timer register of Arduino. Although I am not engaging in those tactics right now, you may find related do it yourself projects published elsewhere in this website.

You can use this great online RC low-pass filter design tool (http://sim.okawa-denshi.jp/en/PWMtool.php) to calculate the peak-to-peak ripple voltage and settling time at a given PWM frequency and cut-off frequency or values ​​of R and C.

The story is so far

So, looking in my junk box, I found some cheap LM317 voltage regulator modules and started thinking about reusing them in another way. First, I did some crude pulse width modulation experiments and succeeded as you can see here. Hope this gives you some design sparks to play with the old elements around your workbench. It’s worth noting that the Chinese LM317 modules are still available at low prices.

The next in line is an upgrade using a dedicated digital-to-analog converter (DAC) circuit, and perhaps another voltage regulator chip instead of the LM317. Stay tuned for more!

Leave a Comment