Inverse PWMs

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

Inverse PWMs

1,818 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by magnetronus on Thu Aug 27 01:24:35 MST 2015
How can I do 2 inverse PWMs in the same timer?

I mean, for example, I configured CT32B0_MAT1 for counter reset, PWM mode is enabled for CT32B0_MAT0 and CT32B0_MAT3 with 50% duty-cycle (half period of MAT1).
CT32B0_MAT0 and CT32B0_MAT3 have the same waveform.
My question is, how can I get inverse waveform for CT32B0_MAT3 for example (anti-phase)?
0 Kudos
Reply
10 Replies

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 07:47:35 MST 2015
And with EMR your delay should disappear:

[img=640x480]https://www.lpcware.com/system/files/F0002TEK.JPG[/img]
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 06:14:10 MST 2015

Quote: lpcxpresso-support
If your part has an SCT (a.k.a. SCTimer) you might look into using that.



LPC1343  :D
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Aug 27 06:11:29 MST 2015
If your part has an SCT (a.k.a. SCTimer) you might look into using that.

There is the Red State tool in LPCXpresso to help configure it and the LPCOpen libraries have an API for some configurations.

Ciao,
LPCXpresso-Support
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 04:56:47 MST 2015
Another option (without interrupts) is to use PWM and toggle MATCH outputs via EMR.

Of course you have to preset MATCH outputs high / low (via EMR) before...

0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by magnetronus on Thu Aug 27 03:51:22 MST 2015
You right.
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 03:23:56 MST 2015
I'm not sure which toolchain and libraries you are using in detail (code snippets are not very informative  :(( ), but of course functions like GPIO_TestValue() and GPIO_SetValue() are damned slow and should be replaced...
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by magnetronus on Thu Aug 27 03:17:14 MST 2015
O'k.

I use LPCXpresso, my code optimize for size (-Os).
I use LPC1343 MCU.

Timer0 32bit initialization:

/* Enable the clock for CT32B0 */
LPC_SYSCON->SYSAHBCLKCTRL |= (0x01 << 9);

/* Selects function PIO1_6 */
LPC_IOCON->PIO1_6 &= ~0x07;

GPIO_SetDir(GPIO_PORT1, GPIO_BIT6, GPIO_DIR_OUT);
GPIO_SetValue(GPIO_PORT1, GPIO_BIT6, GPIO_LEVEL_LOW);

/* Selects function R_PIO0_11 */
LPC_IOCON->R_PIO0_11 &= ~0x07;
LPC_IOCON->R_PIO0_11 |= 0x01;

GPIO_SetDir(GPIO_PORT0, GPIO_BIT11, GPIO_DIR_OUT);
GPIO_SetValue(GPIO_PORT0, GPIO_BIT11, GPIO_LEVEL_HIGH);

                /* Set period */
                LPC_TMR[CT32B0]->MR[MAT1] = SysTick_GetPeriod(120000);    // 120 KHz
                
/* Set interrupt and reset on CT32B0_MAT1 */
LPC_TMR32B0->MCR = LPC_TIMER_MCR_MR1I | LPC_TIMER_MCR_MR1R;

/* Enable interrupt vector for 32-bit Timer 0 */
NVIC_EnableIRQ(TIMER_32_0_IRQn);


Interrupt (for GPIOs toggle):
if (LPC_TMR32B0->IR & LPC_TIMER_IR_MR1INT)
{
LPC_TMR32B0->IR |= LPC_TIMER_IR_MR1INT;/* clear interrupt flag */

volatile uint8_t math1_6 = GPIO_TestValue(GPIO_PORT1, GPIO_BIT6, GPIO_LEVEL_LOW) ? GPIO_LEVEL_HIGH : GPIO_LEVEL_LOW;
volatile uint8_t math0_11 = GPIO_TestValue(GPIO_PORT0, GPIO_BIT11, GPIO_LEVEL_LOW) ? GPIO_LEVEL_HIGH : GPIO_LEVEL_LOW;

                assert(math1_6 != math0_11);

GPIO_SetValue(GPIO_PORT1, GPIO_BIT6, math1_6);
GPIO_SetValue(GPIO_PORT0, GPIO_BIT11, math0_11);
}
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 02:56:11 MST 2015

Quote: magnetronus
...(because PIO1_6/MAT0 and R_PIO0_11/MAT3 use different ports).



:quest:

Sorry, can't follow you. Could be useful to post a sample (if we are talking about LPCXpresso) to show what you are doing in detail (optimization, inlining...) and which MCU you are using...


0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by magnetronus on Thu Aug 27 02:34:13 MST 2015
When I use interrupt (where I toggle GPIOs) I get undesirable time shift (because PIO1_6/MAT0 and R_PIO0_11/MAT3 use different ports).
See attached screenshot from scope.
0 Kudos
Reply

1,799 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu Aug 27 01:30:03 MST 2015
What about using interrupts?
0 Kudos
Reply