Implementing a 0~10V Output Circuit with Microcontroller

  • Introduction

  • 1. MCU’s DAC

  • 2. PWM with Filtering Circuit

    • 2.1 PWM Output DAC

    • 2.2 Explanation of RC Value Selection for PWM Filter

    • 2.3 0~3.3V PWM Output to 0~10V

  • 3. Dedicated Conversion Chips

Introduction

It has been a long time since I attended a circuit class, and recently I encountered a project requirement, so I thought I would make a circuit record summary.

Of course, I haven’t used all of the circuits in this article before, but since I wrote it, I will definitely draw a practical board and test each one.

The main content of this circuit class is: How to achieve 0 ~ 10V signal output using a microcontroller.

1. MCU’s DAC

The first method is to use the built-in DAC module of the microcontroller. Many microcontrollers now come with DAC modules, and we can directly use the output of the DAC module.

For example, the most common power supply system for microcontrollers is: 0 ~ 3.3V. Therefore, we can amplify 0 ~ 3.3V by 3 times to achieve 0~10V output.

The amplification circuit is, of course, implemented using an operational amplifier, which I have summarized in another blog post:

Summary of Common Operational Amplifier Circuits

Here we are using a non-inverting amplifier circuit, as shown in the following diagram:

Implementing a 0~10V Output Circuit with Microcontroller

DAC1 is the DAC output of the microcontroller, 0 ~ 3.3V, amplified by 3 times.

R2 is selected as 3.3K also due to the symmetry of the operational amplifier, choosing a resistance value equal to that of the parallel resistors R4 and R3.

This article is a summary record of the circuit. As for the effectiveness of the circuit, I need to see if I need to supplement it later in the text, because besides dedicated chips, circuits built using general operational amplifiers powered by a single power supply may have some issues, the most typical one being whether it can output 0V.

Update on testing results: The first method using the DAC amplified by 3 times looks quite satisfactory; here’s the test image:

Implementing a 0~10V Output Circuit with Microcontroller

Above, I manually set the DAC values to show the different output states.

2. PWM with Filtering Circuit

The second method is to use PWM with a filtering circuit.

2.1 PWM Output DAC

To convert the PWM waveform into an analog output, we need to add a filtering circuit. Through a filtering circuit, PWM can be transformed into a DAC output. As shown in the figure below:

Implementing a 0~10V Output Circuit with Microcontroller

For a basic analysis of the filter, I will write a separate article to explain it. Here we just mention that using an RC filter can convert PWM output into an analog voltage.

The above diagram only uses a single RC filtering circuit, which is called a first-order filtering circuit.

To make the output smoother, we will use second-order or even higher-order filtering circuits.

To enhance the load capacity, we will use a voltage follower or other operational amplifier circuits afterwards.

2.2 Explanation of RC Value Selection for PWM Filter

Choosing the RC values for the RC filter is a point that beginners find difficult to understand, and it is one of the key points in filter design.

We all know the cutoff frequency of the RC low-pass filter:

fc=1/2πRC

This formula is very important and must be remembered when understanding the RC filter; it is the cutoff frequency formula.

The cutoff frequency is actually the frequency at which the input signal amplitude drops by 3dB. The cutoff frequency is also known as the -3dB frequency.

Here are some simple points to explain (of course, if you want a specific calculation analysis, you can search online; I haven’t written an article on RC filters yet = =!):

  • The smaller R is, the greater the output loss.
  • The larger R is, the greater the noise ripple.
  • The smaller C is (for example, reaching the pF level), the more easily it is affected by parasitic capacitance.
  • The larger C is (for example, at the uF level), because the larger the capacitor, under normal circumstances, it can only use electrolytic capacitors, but electrolytic capacitors have poor high-frequency characteristics, so avoid using electrolytic capacitors in RC filters.

In summary, isn’t this not allowed, that not allowed? = =! In fact, that’s how it is; there are no perfect solutions for these low-cost circuits. What we are doing is making a trade-off to design a circuit that meets the needs within the limits of cost constraints.

For our PWM, it is essentially a high-frequency pulse signal, where the high-frequency components will be filtered out by the low-pass filter, and only the low-frequency components can pass through the filter to form an analog signal output. We need to ensure that the PWM frequency is much greater than the cutoff frequency of the RC low-pass filter, at least 10 times or even several tens of times higher, because the higher the frequency, the better the filtering effect.

Unfortunately, when filtering the PWM signal, there isn’t a perfect fixed value range to tell everyone. Generally speaking, keep the resistance in the K range, from hundreds of ohms to K level, and then the capacitance in the nF range, from nF to 1uF. Of course, this is just the general case; specific situations should be analyzed specifically.

The details involved require a lot of analysis, but don’t worry, in general use, even if you don’t know how to choose, based on the “experience values” you can find online, you can still complete the circuit design.

The important thing is knowing how to troubleshoot and adjust parameters after you design the circuit according to the experience values; this is the key to hardware design.

2.3 0~3.3V PWM Output to 0~10V

Solution 1: RC Filter

As mentioned above, let’s summarize the circuit we tested this time:

Implementing a 0~10V Output Circuit with Microcontroller

The resistance and capacitance in the figure can be modified according to your needs.

Testing:

As mentioned above, we can calculate the cutoff frequency of the RC low-pass filter, and we need to ensure that the PWM frequency is much greater than the cutoff frequency of the RC low-pass filter.

If the PWM frequency is relatively low, what will happen? For example, if my PWM period is 1Hz and the duty cycle is set to 50%, I will directly show you a diagram:

Implementing a 0~10V Output Circuit with Microcontroller

Let’s modify the PWM frequency slightly; for my tests, it’s actually just the timer frequency, as follows:

Implementing a 0~10V Output Circuit with Microcontroller

According to the formula

Tout = ((arr+1)*(psc+1))/Tclk ; // 32MHz main frequency

The timer period is 1ms, which actually indicates a frequency of around 1KHz. To facilitate the representation of the duty cycle from 0 to 100, I changed the arr to 100, which is actually around 1KHz. Let’s take a look at the effect:

Implementing a 0~10V Output Circuit with Microcontroller

In fact, when I tested, I didn’t specifically adjust the resistance and capacitance values, and intuitively, the effect still looks acceptable (the spikes in the above image are mostly due to the oscilloscope’s GND clip being too far away).

Solution 2: Transistor

The transistor solution is based on the circuit from B station teacher Eric’s video. Due to certain reasons, I won’t post the link; you can search for it yourself. Here I also share it as a reference!

There is a problem; the bias voltage in the teacher’s diagram seems to be 11V, which is not easy to meet. I tested it using a 12V in series with a diode:

Implementing a 0~10V Output Circuit with Microcontroller

Because the above image is for reference only!

If you want to ensure that the output does not exceed 10V, it is best to choose a bias voltage of 10V and remove the D3 above, as this way the maximum output approaches 12V.

3. Dedicated Conversion Chips

The first two methods are relatively low cost, and like level conversion circuits, there are dedicated conversion chips for 0~10V output.

But in fact, I haven’t used them, but since we have to test it, we can’t leave it out. However, I don’t know which chip is good, so I can only search online (although in my understanding, the chips found through Baidu search can only be said to have good advertising, but that doesn’t necessarily mean they are good), but there’s no other way, so after a lot of searching, I found this chip: GP8101.

After looking at the introduction, this chip has a series that not only has PWM input but also I2C interface:

Implementing a 0~10V Output Circuit with Microcontroller

Here, I won’t paste too much explanation; you can search for it yourself. This article just treats it as a solution, and we can directly design the circuit diagram according to the recommended circuit:

Implementing a 0~10V Output Circuit with Microcontroller

The testing is actually the same as above; we set different duty cycles and observe the results on the oscilloscope, and the results are still very good.

Conclusion

This article lists different solutions for how to implement a 0~10V output circuit using a microcontroller.

To say which is the most stable and worry-free, it must be using dedicated chips. If you are indeed sensitive to costs, then you have to consider the actual needs. The several circuits listed in the article will also be updated as soon as new discoveries are made in actual testing.

Alright, that’s it for this article, thank you all!

Source: Jinchensuozhi

Friendly Reminder:

Due to recent changes in the WeChat public account push rules, many readers have reported not seeing updated articles in a timely manner. According to the latest rules, it is recommended to click on “Recommended Reading, Share, Collect” more often to become a frequent reader.

Recommended Reading:

  • Xiaomi Wuhan headquarters laid off 90% of employees over 35? The official response is here!

  • No more “brake failure”? Tesla recalls all vehicles sold in recent years!

  • Did the electronics giant just close its factory in China and withdraw from India? It was once attacked and looted!

  • Demanding a pay raise of at least 6%, semiconductor giants face employee protests!

  • Is Tianya Community not dead? The former editor-in-chief revealed that only the domain name and server were stopped… netizens: old memories return!

Please click 【Looking】 to give the editor a thumbs up

Implementing a 0~10V Output Circuit with Microcontroller

Leave a Comment