lpcware

Generate 2 PWM from 1 timer

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by tyassin on Fri May 17 05:45:58 MST 2013
Hello,

I want to generate two PWM signals from one timer. I have tried to use Timer0, but nothing happens.
I use the LPC1114 Xpressoboard. I have attached my code.

LPC_TMR16B0->TCR = 0; //Disable Timer0
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); // System AHB clock control enable clock to timer 0 : 3.5.14
LPC_TMR16B0->EMR = (1<<0)|(1<<1)|(1<<3)|(1<<5)|(1<<7)|(1<<10); // Setup the external match register (1<<0 : EM0 connected to pin) : 18.7.10 External Match Register
// 1<<5 : Set the corresponding External Match bit/output to 1
// 1<<10 : Clear the corresponding External Match bit/output to 0 (CT16Bn_MATm pin is LOW if pinned out : (1<<3).

LPC_IOCON->PIO0_8 &= ~0x07; // Clears the FUNC bits : 8.4.23 IOCON_PIO0_8
LPC_IOCON->PIO0_8 |= 0x02; // Selects function CT16B0_MAT0. PIO0_8/MISO0/CT16B0_MAT0
LPC_IOCON->PIO0_9 &= ~0x07; // Clears the FUNC bits : 8.4.24 IOCON_PIO0_9
LPC_IOCON->PIO0_9 |= 0x02; // Selects function CT16B0_MAT1. PIO0_9/MOSI0/CT16B0_MAT1
// These are compared against the TC ( Timer Counter )
LPC_TMR16B0->MR3 = 1000; // Setup the match registers
LPC_TMR16B0->MR0 = 500; // Match Register 0 - stay low
LPC_TMR16B0->MR1 = 500;
LPC_TMR16B0->MCR = 1<<10; // OK : Match Control Register : 1<<10 = Reset on MR3
// If needed : 1<<9 = Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC.
LPC_TMR16B0->PWMC = 0b1011; // OK : PWM Control Register to enable the selected PWMs
// 0x01 : PWM mode is enabled for CT16Bn_MAT0
// 0x02 : PWM mode is enabled for CT16Bn_MAT1
// 0x08 : PWM mode is enabled for match channel 3

NVIC_EnableIRQ(TIMER_16_0_IRQn); // Enable the TIMER1 Interrupt
LPC_TMR16B0->TCR = 1; // Enable Timer16
Both GPIO0_8 and GPIO0_9 are high all the time.

If someone could see where it goes wrong i would be happy :-)

Thank you

Outcomes