You could be talking about action potentials. Nerve impulses are action potentials of an axon (nerve cell). This is possible because there is a voltage difference between inside and outside of the cell. This is regulated by ion gates and ion channels, which are composed of calcium, sodium, and phosphorus. As you can recall in your biology class, action potential occurs when sodium channels open, allowing influx of sodium ions to excite the resting potential of inside the membrane. This, in turn, reverses polarity, so sodium channels close and sodium ions are actively transported out of the membrane returning the voltage difference to resting state. Calcium channels and ions also serve the same way as sodium, but have have longer durations. Thus, only magnesium is not involved in generation of nerve impulses or action potentials.