I am a student at school, and I am a bit new to STM32. If I want to learn another type of microcontroller, GD32 may be a good choice.
I wanted to make a power supply with as many functions as possible. I saw the IMAXB6 charger and found several shortcomings, so I modified it based on it.
As a CNC power supply, it must first be divided into four major modules: power, digital-to-analog, analog-to-digital, and human-computer interaction .
It is better to teach a man to fish than to teach him to fish.
I think that for hardware open source projects, it is better to just throw out pictures, show off functions, and send HEX. It's better to explain the principles clearly and let others understand your design thoroughly before you share it.
Speaking of power supply, let’s start with the power part.
Power loop:
Input-->xl4501 (my previous open source buck-boost topology, click on my personal homepage to view)-->LM317 (further voltage stabilization)-->ACS712 (Hall current sampling)-->Output
Dummy load circuit:
The output current flows in the reverse direction-->ACS712 (Hall current sampling)-->IRF1404 (low on-resistance MOS tube)-->R12 (sampling resistor)-->GND
Peripheral voltage generation:
First is the intermediate voltage:
Power 5V power supply:
-5V generates:
In fact, all buck topology ICs can be used to generate negative voltage (including synchronous rectification ICs).
Now new PDFs are generally not written. The pictures you see on Baidu are basically MC34063. This chip is very versatile, but its efficiency cannot be improved.
Having said that, the topology inside is worth learning.
Simple power supply filter circuit:
After RC filtering, it is amplified by a triode to suppress ripple.
This starts with the ripple suppression parameter.
The picture below is of 1117. As a low dropout regulator (LDO), since the P tube is used as the adjustment tube, the curve is in line with expectations.
The picture below is of a 7805. Due to the use of N-tube adjustment, it is not sensitive to input interference, so the high-frequency ripple is suppressed.
This is good for DCDC linear voltage stabilization for precision parts.
(The linear voltage regulator in the power section uses LM317 for the same reason, and the model with high current and low voltage drop is LM1084)
Feedback adjustment part:
Pre-regulated voltage follows:
The voltage of LM317 is divided by R6 and R7 and input into Q3 (PMOS). When the GS voltage of Q3 reaches the conduction threshold, Q3 turns on and FB is pulled high.
This causes the XL4051 output to become low, allowing the voltage to follow without being controlled by a microcontroller. According to the parameters on the picture, the measured voltage at both ends of the LM317 is 3V.
Moreover, the bottom of R10 is not connected to GND, but to the output of one of the DACs, so that it can be adjusted from 0V.
[Assumption: Ignore Q3, the voltage of DCDC_CTRL is 1.25V (FB’s internal reference voltage is also 1.25V), then the output voltage is also stable at 1.25V,
If the DCDC_CTRL voltage is higher than 1.25V, the output will be lower than 1.25V (provided there is a load, if there is no load, the current will flow from the feedback resistor to the output). Like an inverting proportional amplifier circuit]
DAC driver amplification:
The first op amp forms the Butterworth filter, which is used for filtering and increasing the input resistance.
The second op amp forms an inverting proportional amplifier, allowing the DAC dynamic range to be adjusted arbitrarily within the op amp power rail, giving full play to the number of DAC bits.
Single-ended to differential circuit:
Because I wanted to use the resolution of the ADC, I used GS8592 (a highly cost-effective precision rail-to-rail operational amplifier) to make a single-ended to differential circuit. However, the current situation is that the current reading is not very stable. I am not sure whether this circuit is Reliable, wait until the problem is solved and the circuit is modified before editing again.
IO reuse for human-computer interaction:
LCD1602 only loads data on the falling edge of EN. At other times, the data pin can be used for other purposes.
Here I lead out a button enable terminal. After setting it low, the button status can be read.
This is the schematic diagram of temperature sampling. A constant current of 4mA is generated through the triode current mirror circuit and flows through the NTC resistor.
This is a resistance table copied from pdf. After calculation and conversion in Excel, the array is exported. It is recommended that you do the same.
(The Tencent document link is given at the end, you can learn the corresponding functions)
Through the binary lookup table method, the ADC voltage can be converted into temperature. The code is as follows:
//输出16~99度
uint8_t ntc_decode(uint16_t dat)//以降序排序的二分法查表
{
uint8_t min=0;
uint8_t max=83;//限制最大显示99度
uint8_t temp;
uint8_t i;
for(i=0;i<3;i++)//二分查表
{
temp=(min+max)/2;
if(dat>=ntc_code[temp])
max=temp;
else
min=temp;
}
for(i=min;i<max;i++)//遍历查表
{
if(dat>=ntc_code[i])
break;
}
return i+16;
}
CGRAM uses code to simulate bar display. See the video below for the specific effect.
Through this analog bar, the screen space of 1602 is saved.
Through the percentage of the actual value and the target value, the user can know whether the current mode is constant current or constant voltage, and estimate the current set value.
It is convenient to view faster changes (the refresh speed of the multimeter is generally 4HZ, the character refresh here is 5HZ, and the analog bar is 10HZ)
void lcd_write(uint8_t dat,uint8_t cmd);//1602写数据,cmd为0为命令,1为数据
void LCD_analog(uint8_t add,uint8_t dat)//模拟条CGRAM加载
{
uint8_t temp;
lcd_write(0x40+(add<<3),0);//CGRAM地址
if(dat<=40)//正向百分比显示
{
for(temp=40;temp>dat+4;temp-=5)
lcd_write(0x00,1);//一次填充一行空白
if(dat>0)
{
dat--;
lcd_write(0x1f<<(4-dat%5),1);
temp-=5;
}
temp-=5;//当作渲染了一行
for(;temp<40;temp-=5)//如果还没有负溢出,继续填充
lcd_write(0x1F,1);//一次填充一行黑点
}
else if(dat<80)//反向百分比显示
{
dat-=39;//偏移,然后同理
for(temp=40;temp>dat+4;temp-=5)
lcd_write(0x1f,1);
if(dat>0)
{
dat--;
lcd_write(0x1f>>(dat%5),1);
temp-=5;
}
temp-=5;
for(;temp<40;temp-=5)
lcd_write(0x00,1);
}
}
The rest of the code will not be released. The coupling between functions is very high. It cannot be expressed clearly by simply showing one or two functions. The code will be released after the software and hardware are perfected!
The core algorithm of this power supply is a binary lookup table. During calibration, the corresponding DAC and ADC are saved in the flash.
Skipped intermediate values are filled proportionally. Check the table to find it out when you need it.
Advantages: simple and fast, eliminating the nonlinear error of ADC.
Disadvantages: The output changes caused by the time drift and temperature drift of PT8211 cannot be avoided. And only the calibration data occupies 64kB of flash space
(Quiet BB: ST’s 103c8t6 has 128kB flash, GD’s doesn’t know yet).
If you want to correct the error later, you need to add PID operation.
Components and problems encountered:
Material name | Problems encountered |
---|---|
CS1237 (electronic scale ADC) | The logic voltage requirement is 0.7VDD. However, 3.3 is 0.66 of 5, so it must be driven through level conversion. |
PT8211 (audio DAC) | You can use SPI to be compatible with the I2S bus, but the actual number of output bits is far less than the 16 bits marked. |
GS8592 (precision operational amplifier) | This project uses a lot of components, and the low offset voltage is very suitable for instrument applications. However, I don’t know whether it is a wiring or ACS712 problem, and the current reading is always jumping. |
STM32F103C8T6 | The CH2N channel of PWM cannot be adjusted with the HAL library. It happens to be the IO of the LED backlight driver. |
GD32F103C8T6 | Transplantation has not started yet |
The overall design adopts a motherboard design and is connected through FPC cables, making it easy to adjust the height or plug in and out the STM32 minimum system board.
(The potentiometer with white tape is a sign of calibration)
Finished product pictures:
As an all-around player, how could this be possible!
Developed features: | Features to be developed: |
---|---|
Complete human-computer interaction operation | High efficiency output mode |
Temperature reading and fan control | two-quadrant model |
Adjustable constant current and voltage low noise output | External modules achieve more functions |
false load mode | *** |
Expand module functions:
Lithium battery balancing discharge and single cell voltage detection
Temperature reading of T12 soldering iron interface
Connect to the host computer
Function demonstration video address: https://b23.tv/sxZvqv
Making videos is also a skill, but unfortunately I don’t have more energy to focus on other things. The videos are very poor, with no editing or cutting. Please bear with me.
[Tencent Documents] NTC temperature and voltage comparison table: https://docs.qq.com/sheet/DVHR0Tk9NRnRDeWZ1
Problems with the current circuit:
The ripple is large at constant current output or load, which cannot be solved by this version of PCB. It is necessary to use simulation, modify the active filter circuit of the op amp, and adjust the zero and pole points before it can be used normally.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet