If it is just when you fall asleep that is normal. Since it is keeping you up have you had a lot of exercise during the day? I have muscle fatigue and get that too especially when I first day down and for about an hour afterwards. It is possible that your potassium could be low. Be sure to hydrate and get enough potassium.
mkh9
Thanks for using the forum. I am happy to address your questions, and my answer will be based on the information you provided here. Please make sure you recognize that this forum is for educational purposes only, and it does not substitute for a formal office visit with a doctor.
Without the ability to examine and obtain a history, I can not tell you what the exact cause of the symptoms is. However I will try to provide you with some useful information.
A condition that can cause twitches and cramps of the foot, particularly at night, is restless legs syndrome. Usually patients with this complain of aching sensations in the calves with or without creeping/crawling feelings. These symptoms may be relieved with moving the legs. The treatment of this condition may involve a medication to increase your dopamine levels or may be treated with neurontin, which is also used to treat neuropathic pain as mentioned above.
You should discuss your symptoms with your primary care physician.
Thank you for this opportunity to answer your questions, I hope you find the information I have provided useful, good luck.