Discussion group dedicated to the Philips LPC2000 family of ARM MCUs
Using PWM on an LPC2101 - rfkd07 - Jul 29 8:32:22 2008
Hey there,
unfortunately I have quite some troubles when trying to use PWM on
pin P0.8 (MAT2.1) of my LPC2101 controller (without the use of
interrupts). The following code is what I have until now:
// Configure P0.8
PINSEL0 &= ~(3<<16);
PINSEL0 |= 2<<16;
T2TCR = 1<<1; // Reset TC and PC, disable timer
T2PR = 5; // Prescaling
T2MCR = 1<<10; // Reset on MR3 match
PWM0CON = 1<<3; // Use single edged PWM for MR3
T2EMR = 1<<1 | 3<<6; // Enable MAT2.1 and set toggle mode
// Setup PWM parameters
unsigned short cycles = 49152;
T2MR3 = cycles; // Period duration
T2MR1 = cycles/4; // Pulse width
T2TCR = 1<<0; // Enable counter
Prescaling and the value of the 'cycles' variable are computed
depending on the frequency, the values above are just examples for
F=200Hz (PCLK=58,982,400Hz). My problem is that the pulse remains
constantly high for 5ms, then constantly low for 5ms. Seems like MR1
is getting ignored. Any help available? Thanks in advance.
-rfkd07
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )
Re: Using PWM on an LPC2101 - wvanhoomissen - Jul 30 0:53:29 2008
A couple things to check:
PLL multipler (make sure ur clock speed is what you think)
Peripheral clock divider (R U dividing main clock by 2?)
--- In l...@yahoogroups.com, "rfkd07"
wrote:
>
> Hey there,
>
> unfortunately I have quite some troubles when trying to use PWM on
> pin P0.8 (MAT2.1) of my LPC2101 controller (without the use of
> interrupts). The following code is what I have until now:
>
> // Configure P0.8
> PINSEL0 &= ~(3<<16);
> PINSEL0 |= 2<<16;
>
> T2TCR = 1<<1; // Reset TC and PC, disable timer
> T2PR = 5; // Prescaling
> T2MCR = 1<<10; // Reset on MR3 match
> PWM0CON = 1<<3; // Use single edged PWM for MR3
> T2EMR = 1<<1 | 3<<6; // Enable MAT2.1 and set toggle mode
>
> // Setup PWM parameters
> unsigned short cycles = 49152;
> T2MR3 = cycles; // Period duration
> T2MR1 = cycles/4; // Pulse width
> T2TCR = 1<<0; // Enable counter
>
> Prescaling and the value of the 'cycles' variable are computed
> depending on the frequency, the values above are just examples for
> F=200Hz (PCLK=58,982,400Hz). My problem is that the pulse remains
> constantly high for 5ms, then constantly low for 5ms. Seems like MR1
> is getting ignored. Any help available? Thanks in advance.
>
> -rfkd07
>
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Using PWM on an LPC2101 - rfkd07 - Jul 30 1:12:41 2008
Thanks for your reply. The PLL is fine I think and my PCLK is running
at the same speed as CCLK (~58 MHz). System ticks based software
timers work perfectly so I think the problem must be somewhere else.
Any other ideas?
--- In l...@yahoogroups.com, "wvanhoomissen"
wrote:
>
> A couple things to check:
> PLL multipler (make sure ur clock speed is what you think)
> Peripheral clock divider (R U dividing main clock by 2?)
>
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Using PWM on an LPC2101 - ksdoubleshooter - Jul 30 12:25:44 2008
Remove the line setting up T2EMR and set up the RIGHT bit in the
RIGHT PWMCON register.
Jeff
--- In l...@yahoogroups.com, "rfkd07"
wrote:
>
> Hey there,
>
> unfortunately I have quite some troubles when trying to use PWM on
> pin P0.8 (MAT2.1) of my LPC2101 controller (without the use of
> interrupts). The following code is what I have until now:
>
> // Configure P0.8
> PINSEL0 &= ~(3<<16);
> PINSEL0 |= 2<<16;
>
> T2TCR = 1<<1; // Reset TC and PC, disable timer
> T2PR = 5; // Prescaling
> T2MCR = 1<<10; // Reset on MR3 match
> PWM0CON = 1<<3; // Use single edged PWM for MR3
> T2EMR = 1<<1 | 3<<6; // Enable MAT2.1 and set toggle mode
>
> // Setup PWM parameters
> unsigned short cycles = 49152;
> T2MR3 = cycles; // Period duration
> T2MR1 = cycles/4; // Pulse width
> T2TCR = 1<<0; // Enable counter
>
> Prescaling and the value of the 'cycles' variable are computed
> depending on the frequency, the values above are just examples for
> F=200Hz (PCLK=58,982,400Hz). My problem is that the pulse remains
> constantly high for 5ms, then constantly low for 5ms. Seems like MR1
> is getting ignored. Any help available? Thanks in advance.
>
> -rfkd07
>
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Using PWM on an LPC2101 - rfkd07 - Jul 31 1:40:46 2008
Thanks Jeff, that solved my problem. Stupid me.
--- In l...@yahoogroups.com, "ksdoubleshooter"
wrote:
>
> Remove the line setting up T2EMR and set up the RIGHT bit in the
> RIGHT PWMCON register.
>
> Jeff
>
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )