Hi Frank,
Your best bet is to stay for 3 months. I wouldn’t recommend staying any longer. Three months in Spain is still a lot better than 3 winter months in the UK.
Sadly, you didn’t apply for Spanish residency for your earlier trips, which you should have done as they were over three months long. If you had, you would have been able to stay for longer now.