# Question analysis
[Bidirectional DC-DC converter (Question A).pdf](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fb8e7deb-6391-401d-a299- 8078e064f79d/%E5%8F%8C%E5%90%91DC-DC%E5%8F%98%E6%8D%A2%E5%99%A8%EF%BC%88A%E9%A2%98%EF%BC %89.pdf)
![QQ screenshot 20230501001907.jpg]
## The basic requirements are
to connect S1 and S3, disconnect S2, and set the device to charging mode.
### 1. Under the condition of U2=30V, realize constant current charging of the battery. The charging current I1 is step-adjustable within the range of 1~2A, the step value is not greater than 0.1A, and the current control accuracy is not less than 5%.
How to achieve this goal? You may think it's very simple, just need a simple PID control, but in the actual process, you will find a little problem, that is, the current control accuracy is unstable, jumps up and down, and it is difficult to meet the requirements.
Solution to the problem: Use dual PID control, and the output of the previous PID is used as the target value of the next PID to realize the series connection of one PID. For example, my code uses two samples to sample the values of I1 and U1, so that I1 is finally controlled at 2A, and the control accuracy is less than 5%. The solution
to achieve step-adjustable current
: Use interrupt triggering. For example, I use key0 to reduce the value of target. Because the interrupt can definitely be triggered, it can be modified. If it is placed in the main function, it may not be triggered.
### 2. Set I1=2A and adjust the output voltage of the DC regulated power supply so that when U2 changes within the range of 24~36V, the change rate of charging current I1 is required to be no more than 1%.
There is nothing to say. Pay attention to setting the upper limit of the output duty cycle. If the upper limit is lower, the current will not reach 2A.
### 3. Set I1=2A, under the condition of U2=30V, the efficiency of the converter is ≥90%.
In terms of efficiency, I don’t want to mention it. The efficiency I made is more than 94%.
### 4. Measure and display the charging current I1. The measurement accuracy is not less than 2% in the range of I1=1~2A.
Finish with some OLED functions.
### 5. It has overcharge protection function: set I1=2A, when U1 exceeds the threshold U1th=24±0.5V,
it is more clever to stop charging. What I was thinking at the time was to sample the output duty cycle of U1 when it reaches 24v. If it is 0, it means no PWM wave is output, but this will cause problems in the circuit, causing the battery to be partially short-circuited, generating a large current, and burning directly.
At this time, you can add a relay to the circuit. When U1 exceeds, turn off the PWM and use the relay to disconnect the circuit, and it will be successful.
> I didn’t write it in my code because I didn’t use it during the test. I used a fuse and didn’t pay attention to this
>
## Development part
### 1. Disconnect S1, connect S2, and set the device to discharge mode. Keep U2=30±0.5V, at this time the converter efficiency is ≥95%.
In terms of efficiency, pass.
### 2. Connect S1 and S2, disconnect S3, and adjust the output voltage of the DC regulated power supply so that when Us changes within the range of 32~38V, the bidirectional DC-DC circuit can automatically switch the working mode and maintain U2=30± 0.5V.
At that time, my teammates and I were confused by this question and thought we needed to switch between BUCK and BOOST modes. In fact, we didn't need to.
You only need to control BOOST to always keep U2 equal to 30V. The DC regulated power supply is just an interference item, so this question is not too difficult.
### 3. Simplify the structure and reduce the weight while meeting the requirements, so that the total weight of the two-way DC-DC converter, measurement and control circuit and auxiliary power supply is no more than 500g.
The total weight is smaller and simpler.
#Circuit part
## Bidirectional DC-DC
! [QQ screenshot 20230501004238.jpg]
## Auxiliary power supply
! [QQ screenshot 20230501004351.jpg]
Why is the auxiliary power supply needed?
Because there will only be one power output at that time, which is about 30V, and the microcontroller needs 5V power supply, and the chip needs 12V and 5V power supply, so an auxiliary power supply module is needed. Note: The terminal on the left below outputs 5V, the terminal on the right outputs 3.3V, and the terminal on the upper right outputs 12V.
**Because my file is relatively large, I will upload the test video to station B. Please note that the BOM table in my PCB file does not match. Please purchase according to the schematic diagram. The package and numerical value should be consistent. Please refer to the attachment for the code file. **