1. PN junction energy band and contact electromotive force difference
Under thermal equilibrium conditions, the junction area has a unified EF; in the part far away from the junction area, the relationship between EC, EF, and EV is the same as the state before the junction is formed. From the PN junction model and energy band diagram under thermal equilibrium (see Figure 1), it can be seen that when N-type and P-type semiconductors exist alone, there is a certain difference between EFN and EFP. When the N-type and P-type are in close contact, electrons will flow from the higher Fermi level to the lower Fermi level, and the holes flow in the opposite direction. At the same time, a built-in electric field is generated, and the direction of the built-in electric field is from the N area to the P area. Under the action of the built-in electric field, EFN will move down along with the energy band of the entire N region, and EFP will move up together with the energy band of the entire P region until the Fermi level is leveled to EFN=EFP and the carriers stop flowing. At this time, the conduction band and the valence band of the junction area bend correspondingly, forming a potential barrier. The barrier height is equal to the difference between the Fermi level when N-type and P-type semiconductors exist alone
qVD=EFN-EFP (1)
Derives
VD=(EFN-EFP) /q (2)
In the formula: q is the electric quantity of electrons; VD is the contact electromotive force difference or the built-in electromotive force.
For states outside the depletion zone, VD is
VD=(KT/q) ln(NAND/ni2) (3)
In the formula: NA, ND, ni are acceptor, donor, and intrinsic carrier concentration, respectively.
It can be seen that VD is related to doping concentration. At a certain temperature, the higher the doping concentration on both sides of the PN junction, the greater the VD. For materials with forbidden bandwidth, ni is small, so VD is also large.

2. PN junction photoelectric effect
When the PN junction is exposed to light, both the intrinsic absorption and extrinsic absorption of photons will produce photo-generated carriers. But it is only the minority carriers excited by intrinsic absorption that can cause the photovoltaic effect. The photo-generated holes generated in the P-zone and the photo-generated electrons in the N-zone are multiple electrons, and they are all blocked by the barrier and cannot cross the junction. Only the photogenerated electrons in the P zone, the photogenerated holes in the N zone and the electron-hole pairs (minority carriers) in the junction zone can drift through the junction under the action of the built-in electric field when they diffuse to the junction electric field. The photo-generated electrons are drawn to the N region, and the photo-generated holes are drawn to the P region, that is, the electron-hole pairs are separated by the built-in electric field. This leads to the accumulation of photogenerated electrons near the boundary of the N zone and the accumulation of photogenerated holes near the boundary of the P zone. They generate a light-generated electric field that is opposite to the direction of the built-in electric field of the thermally balanced PN junction, and its direction is from the P zone to the N zone. This electric field lowers the potential barrier and reduces the photoelectromotive force difference. The P terminal is positive and the N terminal is negative. Therefore, the junction current flows from the P area to the N area, and its direction is opposite to the photocurrent.
In fact, not all photo-generated carriers generated can generate photo-generated current. Suppose that the diffusion distance of holes in the N zone during the lifetime τn is LP, and the diffusion distance of the electrons in the P zone during the lifetime τn is Ln. Ln+LP =L is much larger than the width of the PN junction itself. Therefore, it can be considered that within the average diffusion distance L near the junction, the generated photo-generated carriers can generate photocurrent. When the distance of the generated electron-hole pair from the junction region exceeds L, all of them will recombine during the diffusion process, which has no effect on the photoelectric effect of the PN junction.
An additional current (photocurrent) IP will be generated in the PN under illumination, and its direction is the same as the reverse saturation current I0 of the PN junction, generally IP≥I0. at this time,

Let IP=SE, then

The voltage between the P terminal and the N terminal when the external circuit of the PN junction under illumination is open, that is, the V value when I=0 in the above current equation

Open circuit voltage VOC
VOC=(KT/q) ln(SE+ I0) / I0 ≈ (KT/q) ln(SE/I0) (7)
The PN junction under the light, when the external circuit is short-circuited, the current flowing from the P terminal through the external circuit and flowing from the N terminal is called the short-circuit current ISC. That is, the value of I when V=0 in the above current equation is ISC=SE.
VOC and ISC are two important parameters of the PN junction under light. At a certain temperature, VOC has a logarithmic relationship with the illuminance E, but the maximum value does not exceed the contact electromotive force difference VD. In low light, there is a linear relationship between ISC and E. The four states of PN junction are as follows:
(1) Thermal equilibrium state without light. N-type and P-type semiconductors have a uniform Fermi level, and the barrier height is: qVD=EFN-EFP.
(2) The circuit outside the PN junction is open under stable light. The photo-generated voltage VOC that appears due to the accumulation of photo-generated carriers no longer has a uniform Fermi level, and the barrier height is: q (VD-VOC).
(3) The external circuit of the PN junction is short-circuited under stable light. There is no photo-generated voltage at both ends of the PN junction, and the barrier height is qVD. The photo-generated electron-hole pairs are separated by the built-in electric field and flow into the external circuit to form a short-circuit current.
(4) There is light and load. A part of the photocurrent establishes a voltage Vf on the load, and the other part of the photocurrent is offset by the forward current caused by the forward bias of the PN junction, and the barrier height is q (VD-Vf).