The expert witness in a criminal trial

What is the role of the expert witness in a criminal trial? What are the two primary points in a criminal trial during which the expert witness may have to testify?