You use 'a while' if you're also using the word 'for', as in, "I'll drive for a while; you get some sleep." If you're not using 'for', then you use 'awhile'. "I'll drive awhile; you get some sleep."
This–and a lot of other useful information–can be found at Paul Brians' (Big) List Of Errors page. It's ridiculously helpful, and if you'd prefer it in an offline format, he's written a book.