Jump to content
Sign in to follow this  
Rei Vilo

[SOLVED] Help! Software PWM for the MSP430F5529

Recommended Posts

SOLVED! Thanks Energia! Link to solution

 

I'm using a BoosterPack with PWM in pin 9 = P2_1 @ G2553.

 

Unfortunately, the MSP430F5529 doesn't feature PWM in pin 9 = P4_2 @ F5529.

 

How to implement a software PWM?

 

I guess I need to use a timer-based interrupt, but I have no experience in that field.

 

This would be very useful to improve compatibility across the BoosterPacks and LaunchPads.

 

Thank you for your help.

Share this post


Link to post
Share on other sites

Well, you could set pin 9 as an input, use a hardware pwm pin, and use a jumper from that pin to pin 9. Sure, you loose a pin, but unless your design is pin-heavy, I'm sure you have one to spare.

Share this post


Link to post
Share on other sites

I usually like to design my boosterpacks so they are reconfigurable with a knife and solder+wire for these scenarios. But rigging it with a jumper wire sharing with another pin is an option... Alternately I have a boosterpack design you may want to make a run of from Seeed or Elecrow. Let me get a link.

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Share this post


Link to post
Share on other sites

That said, the technique for hardware-assisted software PWM is to take a timer not currently in use, configure its CCR0 to the max count, CCR1 or 2 or whatever sets your duty cycle, then set an interrupt function for its compare-match and the timer's overflow (these may be different and require 2 different ISR functions, can't remember). Inside those functions you manipulate the pin (P4OUT |= BIT2 or P4OUT &= ~BIT2). Be sure to set the interrupt-enable bit and configure the counting mode & clock source in the TxxCTL register correctly.

 

Note- these ISRs do not need to mess with the LPM bits.

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Share this post


Link to post
Share on other sites

Easiest way to do this is through some trickery with the PMAP registers. Pin 9 aka P4_2 happens to be on port 4 that features the pin mapping peripheral. This means that a lot of functions can be mapped to any pin on port 4 including the timer stuff. The idea behind this is to PMAP P4_2 to one of the timer outputs using the pinMode_int() API. In the example below I mapped P4_2 to TB0.2. I will explain later why I picked this pin.

The following define will be used as a parameter to the pinMode_int() call:

#define PM_P42_SET_MODE ((PM_TB0CCR2A << 8) | PORT_SELECTION0 | OUTPUT)

The upper 8 bits of the mode parameter of pinMode_int defines the values for the PMAP register. In this case I am configuring it to be timer compare output TB0.2.

The digital_pin_to_timer[] that is defined in pins_energia.h does not include a timer define for P4.2 so we will need to use a shadow pin to trick it into actually setting up TB0.2 as timer output. It so happens to be that TB0.2 is also on P7.4. So in the Sketch we will actually do an analogWrite to this pin instead of P4.2. P7.4 does have the timer defined and since we "copied" that timer output to P4.2 using the PMAP register we will also see a PWM signal on P4.2. This does mean that the PWM signal is also present on P7.4. Alternatively you can use P3.6 (TB0.6) and P3.5 (TB0.5) if P7.4 is in conflict with other pins. Below is the complete Sketch:

#define PM_P42_SET_MODE ((PM_TB0CCR2A << 8) | PORT_SELECTION0 | OUTPUT)

void setup()
{
  pinMode_int(P4_2, PM_P42_SET_MODE); 
  analogWrite(P7_4, 128);
}

void loop()
{
  
}

Let me know if this works for you.

Share this post


Link to post
Share on other sites

So you remapped it with port mapper?

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Let me know if this works for you.

 

 

Yes, and it works very fine. 

 

I had to adapt all the libraries as they are designed for smaller screens or other MCUs.

 

The F5529 provides enough memory for one image, but the screen requires a second one for transition. Next step: use the EEPROM provided by the BoosterPack as cache.

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  

×