Multiple PWM outputs?

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

Multiple PWM outputs?

854 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by avass on Wed Jan 02 23:56:08 MST 2013
Hi,

I would like to output two independent PWMs. For example, MAT0 outputing "0.1V" and MAT1 outputing "2.6V"...
I've been trying to use timer 0 using the init_timer16PWM / setMatch_timer16PWM functions outputing on 0_8/0_9 (MAT0/MAT1), but it looks like they are somehow interconnected. I am sure I don't know enough, I've been reading the docs, yet here I'm...

So far my code is :

LPC_TMR16B0->TCR = 0;//Disable Timer0

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);// System AHB clock control enable clock to timer 0

LPC_TMR16B0->EMR = (1<<EMC3)|(0<<EMC2)|(1<<EMC1)|(1<<EMC0)|(1<<3)|(MATCH0)|(MATCH1);// Setup the external match register
LPC_IOCON->PIO0_8 &= ~0x07;
LPC_IOCON->PIO0_8 |= 0x02;// Timer0_16 MAT0
LPC_IOCON->PIO0_9 &= ~0x07;
LPC_IOCON->PIO0_9 |= 0x02;// Timer0_16 MAT1
LPC_TMR16B0->MR3 = 1000;// Setup the match registers
LPC_TMR16B0->MR0 = 0;// Match Register 0
LPC_TMR16B0->MR1 = 0;
LPC_TMR16B0->MCR = 1<<10;// Match Control Register : Reset on MR3
LPC_TMR16B0->PWMC = (1<<3)|0x02|0x01;// PWM Control Register Enable the selected PWMs and enable Match3
NVIC_EnableIRQ(TIMER_16_0_IRQn);// Enable the TIMER1 Interrupt

LPC_TMR16B0->MR0 = 50;
LPC_TMR16B0->MR1 = 500;

LPC_TMR16B0->TCR = 1;// Enable Timer16

I thought this would output 50/1000*3.3V on 0_8 and 500/1000*3.3V on 0_9, yet I'm getting 1.5V and 2.90Vs...

Can somebody please help.

Thanks!
Labels (1)
0 Kudos
Reply
4 Replies

782 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Wed Jul 01 00:42:03 MST 2015

Quote: tjones
we're evaluating the LPC812 platform so I could benefit from the community's experience


Please don't hijack old threads, in particular not if they are in the subforum for a different controller.
0 Kudos
Reply

782 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jun 30 14:37:39 MST 2015

Quote: tjones
Will this be possible by, say, setting the period of one counter with a MATCH0 and the pulse with MATCH1-4?



Yes, that's the usual way to generate different PWM signals...
0 Kudos
Reply

783 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tjones on Tue Jun 30 14:30:29 MST 2015
Hello,

Please forgive the newbie question - we're evaluating the LPC812 platform so I could benefit from the community's experience.

I am trying to output 4 PWMs on the LPC812.  The period can be the identical on each PWM output but the pulse width must be independently modulated.   Will this be possible by, say, setting the period of one counter with a MATCH0 and the pulse with MATCH1-4?  Or some such?

Thanks in advance,
Tom
0 Kudos
Reply

783 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by avass on Thu Jan 03 02:19:37 MST 2013
Sorry, found it... Got confused a bit by the pinouts on the LPCXpresso board... MISO=MAT0 and MOSI=MAT1...
BTW, this one works well :

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 = 1001;// Match Register 0 - stay low
LPC_TMR16B0->MR1 = 1001;
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 = 0x08|0x02|0x01;// 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

LPC_TMR16B0->MR0 = 50;  // Test some values...
LPC_TMR16B0->MR1 = 950;
0 Kudos
Reply