PWM for LPC1114

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

PWM for LPC1114

1,125 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tombond on Fri Mar 16 08:12:39 MST 2012
Hi,

I'm a student from germany and atm I'm doing a little project using the LPC1114/302. Therefore I need a 2730Hz 50% PWM.

Now what I did was:

LPC_SYSCON->SYSAHBCLKCTRL |=  (1<<8);             // Enable Clock for TMR1
LPC_IOCON->PIO1_9 |=  (1<<0);                     // PIN1_9 = CT16B1_MAT0
LPC_TMR16B1->MR0 = 2200;                          // 50% Duty Cycle
LPC_TMR16B1->MR3 = 4400;                          // Cycle Length
LPC_TMR16B1->MCR |= (1<<10);                      // TC Reset on MR3 Match
LPC_TMR16B1->PWMC |= (1<<0);                      // PWM Mode          
LPC_GPIO1->DIR |= (1<<9);                         // Output
LPC_TMR16B1->TCR |= (1<<0);                       // GO
but the Pin1_9 stays 3,3V without any changes.
Even LPC_TMR16B1->EMR &=     ~(1<<0); didn't change a thing, it still is high.
Does anybody know what I'm doing wrong?

EDIT: While debugging, I just found out that writing the IOCON->PIO1_9 isn't working. Any ideas?

Thanks,
Thomas
0 Kudos
Reply
4 Replies

1,074 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tombond on Fri Mar 16 09:37:09 MST 2012
Thanks again for the explanation.

I'm not using CMSIS because I use IBM Rational Rhapsody to create a UML model, the Strauss bridge by Willert and µVision from Keil. A professor here at my school gave me a short introduction to all this stuff but I have a really hard time getting into it. I copied my system_lpc11xx.c from a Keil demo project called "RTX_Blinky", so I don't know if it's possible to use CMSIS with µVision instead of LPCXpresso.
0 Kudos
Reply

1,074 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 16 09:22:11 MST 2012

Quote:

Do I have to set this bit to make changes in IOCON possible?

Yes

Usually CMSIS is doing that for you (therefore that's not mentioned in samples) in system_LPC11xx.c:
#define AHBCLKCTRL_Val        0x0001005F
...
LPC_SYSCON->SYSAHBCLKCTRL = AHBCLKCTRL_Val;
If you don't use CMSIS or set AHBCLKCTRL yourself, default value is used and bit 16 is reset :eek:
0 Kudos
Reply

1,074 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tombond on Fri Mar 16 09:05:25 MST 2012
Thank you very very much!
Enabling the IOCON bit solved the problem, but still I don't get why :D

Do I have to set this bit to make changes in IOCON possible?
I never thought of this because in aaaall the threads around here no one ever said anything about enabling this bit xD
Could you please explain to me why I had to do this?

Thanks for your time,
Thomas
0 Kudos
Reply

1,074 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 16 08:46:05 MST 2012
This part of your code is working

    LPC_SYSCON->SYSAHBCLKCTRL |=  (1<<8);             // Enable Clock for TMR1
    LPC_IOCON->PIO1_9 |=  (1<<0);                     // PIN1_9 = CT16B1_MAT0
    LPC_TMR16B1->MR0 = 2200;                          // 50% Duty Cycle
    LPC_TMR16B1->MR3 = 4400;                          // Cycle Length
    LPC_TMR16B1->MCR |= (1<<10);                      // TC Reset on MR3 Match
    LPC_TMR16B1->PWMC |= (1<<0);                      // PWM Mode
    LPC_TMR16B1->TCR |= (1<<0);                       // GO
and doing exactly what it should: generating 50%  10909 Hz PWM (at 48MHz).

If you don't see PIO1_9 changing, use your debugger to check all registers you've used. Probably you've changed some settings (SystemInit() ?) and now that's surprising you :eek:

Edit: If IOCON isn't working SYSAHBCLKCTRL  bit 16 (IOCON) is reset :rolleyes:
0 Kudos
Reply