pwm on the lpc1115 via om13087 board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pwm on the lpc1115 via om13087 board

1,620 Views
_arm_
Contributor I

I'm struggling to get PWM working on this board.  I'm using lpcxpresso and my code is below.  My goal is to have the blue LED on pin 28 of the board to blink along with the PWM signal (50% duty cycle so a basic square wave). And I want to use the pointer style syntax.

#include "LPC11xx.h"

int main(void) {

   // set up pin for PWM use (sec 7.4.23)
   LPC_IOCON->PIO0_9 &= ~(0x3FF);
   LPC_IOCON->PIO0_9 |= 0x2;

   // enable clock signal to 16 bit timer0 (sec 3.5.14)
   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);

   LPC_TMR16B0->PR          = 12000-1;
   LPC_TMR16B0->MR3       = 1000;
   LPC_TMR16B0->MR0       = 500;
   LPC_TMR16B0->MCR       = (1<<10);          // Reset on MR3 Match
   LPC_TMR16B0->PWMC    = 0b1010;         // set channel 0 and 1 to PWM mode (sec 18.7.12)
   LPC_TMR16B0->TCR         |= (0x3);            // Enable & Reset Timer
   LPC_TMR16B0->TCR         &= ~(0x2);       // Clear Reset Bit

   while(1){
   }

   return 0;

}

Labels (2)
0 Kudos
Reply
1 Reply

1,304 Views
_arm_
Contributor I

I figured out that the problem was coming from how I was setting up the project in lpcxpresso.  I went with the legacy CMSIS library instead.  (I followed along with Tutorial on Using MCUXpresso to create Cortex-M projects with CMSIS and adapted for lpcxpresso as needed.)  Here's the code that works.  I got the board blinking the green LED on PIO0_8.

#include "LPC11xx.h"

int main(void) {

//Set up 16 bit timer for PWM operation

//set up pin for PWM use (sec 7.4.23)
LPC_IOCON->PIO0_8 = (LPC_IOCON->PIO0_8 & ~(0x3FF)) | 0x2;
// LPC_IOCON->PIO0_9 = (LPC_IOCON->PIO0_9 & ~(0x3FF)) | 0x2;

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); //enable clock signal to 16 bit timer0 (sec 3.5.14)

LPC_TMR16B0->PR = 48000-1; //set prescaler max value, not used here (sec 18.7.4)
LPC_TMR16B0->MR3 = 1000; //set value for period (sec 18.7.7)
LPC_TMR16B0->MR0 = 500; //set value for duty cycle (sec 18.7.7)
// LPC_TMR16B0->MR1 = 500; //set value for duty cycle (sec 18.7.7)
LPC_TMR16B0->MCR = (1<<10); //set for reset on counter match (sec 18.7.6)

LPC_TMR16B0->CCR = 0; //set to timer mode (sec 18.7.11)
LPC_TMR16B0->PWMC = 0x1; //set channel zero to PWM mode (sec 18.7.12)

LPC_TMR16B0->TCR |= 0x3; //enable and reset counter (sec 18.7.2)
LPC_TMR16B0->TCR &= ~(0x2); //clear reset bit (sec 18.7.2)

while(1){
}
return 0 ;

}

0 Kudos
Reply