if you woke up from a nightmare, its likely that your body was responding to the signals that were going through your brain, gearing up your "fight or flight response" thinking it needed to rect to whatever was getting your brain so worked up.
if you weren't having a nightmare, or stressed out by something in your environment, a pounding heart usually is caused by one of two things. Oxygen deprevation (which is usually caused by physical exertion, but that's an unlikely scenerio if you are sleeping) i guess there's a chance you are experiencing some sleep apnea and not breathing properly while you sleep. If this is the case, you should see a doctor about it. The other thing that causes you to have the sensation of a pounding heart is high blood pressure. This can be caused by a number of things, but if you're only experiencing it when you wake up from sleeping, my guess would be dehydration. I'd reccomend trying to drink more water through-out the day in general, but especially before bed. And if you wake up and your heart feels like its pounding hard, get up and have a glass of water. It will calm your nerves a bit and hydrate you a bit more. hopefully that will help.