samadivk 0 Posted November 3, 2013 Share Posted November 3, 2013 Hi I'm wondering if there's a way to create multiple threads on an msp430g2553 or msp430g2452 using Energia. My project is to try to get software PWM, so I need to create a loop to turn the pin on and off at the correct times, but in a different thread. Thanks in advance! Quote Link to post Share on other sites
grahamf72 169 Posted November 4, 2013 Share Posted November 4, 2013 Msp430 does not have hardware multi-tasking or multi-threading. The closest you can achieve is through the use of a timer interrupt to interrupt the main program and then execute some other code. When the interrupt has completed, control returns back to where the main code was when the interrupt triggered. Inside the interrupt, care needs to be taken to not call code which is not re-entrant, and be certain that it will finish the interrupt routine faster than the timer interrupt. Sent from my iPhone using Tapatalk Quote Link to post Share on other sites
roadrunner84 466 Posted November 4, 2013 Share Posted November 4, 2013 Threading is taking the approach of multi-processing backward. Instead of trying to make your chip into a single sequential machine, observe that the peripherals allow you to do true multi-processing, albeit all except one be very simple tasks. PWM for example is very well done with the timer. I personally would just apply the timer and use that to set PWM in the ISR (or directly PWM wit the timer if that serves the purpose enough). But Energia is claiming control of the timers, and altering them will affect some of the background stuff that's going on. So in the case of Energia, you could attach to the millis interrupt (which is provided from a timer) and do SoftPWM in that function. Quote Link to post Share on other sites
energia 485 Posted November 4, 2013 Share Posted November 4, 2013 @@samadivk, what is the reason for not wanting to use analogWrite? It will help planning enhancements if we understand what's missing from the current API's. Robert Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.