The week before Halloween Dumbledore found her examining Helga's crest. When he had put the first charms on her- learn everything, protect Harry, take care of Harry. So when the troll attacked, she hadn't been where she was supposed to be because of Ron, and she lied to protect them. And she did it, not because she felt she owed them because Dumbledore ordered her to.