I find that regulating my free time with something like the pomodoro technique to be very helpful. When I'm in a pomodoro, I am in my own world of code, but when the buzzer rings I make coffee, read a book, or take a walk.
Just having the span of 5 minutes to not think about work enables me to attack the problem with renewed vigor. Ultimately I get more done, and I'm happier for it!
If you don't feel like working - go and do something you feel like doing. You'll be a lot more effective when you feel like working again.