altineller 4 Posted August 19, 2014 Share Posted August 19, 2014 Hello, Is there anyway to output pwm from a msp430g2553 other than analogWrite() ? I am expecially interested in increasing the resolution of pwm output. I have been implementing a pid motor controller, and i am almost done, but I am checking my options for precision and integration time. Best Regards, C.A. Quote Link to post Share on other sites
bobnova 59 Posted August 19, 2014 Share Posted August 19, 2014 Oh yes, you can get far more precise and a higher or lower overall frequency too. That's datasheet / UserGuide material though. I did some playing with copy/pasted code a while ago but don't remember enough to help you much. The stellaris / Tiva-C boards have PWMWrite in Energia, which allows you to set the resolution, frequency and duty cycle in one go (takes a while and causes glitches, though). Sadly the 2553 doesn't have that function in energia. Quote Link to post Share on other sites
spirilis 1,265 Posted August 19, 2014 Share Posted August 19, 2014 Interesting this discussion came about b/c I'm talking with @@energia on IRC about the issue. The current Energia analogWrite implementation is basically broken and needs fixing and we're looking at our options... In theory analogFrequency() I think lets you change the precision of the PWM subsystem too. Quote Link to post Share on other sites
energia 485 Posted August 19, 2014 Share Posted August 19, 2014 @@altineller are you referring to increasing the number of steps in which you can control the duty cycle or the frequency of the PWM signal? Quote Link to post Share on other sites
altineller 4 Posted August 23, 2014 Author Share Posted August 23, 2014 @@energia Yes, I am interested in having higher resolution in changing duty cycle of the pwm signal. @@bobnova are there any documentaion on the PWMWrite function? I could not see it in energia reference. It would also be interesting to change pwm frequency itself (not duty cycle) - this is said to eliminate noise when driving a motor, but has some disadvantages as well. Best, Quote Link to post Share on other sites
bobnova 59 Posted August 25, 2014 Share Posted August 25, 2014 @@altineller not really, no. It's something of a hidden function. You have to include wiring_analog.c (#include <wiring_analog.c>) to kick things off. That includes the PWMWrite function. Then you can call it thusly: PWMWrite(PIN,numberOfSteps,dutyCycle,frequency); For example: PWMWrite(PD_1,500,250,6000); Would start PWM on pin PD_1, 500 steps from 0 to 100%, 50% duty cycle (500 / 2 = 250), 6000Hz frequency. It's worth noting that the function call does glitch when you call it on a pin already putting PWM out. It's not enough to hear driving a speaker, but it could cause you issues if you're calling it a lot. There's a thread around here somewhere on that subject. The frequency cap is very high, if I recall correctly I'd tested it to work >1MHz. I could be thinking about a different MCU, I've tested sort of a lot of them. Santosh333 1 Quote Link to post Share on other sites
abecedarian 330 Posted August 25, 2014 Share Posted August 25, 2014 Hmm... trying @@bobnova suggestion using: #include <wiring_analog.c> void setup() { // put your setup code here, to run once: pinMode(P1_6, OUTPUT); PWMWrite(P1_6,500,250,6000); } void loop() { // put your main code here, to run repeatedly: }Results in the following error (on a G2553 LP): In file included from sketch_aug25a.ino:1:0: E:\energia-0101E0012-windows\energia-0101E0012\hardware\msp430\cores\msp430/wiring_analog.c: In function 'void analogWrite(uint8_t, int)': E:\energia-0101E0012-windows\energia-0101E0012\hardware\msp430\cores\msp430/wiring_analog.c:107:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] sketch_aug25a.ino: In function 'void setup()': sketch_aug25a.ino:7:29: error: 'PWMWrite' was not declared in this scope Quote Link to post Share on other sites
bobnova 59 Posted August 25, 2014 Share Posted August 25, 2014 I think I might have edited my wiring_analog. Try #include <wiring_private.h> It's in energia somewhere. EDIT: I have no idea if it works on G2553s, as I mentioned up above I've only used it as a Tiva-C / Stellarpad function, it may well not exist for the G2553. The G2553 timers are certainly capable of different frequencies and resolutions though. Quote Link to post Share on other sites
fyaman66 1 Posted February 3, 2016 Share Posted February 3, 2016 Hello, Thanks alot. I found the solution this worked for me: #include <wiring_analog.c> void setup() { pinMode(PL_4, OUTPUT); PWMWrite(PL_4,1000,50,50); // PWMWrite(PINnumber, number of steps, dutycycle, frequency); } Fmilburn 1 Quote Link to post Share on other sites
energia 485 Posted February 5, 2016 Share Posted February 5, 2016 @@altineller for changing the analogWrite() resolution on MSP430 see this post: http://forum.43oh.com/topic/9341-change-resolution-pwm-with-msp430fr6989/?p=70874 altineller 1 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.