id ask at the end of your third week... just in case the attending would like to go over your CV and maybe personal statement, then have a chance to talk with you directly the following and last week. granted you should of had plenty of face time with the attending by this point, but they still may want to meet with you. it happened with two of my letter writers. also, remember it may take several weeks for an attending to write your letter, which can hurt you if your rotation is late.
i have no idea how long after a rotation you can/should ask... you could always ask if they feel comfortable writing you a letter, and if they say no, then they say no. its seems like the longer you wait, the less impressive your letter will be.
you should ask before you leave the rotation. you will have to give them a copy of you CV and a little more about yourself will probable help as Cakes stated.
most services that have a lot of rotators realize the question of a LOR will be coming at some point. i think while you are on the service and you get a sense of how you are doing (meaning you think you are doing well), then you should probably ask. if you think you are not doing well, you may not want that LOR. i think 3 weeks is a good time for asking, it's not last minute and it is not too early.