Jump to content
Sign in to follow this  
Bernard

LM4F120 PWM

Recommended Posts

Hi,

 

I have found an excellent tutorial about PWM on Stellarpad that help me to understand .

 

Here is the Energia version :

/* PWM * TIMER0 B 
 * PF_1  RED_LED    
 */
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"

unsigned long ulPeriod, dutyCycle;

void setup()
{ 
  ulPeriod = 2000; 
  dutyCycle = 500;

  // PF_1 on  T0CCP1
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinConfigure(GPIO_PF1_T0CCP1);
  GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1);

  // Timer configuration
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  TimerConfigure(TIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);
  TimerLoadSet(TIMER0_BASE, TIMER_B, ulPeriod -1);
  TimerMatchSet(TIMER0_BASE, TIMER_B, dutyCycle); 
  TimerEnable(TIMER0_BASE, TIMER_;
}
void loop()
{    
  TimerMatchSet(TIMER0_BASE, TIMER_B, dutyCycle++);

  if(dutyCycle >= ulPeriod - 1)
    dutyCycle = 0;
  delay(1); 

}
// End of .ino file


I wanted to share .. it could be usefull for beginers like me.

 

Salutations

 

Bernard

 

 

 

Share this post


Link to post
Share on other sites

Just remember to add the line

 

HWREG(TIMER0_BASE + TIMER_O_TAMR) |= (TIMER_TAMR_TAMRSU | TIMER_TAMR_TAPLO | TIMER_TAMR_TAILD);

 

if you bump into problems. It is in the comments section of that blog post.

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  

×