Jump to content
43oh

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

 

 

 

Link to post
Share on other sites
  • 2 months later...

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...