I'm not an expert, it may be worth a go, then you could see if you still get the headaches in the morning, even if you've not taken the tablet
Or, perhaps schedule the tablet progressively later each day till you eventually get to your bedtime?
Could you have a chat with a pharmacist?
Hopefully, somebody who knows what they are talking about will be along soon