The court shall order a mental examination of the defendant when it has reasonable ground to doubt the defendant's mental capacity to proceed. Prior to the ordering of any such mental examination, the court shall appoint counsel to represent the defendant if he has not already retained counsel.
La. Cr.P. § 643