The p-n junction is the place where two different types of semiconductor material - the n-type and the p-type - meet within a semiconductor substrate. It is the properties of this junction that create separation between the negative and positive layers of the photovoltaic cell, creating a voltage across the cell and separate negative and positive terminals.
Doping is the process by which the positive and negative layers are created in the semiconductor substrate. In the case of most photovoltaic modules - and indeed most semiconductor based electronics - the base substrate material is silicon. Other elements are then added to different parts of the substrate to create n- and p-type material. This process of adding impurities to a semiconductor to change its characteristics is called doping.
Silicon (Si) has 14 electrons in its electron shells, and therefore 4 valence electrons in its outermost shell. In order to create the n-type layer of the PV cell, the upper layer of the silicon cell is doped with an element that has 5 valence electrons. Phosphorus (P), which has 15 electrons, is a common choice for this. Between the Silicon atoms and the atoms introduced through doping, there are a total of 9 valence electrons available for covalent bonding, which is one more than will fit in the valence shell, meaning that when the two atoms bond there is one extra valence electron free to participate in conduction.
Similarly, the p-type layer is created by doping the bottom layer of the silicon cell with an element containing only 3 valence electrons in its outer shell. Boron (B), which has a total of 5 electrons, is often used in the p-type layer. When the Silicon atoms bond with these atoms, a hole is effectively created because the resulting covalent bond lacks an 8th electron.
When the n-type and p-type materials meet at the p-n junction, electrons from the n-type layer tend to migrate into the p-type layer where they fill the "holes" in the outer valence shell created by the silicon-boron covalent bonding. The area at the edge of the junction from which the electrons migrated on the n-type side becomes positively charged because now there are positive ions that have given up an electron. Similarly, the area at the edge of the junction on the p-type side that accepted these electrons now has a net negative charge. This region is known as the "depletion region" because following the electron migration there are no longer any charge carriers available to move, and the junction is in a state of equilibrium. Additionally, these ions on each side of the junction create an electric field across it, which prevents any other electrons from crossing the junction from the n-type layer to the p-type layer.
However, if a circuit is created connecting the top and the bottom layer of a photovoltaic cell, electrons from the n-type layer that cannot travel across the p-n junction because of the depletion region can now travel through the circuit to reach the p-type circuit. Once the electrons arrive at the bottom contact of the PV cell, the same electric field that prevented them from traveling across the depletion region in the downward direction will now draw them back up to the n-type layer.