Jump to content
Sign in to follow this  
altineller

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);  
}

Share this post


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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×