lpcware

PWM on LPC1343

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by tinto on Fri Jan 13 00:23:40 MST 2012
Could someone help me to find out the error in this program? I built the program successfully using LPCXpresso and debugged with the LPC1343 development board. But I am not getting any PWM at the output pins. The output is always high. What is the problem with this code?

#include "LPC13xx.h"

int main(void)
{
/*************************************************************************//**
  Set up 16 bit counters CT16B0 and CT16B1 to run as PWM with a cycle
  length of 4096
*****************************************************************************/

    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7);    // Enable clock to timer 0, CT16B0
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 8);    // Enable clock to timer 1, CT16B1

    // 16 bit timer 0 - CT16B0
    // PIO0_8 IS A
    LPC_IOCON->PIO0_8 |= 0x02;        // - set bit 1 to connect pin to CT16B0_MAT0
    LPC_IOCON->PIO0_8 &= ~(1 << 3);    // - clear bit 3 (and set 4: pull-up resistor)
    LPC_IOCON->PIO0_8 |= (1 << 4);    // - set bit 4

    // PIO0_9 IS C
    LPC_IOCON->PIO0_9 |= 0x02;        // - set bit 1 to connect pin to CT16B0_MAT1
    LPC_IOCON->PIO0_9 &= ~(1 << 3);    // - clear bit 3 (and set 4: pull-up resistor)
    LPC_IOCON->PIO0_9 |= (1 << 4);    // - set bit 4

    // 16 bit timer 1 - CT16B1
    // PIO1_9 IS B
    LPC_IOCON->PIO1_9 |= 0x01;        // - set bit 0 to connect pin to CT16B1_MAT0
    LPC_IOCON->PIO1_9 &= ~(1 << 3);    // - clear bit 3 (and set 4: pull-up resistor)
    LPC_IOCON->PIO1_9 |= (1 << 4);    // - set bit 4

    // PIO1_10 IS D
    LPC_IOCON->PIO1_10 |= 0x02;        // - set bit 1 to connect pin to CT16B1_MAT1
    LPC_IOCON->PIO1_10 &= ~(1 << 3);// - clear bit 3 (and set 4: pull-up resistor)
    LPC_IOCON->PIO1_10 |= (1 << 4);// - set bit 4

    LPC_TMR16B0->MCR |= (1 << 10);// Reset TC counter when it reaches Match Register 3 value
    LPC_TMR16B1->MCR |= (1 << 10);// Reset TC counter when it reaches Match Register 3 value

    LPC_TMR16B0->EMR |= 0x000000F0;// Toggle output when a match occurs with MR0 and MR1
    LPC_TMR16B1->EMR |= 0x000000F0;// Toggle output when a match occurs with MR0 and MR1

    LPC_TMR16B0->MR0 = 2048;// A duty cycle - TMR16B0 Match register 0
    LPC_TMR16B0->MR1 = 2048;            // C duty cycle - TMR16B0 Match register 1
    LPC_TMR16B0->MR3 = 4096;            // Cycle length 4096 (= 17.8kHz) - Match register 3

    LPC_TMR16B1->MR0 = 2048;            // B duty cycle - TMR16B1 Match register 0
    LPC_TMR16B1->MR1 = 2048;            // D duty cycle - TMR16B1 Match register 1
    LPC_TMR16B1->MR3 = 4096;            // Cycle length 4096 (= 17.8kHz) - Match register 3

    LPC_TMR16B0->PWMC |= (1 << 0);      // A    Timer 0 MAT0 is PWM
    LPC_TMR16B0->PWMC |= (1 << 1);      // C    Timer 0 MAT1 is PWM
    LPC_TMR16B1->PWMC |= (1 << 0);      // B    Timer 1 MAT0 is PWM
    LPC_TMR16B1->PWMC |= (1 << 1);      // D    Timer 1 MAT1 is PWM

    LPC_GPIO0->DIR |= (1 << 8);        // - select OUTPUT
    LPC_GPIO0->DIR |= (1 << 9);        // - select OUTPUT
    LPC_GPIO1->DIR |= (1 << 9);        // - select OUTPUT
    LPC_GPIO1->DIR |= (1 << 10);        // - select OUTPUT

    LPC_TMR16B0->TCR = 1;    //enable timer 0
    LPC_TMR16B1->TCR = 1;    //enable timer 1

while(1){}
}

Outcomes