Hi ?,
> // Configure P0.8
> PINSEL0 &=3D ~(3<<16);
> PINSEL0 |=3D 2<<16;
>=20
> T2TCR =3D 1<<1; // Reset TC and PC, disable timer
> T2PR =3D 5; // Prescaling
> T2MCR =3D 1<<10; // Reset on MR3 match
> PWM0CON =3D 1<<3; // Use single edged PWM for MR3
> T2EMR =3D 1<<1 | 3<<6; // Enable MAT2.1 and set toggle mode
>=20
> // Setup PWM parameters
> unsigned short cycles =3D 49152;
> T2MR3 =3D cycles; // Period duration
> T2MR1 =3D cycles/4; // Pulse width
> T2TCR =3D 1<<0; // Enable counter
>=20
one line, two problems: :-)
> PWM0CON =3D 1<<3; // Use single edged PWM for MR3
You have to use PWM2CON instead of PWM0CON (which is for Timer0!).
And you want MAT2.1 to be a PWM output, not MAT2.3, so you have to set bit =
1 as in:
PWM2CON =3D 1 << 1; // Use single edged PWM for MR1
There is a typo in the User Manual: The PWM control registers for timers 2 =
and 3 are named PWM0CON and PWM1CON. Of course they need to be PWM2CON and =
PWM3CON. The register address is correct.
Probably your header file is ok, so in fact your setting controls Timer0 in=
stead of Timer2.
You don't have to set T2EMR for PWM mode, because it is ignored there. But =
since you don't enable PWM yet, it DOES have an effect (toggle every full c=
ycle).
This code works for me:
T2TCR =3D 2;
T2PR =3D 5;
T2MCR =3D 1 << 10; // MR3 will reset the timer
PWM2CON =3D 1 << 1; // MR1 controls MAT2.1 in PWM mode
T2MR3 =3D cycles-1;
T2MR1 =3D (cycles/4)-1;
T2TCR =3D 1;
Regards,
Rolf
----- Urspr=FCngliche Mail ----
Von: rfkd07
An: l...@yahoogroups.com
Gesendet: Dienstag, den 29. Juli 2008, 12:21:04 Uhr
Betreff: [lpc2000] Using PWM on an LPC2101
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 &=3D ~(3<<16);
PINSEL0 |=3D 2<<16;
T2TCR =3D 1<<1; // Reset TC and PC, disable timer
T2PR =3D 5; // Prescaling
T2MCR =3D 1<<10; // Reset on MR3 match
PWM0CON =3D 1<<3; // Use single edged PWM for MR3
T2EMR =3D 1<<1 | 3<<6; // Enable MAT2.1 and set toggle mode
// Setup PWM parameters
unsigned short cycles =3D 49152;
T2MR3 =3D cycles; // Period duration
T2MR1 =3D cycles/4; // Pulse width
T2TCR =3D 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=3D200Hz (PCLK=3D58,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
=20=20=20=20
__________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com
------------------------------------

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