Back to all threads

LPC1343 and pwm

Post reply

shreyav22 
(1 posts)

Posted: 22 May 2012, 04:05

Hello everyone!
I have been trying to generate a pwm output using the code given below using the code base. However I do not get output when I connect the P1.9 to the oscilloscope. It builds without error but no output on debug.It would be great if anyone can help me find the problem. Thankyou.
static void timer16PWMInit()
{
  /* Enable the clock for CT16B1 */
  SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);

  /* Configure PIO1.9 as Timer1_16 MAT0 Output */
  IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK;
  IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0;  

  /* Set period (MR3) to 2ms */
  TMR_TMR16B1MR3 = TIMER16_CCLK_1MS * 2;

  /* Set Duty Cycle (MR0) to 50% */
  TMR_TMR16B1MR0 = TIMER16_CCLK_1MS * 1;

  /* Configure match control register to reset on MR3 */
  TMR_TMR16B1MCR = (TMR_TMR16B1MCR_MR3_RESET_ENABLED);

  /* External Match Register Settings for PWM */
  TMR_TMR16B1EMR = TMR_TMR16B1EMR_EMC0_TOGGLE | TMR_TMR16B1EMR_EM0;

  /* Enable PWM0 and PWM3 */
  TMR_TMR16B1PWMC = TMR_TMR16B1PWMC_PWM0_ENABLED | TMR_TMR16B1PWMC_PWM3_ENABLED;

  /* Enable Timer1 */
  TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED;
}




Reply

Xavier 
(3 posts)

Posted: 16 Sep 2012, 20:09

shreyav22 said:

Hello everyone!
I have been trying to generate a pwm output using the code given below using the code base. However I do not get output when I connect the P1.9 to the oscilloscope. It builds without error but no output on debug.It would be great if anyone can help me find the problem. Thankyou.
static void timer16PWMInit()
{
  /* Enable the clock for CT16B1 */
  SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);

  /* Configure PIO1.9 as Timer1_16 MAT0 Output */
  IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK;
  IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0;  

  /* Set period (MR3) to 2ms */
  TMR_TMR16B1MR3 = TIMER16_CCLK_1MS * 2;

  /* Set Duty Cycle (MR0) to 50% */
  TMR_TMR16B1MR0 = TIMER16_CCLK_1MS * 1;

  /* Configure match control register to reset on MR3 */
  TMR_TMR16B1MCR = (TMR_TMR16B1MCR_MR3_RESET_ENABLED);

  /* External Match Register Settings for PWM */
  TMR_TMR16B1EMR = TMR_TMR16B1EMR_EMC0_TOGGLE | TMR_TMR16B1EMR_EM0;

  /* Enable PWM0 and PWM3 */
  TMR_TMR16B1PWMC = TMR_TMR16B1PWMC_PWM0_ENABLED | TMR_TMR16B1PWMC_PWM3_ENABLED;

  /* Enable Timer1 */
  TMR_TMR16B1TCR = TMR_TMR16B1TCR_COUNTERENABLE_ENABLED;
}




I used this next code for PWM on LPC1114. Timer modules are similar to that on LPC1343:

void pwm_Init(LPC_TIMER_T * me, uint32_t frec)
{
LPC_SYSCON->SYSAHBCLKCTRL|=BIT(8);

LPC_IOCON->PIO1_9=(1)|(2<<3);

me->TCR=BIT(1);


me->MR3=frec;


me->MR0=frec/2;

me->MCR|=BIT(10);


me->PWMC|=BIT(0)|BIT(3);

me->TCR=BIT(0);
}

It's very similar to yours, but it compiles over LPCXpresso, and I used explicit constants instead #define(s). Don't worry about the 'me' pointer, it just points to the correct timer. 

Reply

Post reply