lpcware

Timer as PWM on LPC1769

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by kabriolin on Tue Sep 24 02:13:54 MST 2013
Hi,

Currently developping a new release of an existing personnal board, i'm looking for reaplacing the current 3 uC by an LPC1769.

So I need 6 PWM at 50Hz, that's OK with the PWM module.
But I need 2 more PWM at 10KHz, I was expecting to use one of the Timer module.
Actually I can only create 2 square waves, change the frequency, but not the dutycycle.

I've use TIMER2, with MAT2.0 and MAT2.1 as channels, and MAT2.2 to reset as I did on LPC1347 on the first release.
But on GPIO0.6 and GPIO0.7, I can only see two beautiful squares, not really PWMs.

Is it any way to use a TIMER as PWM without using interrupts?

This is my Init code:

        /*By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
/* Bit 12~13 is for TIMER2 */
pclkdiv = (LPC_SC->PCLKSEL1 >> 12) & 0x03;
switch ( pclkdiv )
{
case 0x00:
default:
pclk = SystemCoreClock/4;
break;
case 0x01:
pclk = SystemCoreClock;
break;
case 0x02:
pclk = SystemCoreClock/2;
break;
case 0x03:
pclk = SystemCoreClock/8;
break;
}

LPC_PINCON->PINSEL0 |= (0x1<<12)|(0x1<<13); //P0.6 as MAT2.0
LPC_PINCON->PINSEL0 |= (0x1<<14)|(0x1<<15); //P0.7 as MAT2.1

LPC_TIM2->TCR = 2;//Reset counter

LPC_TIM2->IR = 0x0F;          /* Clear MATx interrupt include DMA request */

        LPC_TIM2->EMR |= (1<<0)|(1<<4)|(1<<5); //MAT2.0, toogle on reset
LPC_TIM2->EMR |= (1<<1)|(1<<6)|(1<<7); //MAT2.1, toogle on reset

LPC_TIM2->PR  = pclk/1000000; /* set prescaler to get 1 M counts/sec */

LPC_TIM2->MR0 = 5000;  /* Set up interval */
LPC_TIM2->MR1 = 3000;  /* Set up interval */

LPC_TIM2->MR2 = 10000; /* Set up interval */

LPC_TIM2->MCR = (0x1<<7);/* Reset on MR2 */

LPC_TIM2->TCR = 1;     //Start Timer
}


Thx

Outcomes