I agree with most of the comments, but there is something else to try: nootropics.
In particular, for this exact application (well for me work--mathematical software, i'm unfortuantely way too old to have 'homework') I have found some success with oxiracetam + the GPC choline. It doesn't give any jitters like caffeine, and it doesn't have any emotional effect one way or another. What it does do is make me want to work and do cognitively difficult things instead of blowing it off.
I've used this one before:
but there are many similar ones.