The 1640s are the last years of the Thirty Years War, and part of the Franco-Spanish War. In the years prior to the conflicts, Spain was built up to be a huge and renowned Imperial Empire (though flawed), and when they came, Spain seemed to fail to live up to its name. Throughout the Thirty Years War, Spain was involved in numerous conflicts in its possessions in Italy, the Netherlands, and at home in the Iberian Peninsula. Though Spain saw early successes in the war, it was eventually curbed when it began to lose vital battles, and this was made worse because of Spanish success prior to the losses. In 1637 the Dutch captured Breda, in 1638 Bernard of Weimar took Beisach, effectively cutting the Spanish Road in half. This heavily jeapordized Spains position in the Netherlands, since now supplies could only be sent to it via the English Channel, which dependend on the English cooperating. In 1639, a large Spanish fleet manned by Don Antonio de Oquendo was destroyed by the dutch, a fleet which was partly tasked to relieve the situation in the Netherlands. Finally in 1938, a Portugese-Spanish Armada that sailed to reconquer Brazil was thwarted by a smaller Dutch fleet and effectively disbanded after the Portugese Commander gave up.
In addition, the Spanish economy was dying. Castile, arguably the most important part of Spain, took the main hit of the economic demands of the wars Spain waged in the 16th and 17th centuries. By the time the Thirty Years War and the Franco-Spanish Wars loomed over, Castile was increasingly weary and tired, so denuded of men that the levies were a pitiful affair, effectively making it more and more impossible to keep the armies up to strength. The economic position by now was also exceptionally grave, Spain's last source of economic strength was the trading system between Seville and the America, and it was failing. Olivares, the Spanish finance minister at the time, whos repeated confiscations of silver remittances and interference in the American trade lead to the inevitable result of failure. Effectively, the merchants lost confidence, as the Sevillian shipping was in decay, and by 1640, Spains supply of silver abruptly ended when there were no silver fleets. The whole system of credit and confidence by which Seville had for long shored up the Spanish Monarchy was gradually crumbling. This might not sound huge, until one considers that Seville was effectively Spains center of Silver trade, as it was called the "Sevillian Commercial System", and provided Spain with its silver and credits. Therefore, when it began to crumble due to the result of the decaying trade with America and the interference of Spanish officials, the fall of the Sevillian silver trade meant a crumbling of the Spanish economy which was built upon it. Nothing was made better by the fact that Spain was in a state of unending war and abuse prior to the 1640's, and so many wars eventually pay a toll on even an empire as grand as the Spanish Empire. By 1640, the Spanish army was spent and tired, the funding of the war effort was rather poor, and the constant defeats in its recent wars meant Spain was losing means of funding its wars. The loss of the connectivity of the Spanish Road particularly secluded its European possessions in Italy and the Netherlands, increasing the costs needed to supply and support them, all the while making it harder for them to send back their wealth to Spain. Spains acute lack of good leaders in the 17th century compounded its problems further.
Therefore, with Spain slowly but surely losing its wars with France, and its economy slowly crumbling, the Spanish did one last thing to ill the public. The Spanish decided that there was still a chance of victory through a prolonged stalemate with France, where an induced exhaustion of France would bring her to terms. This would require unrelenting pressure on the French, which would require all of Spain to help and contribute towards, as Castile was worn out and mostly a spent force. This meant for example, that Catalonia would have to be prepared to dedicate troops to Italy and a renewed offensive across the Flanders border. Therefore, Spain decided that the troops fighting the Salses campaign should be billeted in Catalonia until the next campaigning season. One can easily imagine how Catalans would be hardly pleased to hear that now they had to house the Spanish army in their homes while Spain was losing the war and the economy was falling. Since the action of billeting Catalonia also meant that a new army to support the war effort was meant to be formed out of the Catalonian (among other provinces) populations, the existing Spanish troops were similarly in no state of mind to bother with the "second best".
The stage was set. Throughout February and March of 1640, troops clashed with the civilians, and the counts and dukes proved unable to retain order. In the ensuing rebellions, the Catalans were repeatedly alienated by Castile, since they meant to use Catalonia to fund the wars and bear the burden of Spains problems at the time. Effectively, the Conde Duque underestimated the willingness of the Catalans to request French help with ending their troubles.
At the same time, the revolts in Catalonia reignited the passion of the Portugese, who have for a long time now wished to cut ties with Castile, and Spain in general with increased determination. The ideas for a Portugese revolution were laid down when Spain unwittingly got the idea to try and settle both the revolt in Catalonia and the uneasiness of the Portugese by ordering a Portugese Army to put down the Catalonian revolts. All the while, the French secretly sent funds to Lisbon. On December 1, while the Royal Spanish Army marched into Catalonia, Portugal revolted and the entirety of the country effectively switched over, as Castile had virtually no troops in Portugal anymore. Immediately, the Spanish tried to mediate the situation by getting a peace treaty with the Dutch and with the Catalans. But even though they offered good terms to the Catalans, the Spanish army unwittingly wasn't stopped and kept marching on Barcelona, effectively rendering the Catalan public to be in no mood to accept peace terms. Riots in Barcelona broke out where supporters of Castile were hunted and stopped from considering any peace offers. The leader of Catalonia, due to the approaching Spanish army, was left with no choice but to declare that Catalonia would switch allegiance to the French on January 23. The French, who were rather happy with the switch of allegiance, flooded military support and defended Barcelona, forcing the Spanish army to wrongly retreat.
By now, with the crumbling economy, weakened army, and the loss of two vital principalities; Portugal and Catalonia, the Spanish crown had neither the money nor the men to prosecute its wars abroad while trying to suppress two local revolutions. The bold and admirable, though rather meddling and incompetent, rule of Olivares was eventually too much to put up with, and Andalusian nobles set out to fix the wrongs in Madrid, while following the example of Portugal and try to create Andalusia into an independent state. The conspiracy failed in 1641, but because the awkward rule of Olivares once again lead to the inflation and then crash of the worth of silver continued to inspire conspiracy plots to plop up everywhere. In 1643, the king and Olivares went to the front in Agron, where the Spanish army continued to see no more success than before their arrival. In these years, the French allthewhile captured Perpignon, and continued to crush the Spanish armies in several engagements. Spain was divided to fight a revolution in Portugal, a revolution in Catalonia, to fight French armies flooding into Spanish territory on the Iberian Peninsula, all the while trying to fight abroad in Italy, the Netherlands, and the seas as part of its contribution to the Habsburg cause of the Thirty Years War. Spain was a spent force, and the incompetency of the monarchy at solving these wars and problems lead to continuous conspiracies, revolts, and rebellions that had to be put down periodically throughout the 1640's.
To continue the events from here on (I mostly covered 1640-1643) would be a tedious task since Spain as a whole is a complex matter in the 1600's. Needless to say, however, that Spains source of revolututions and rebellions in the 1640's were largely inspired by its inability to stop going to war and effectively grounding down its manpower and will to wage war, the collapse of the Seville silver trade to America lead to a huge blow to the Spanish economy, and the Spanish alienation/mistreatment of Catalonia and Portugal effectively lead to their uprisings, both of whom would persist well into the late 1640's.
Main Source:
Imperial Spain: 1469-1716 by J.H. Elliot