Jump to content
43oh

analogWrite bug with msp430g2553 in energia


Recommended Posts

Hello,

 

When I execute the code below, and check P2_1 and P2_2 on my scope, I see that both pins are 128, i.e, whichever analogWrite statement takes place the last, it overrides the one before. I am using launchpad v1.4

 

If I write 0 to one of the pins, it will work correctly.

 

void setup()
{
 
   pinMode(P2_1, OUTPUT); 
   pinMode(P2_2, OUTPUT);   
   
   analogWrite(P2_1, 32);
   analogWrite(P2_2, 128);  
   
}
 
unsigned long time;
 
void loop()
{
  time = millis();
  delay(100);  
}
Link to post
Share on other sites

On the MSP430G2553 P2_1 and P2_2 are analog write capable. But they are both connected to TimerA1 CCR1, so if you use analogWrite on both, they will both deliver the same output. You need to change one of your pins to one that is on a different Timer or a Different CCR register.

 

Options include:

P1.2, P1.6 or P2.6 - all on Timer0, CCR1

P2.4 or P2.5 - on Timer1, CCR2

 

This is a common mistake with analogWrite on the MSP430G2 launchpad - although the device has 7 pins capable of PWM output, the way the timers are connected there are only 3 PWM channels.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...