EmbeddedRelated.com
Forums

PWM - no output signal

Started by Henry September 19, 2011
Hello,

my intention is to control a fan using PWM1[4] of an LPC2468.
Therefore I configured P1.23 as PWM1[4]. MR0 controls the cycle length and PWM1 shall run in Single Edge Controlled Mode.
The timing is ok, I checked that by setting/resetting a GPIO pin in the interrupt handler.
The problem is that I don't get a signal at PWM1[4] (=P1.23). P1.23 is ok. when I configure it as an GPIO pin and toggle it.

This is my initialization code:

void InitPwm1( DWORD cycle ) {

PCONP |= (1 << 6); // default, PWM1 power/clock control bit.

//--- PCLK_SEL0 ---------------
PCLKSEL0 &= ~(3 << 12); // PWM1: PLCKSEL0[13:12] =00 --> CCLK /4

//--- Select PWM1[4] ---
PINSEL3 &= ~(3<<14);
PINSEL3 |= (2 << 14); // P1.23 becomes PWM1[4]

//--- Interrupts --------------
ctl_set_isr(8,8,CTL_ISR_TRIGGER_FIXED,Pwm1_IRQHandler,0);
ctl_unmask_isr(8); // VICIntEnable |= (1<<5);

//---Timer --------------------
PWM1TCR = TCR_RESET; // Counter Reset
PWM1PR = 0x00; // no prescaler, --> 18 pulses per 1s
PWM1CTCR = 0; // timer mode, (default)
//--- Match Regiser ----------
PWM1MCR = PWMMR0I | // interrupt on PWMMR0,
PWMMR0R // reset on PWMMR0, reset TC if PWM0 matches,
| PWMMR1I
;
PWM1MR0 = cycle; // cycle = 100*1000*18, i.e. 100ms

PWM1MR1 = cycle/2; // pulse length 50ms
--------------------------------
PWM1LER = LER0_EN | LER1_EN; // Latch Enable f MR0 (cycle length)
und MR1 (match register 1)

//--- PWM-Mode -------------------------------

PWM1PCR = PWMENA4; // 1 << 12, enable PWM1[4] f Single Edge Controlled Mode

//--- starten --------------------------------
PWM1TCR = TCR_PWM_EN |
TCR_CNT_EN; // enable PWM1 (= PWM mode) and start counter

}

An Engineer's Guide to the LPC2100 Series

I would suggest you try with ARMwizard http://alexan.edaboard.eu

This is an example of the PWM initialization code it can generate

/******************************************************************************
PWM1
*******************************************************************************
Counter Enabled, Counter Reset=0, PWM mode enabled
Timer mode: count on rising edge of PCLK
Counter clk: 15 MHz, Counts every: 66,67 ns (calculated with peripheral clock: 15MHz)
MCR1.0 : reset, generate interrupt on compare match
PWM frequency: 29,2969 KHz
PWM1: Single edge, set by MR0, reset by MR1, output enabled
PWM2: Single edge, set by MR0, reset by MR2, output disabled
PWM3: Single edge, set by MR0, reset by MR3, output disabled
PWM4: Single edge, set by MR0, reset by MR4, output disabled
PWM5: Single edge, set by MR0, reset by MR5, output disabled
PWM6: Single edge, set by MR0, reset by MR6, output disabled
*/
PWM1TC=0x00000000; /* decimal 0 */
PWM1PR=0x00000000; /* decimal 0 */
PWM1MCR=0x00000003; /* binary: 00000000_00000000_00000000_00000011 */
PWM1MR0=0x00000200; /* decimal 512 */
PWM1MR1=0x00000100; /* decimal 256 */
PWM1MR2=0x00000000; /* decimal 0 */
PWM1MR3=0x00000000; /* decimal 0 */
PWM1MR4=0x00000000; /* decimal 0 */
PWM1MR5=0x00000000; /* decimal 0 */
PWM1MR6=0x00000000; /* decimal 0 */
PWM1CTCR=0x00; /* binary: 00000000 */
PWM1CCR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
PWM1PCR=0x00000200; /* binary: 00000000_00000000_00000010_00000000 */
PWM1TCR=0x09; /* binary: 00001001 */

Alex

----- Original Message -----
From: Henry
To: l...
Sent: Monday, September 19, 2011 2:40 PM
Subject: [lpc2000] PWM - no output signal

Hello,

my intention is to control a fan using PWM1[4] of an LPC2468.
Therefore I configured P1.23 as PWM1[4]. MR0 controls the cycle length and PWM1 shall run in Single Edge Controlled Mode.
The timing is ok, I checked that by setting/resetting a different GPIO pin in the interrupt handler.
The problem is that I don't get a signal at PWM1[4] (=P1.23). P1.23 is ok. when I configure it as an GPIO pin and toggle it.

This is my initialization code:

void InitPwm1( DWORD cycle ) {

PCONP |= (1 << 6); // default, PWM1 power/clock control bit.

//--- PCLK_SEL0 ---------------
PCLKSEL0 &= ~(3 << 12); // PWM1: PLCKSEL0[13:12] --> CCLK /4

//--- Select PWM1[4] ---
PINSEL3 &= ~(3<<14);
PINSEL3 |= (2 << 14); // P1.23 becomes PWM1[4]

//--- Interrupts --------------
ctl_set_isr(8,8,CTL_ISR_TRIGGER_FIXED,Pwm1_IRQHandler,0);
ctl_unmask_isr(8); // VICIntEnable |= (1<<5);

//---Timer --------------------
PWM1TCR = TCR_RESET; // Counter Reset
PWM1PR = 0x00; // no prescaler, --> 18 pulses per 1s
PWM1CTCR = 0; // timer mode, (default)
//--- Match Regiser ----------
PWM1MCR = PWMMR0I | // interrupt on PWMMR0,
PWMMR0R // reset on PWMMR0, reset TC if PWM0 matches,
| PWMMR1I
;
PWM1MR0 = cycle; // cycle = 100*1000*18, i.e. 100ms

PWM1MR1 = cycle/2; // pulse length 50ms
--------------------------------
PWM1LER = LER0_EN | LER1_EN; // Latch Enable f MR0 (cycle length)
// and MR1 (match register 1)

//--- PWM-Mode ---------------
PWM1PCR = PWMENA4; // 1 << 12, enable PWM1[4](Single Edge Mode)

//--- starten ----------------
PWM1TCR = TCR_PWM_EN |
TCR_CNT_EN; // enable PWM1 (= PWM mode) and start counter

}

Does anybody have a glue what went wrong?
Your help would be appreciated very much.

Henry
Hello Alex,

the fault was that MR4 is "responsible" for PWM1[4], not MR1. I ignored that all the time. Perhaps one gets blind after a certain time of searching.
ARMwizard is a very good tool.
Thank you for your immediate response and help.

Henry

--- In l..., "Alexan_e" wrote:
>
> I would suggest you try with ARMwizard http://alexan.edaboard.eu
>
> This is an example of the PWM initialization code it can generate
>
> /******************************************************************************
> PWM1
> *******************************************************************************
> Counter Enabled, Counter Reset=0, PWM mode enabled
> Timer mode: count on rising edge of PCLK
> Counter clk: 15 MHz, Counts every: 66,67 ns (calculated with peripheral clock: 15MHz)
> MCR1.0 : reset, generate interrupt on compare match
> PWM frequency: 29,2969 KHz
> PWM1: Single edge, set by MR0, reset by MR1, output enabled
> PWM2: Single edge, set by MR0, reset by MR2, output disabled
> PWM3: Single edge, set by MR0, reset by MR3, output disabled
> PWM4: Single edge, set by MR0, reset by MR4, output disabled
> PWM5: Single edge, set by MR0, reset by MR5, output disabled
> PWM6: Single edge, set by MR0, reset by MR6, output disabled
> */
> PWM1TC=0x00000000; /* decimal 0 */
> PWM1PR=0x00000000; /* decimal 0 */
> PWM1MCR=0x00000003; /* binary: 00000000_00000000_00000000_00000011 */
> PWM1MR0=0x00000200; /* decimal 512 */
> PWM1MR1=0x00000100; /* decimal 256 */
> PWM1MR2=0x00000000; /* decimal 0 */
> PWM1MR3=0x00000000; /* decimal 0 */
> PWM1MR4=0x00000000; /* decimal 0 */
> PWM1MR5=0x00000000; /* decimal 0 */
> PWM1MR6=0x00000000; /* decimal 0 */
> PWM1CTCR=0x00; /* binary: 00000000 */
> PWM1CCR=0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
> PWM1PCR=0x00000200; /* binary: 00000000_00000000_00000010_00000000 */
> PWM1TCR=0x09; /* binary: 00001001 */
>
> Alex
>
> ----- Original Message -----
> From: Henry
> To: l...
> Sent: Monday, September 19, 2011 2:40 PM
> Subject: [lpc2000] PWM - no output signal
>
>
>
> Hello,
>
> my intention is to control a fan using PWM1[4] of an LPC2468.
> Therefore I configured P1.23 as PWM1[4]. MR0 controls the cycle length and PWM1 shall run in Single Edge Controlled Mode.
> The timing is ok, I checked that by setting/resetting a different GPIO pin in the interrupt handler.
> The problem is that I don't get a signal at PWM1[4] (=P1.23). P1.23 is ok. when I configure it as an GPIO pin and toggle it.
>
> This is my initialization code:
>
> void InitPwm1( DWORD cycle ) {
>
> PCONP |= (1 << 6); // default, PWM1 power/clock control bit.
>
> //--- PCLK_SEL0 ---------------
> PCLKSEL0 &= ~(3 << 12); // PWM1: PLCKSEL0[13:12] =00 --> CCLK /4
>
> //--- Select PWM1[4] ---
> PINSEL3 &= ~(3<<14);
> PINSEL3 |= (2 << 14); // P1.23 becomes PWM1[4]
>
> //--- Interrupts --------------
> ctl_set_isr(8,8,CTL_ISR_TRIGGER_FIXED,Pwm1_IRQHandler,0);
> ctl_unmask_isr(8); // VICIntEnable |= (1<<5);
>
> //---Timer --------------------
> PWM1TCR = TCR_RESET; // Counter Reset
> PWM1PR = 0x00; // no prescaler, --> 18 pulses per 1s
> PWM1CTCR = 0; // timer mode, (default)
> //--- Match Regiser ----------
> PWM1MCR = PWMMR0I | // interrupt on PWMMR0,
> PWMMR0R // reset on PWMMR0, reset TC if PWM0 matches,
> | PWMMR1I
> ;
> PWM1MR0 = cycle; // cycle = 100*1000*18, i.e. 100ms
>
> PWM1MR1 = cycle/2; // pulse length 50ms
> --------------------------------
> PWM1LER = LER0_EN | LER1_EN; // Latch Enable f MR0 (cycle length)
> // and MR1 (match register 1)
>
> //--- PWM-Mode ---------------
> PWM1PCR = PWMENA4; // 1 << 12, enable PWM1[4](Single Edge Mode)
>
> //--- starten ----------------
> PWM1TCR = TCR_PWM_EN |
> TCR_CNT_EN; // enable PWM1 (= PWM mode) and start counter
>
> }
>
> Does anybody have a glue what went wrong?
> Your help would be appreciated very much.
>
> Henry
>