Hostal Goya in Barcelona has a great location very close to Catalunya and Las Ramblas - www.hostalgoya.com
. They don't do breakfast but there's a really excellent "all you can eat" place opposite that is open all day - food is freshly prepared and very cheap.
Hostal Persal in Madrid also has a great location near Plaza Santa Ana - www.hostalpersal.com
. It's a bit basic but clean and safe. Plaza Santa Ana is within walking distance of a lot of the main sights, and has some great bars and restaurants. It's a lot of fun just going from bar to bar picking up tapas along the way. I'd definitely recommend staying in that area.
A bit more upmarket and in the same area is Hostal Adria Santa Ana - www.hostaladriasantaana.com
. They don't do breakfast but there are plenty of places nearby that do.
There is a huge festival in Barcelona in September called La Merce. It's a fantastic time to be there but it might be worth checking the dates because hotels fill up very very fast while it's on.