Forums

PWM revisited on 2103

Started by jaydavis95 October 25, 2010
I'm having a heckuva time getting a grip on PWM (I have reviewed all the related posts and other websites).

I am able to get the PWM to work, but ONLY on the ports shown in the code below.
(PO_13
P0_0
P0_8
P0_5)

but the motors do not respond at all on any other port
(for example P0_7 at the end of the code.)

Any help appreciated.

thanks,
Jay

//
// PWM seems to only work correctly on channel 1... but why???
//
#include
#include
#include
#include
#include
//#include "interrupts.h"
#include "uart.h"
#include "SerialPort.h"
#include "system.h"

#define XTALFREQ 12288000 //XTAL frequency in Hz
#define PCLKFREQ (XTALFREQ/4)

unsigned char ch1;

main()
{
FreqInit(); // Set processor Frequency

PINSEL0_bit.P0_13 = 2; // set P0.13 to PWM out Match 1.1 (Timer1) <<<< GOOD !!!!!!
T1PWMCON_bit.PWM1ENA = 1;

T1MR3 = PCLKFREQ/350; // 350MHz sq wave
T1MR1 = PCLKFREQ/10000; // duty cycle
T1MCR_bit.MR3RES = 1; //Reset on MR3 TC restet when match with MR3
T1TCR = 1;
// -------------------

PINSEL0_bit.P0_0 = 2; // set P0.0 to PWM out Match 3.1 (Timer3) <<< GOOD !!!!!!!
T3PWMCON_bit.PWM1ENA = 1;

T3MR3 = PCLKFREQ/350; // 350MHz sq wave
T3MR1 = PCLKFREQ/10000; // duty cycle
T3MCR_bit.MR3RES = 1; //Reset on MR3 TC restet when match with MR3
T3TCR = 1;
// -------------------

PINSEL0_bit.P0_8 = 2; // set P0.8 to PWM out Match 2.1 (Timer2) <<<<< GOOD !!!!!!
T2PWMCON_bit.PWM1ENA = 1;

T2MR3 = PCLKFREQ/350; // 350MHz sq wave
T2MR1 = PCLKFREQ/10000; // duty cycle
T2MCR_bit.MR3RES = 1; //Reset on MR3 TC restet when match with MR3
T2TCR = 1;

// -------------------
PINSEL0_bit.P0_5 = 2; // set P0.5 to PWM out. MATCH 0.1 (Timer0) <<<< GOOD !!!!!!
T0PWMCON_bit.PWM1ENA = 1;

T0MR3 = PCLKFREQ/350; // 350MHz sq wave
T0MR1 = PCLKFREQ/10000; // duty cycle
T0MCR_bit.MR3RES = 1; //Reset on MR3 TC restet when match with MR3
T0TCR = 1;
// ========================================================================== // ***************************** PROBLEM ******************************************
// ***************************** PROBLEM ******************************************
PINSEL0_bit.P0_7 = 2; // set P0.7 to PWM out. MATCH 2.0 (timer2) << no motor response
T2PWMCON_bit.PWM2ENA = 1;

T2MR3 = PCLKFREQ/350; // 350MHz sq wave
T2MR1 = PCLKFREQ/10000; // duty cycle
T2MCR_bit.MR3RES = 1; //Reset on MR3 TC restet when match with MR3
T2TCR = 1;
// ***************************** PROBLEM ******************************************
// ***************************** PROBLEM ******************************************

while(1) // main loop /
{

}
}

An Engineer's Guide to the LPC2100 Series

--- In l..., "jaydavis95" wrote:
>
> I'm having a heckuva time getting a grip on PWM (I have reviewed all the related posts and other websites).
>
> I am able to get the PWM to work, but ONLY on the ports shown in the code below.
> (PO_13
> P0_0
> P0_8
> P0_5)
>
> but the motors do not respond at all on any other port
> (for example P0_7 at the end of the code.)
>
> Any help appreciated.
>
> thanks,
> Jay
>

I have never been fond of these data structures that represent a simple register. In particular, I wonder why a ???_bit can be set to anything other than 0 or 1. But, I haven't seen the structure so I really have no idea how it works.

Then too, PINSELx is a read/write register so, to preserve previous settings, I tend to use a read-modify-write approach.

I might try something like:

PINSEL0 |= (2 << 0) || (2 << 10) || (2 << 16) || (2 << 26);

The bit-banding approach of the LPC17xx devices does not work for the LPC21xx family.

Richard

--- In l..., "rtstofer" wrote:
>
> --- In l..., "jaydavis95" wrote:
> >
> > I'm having a heckuva time getting a grip on PWM (I have reviewed all the related posts and other websites).
> >
> > I am able to get the PWM to work, but ONLY on the ports shown in the code below.
> > (PO_13
> > P0_0
> > P0_8
> > P0_5)
> >
> > but the motors do not respond at all on any other port
> > (for example P0_7 at the end of the code.)
> >
> > Any help appreciated.
> >
> > thanks,
> > Jay
> > I have never been fond of these data structures that represent a simple register. In particular, I wonder why a ???_bit can be set to anything other than 0 or 1. But, I haven't seen the structure so I really have no idea how it works.
>
> Then too, PINSELx is a read/write register so, to preserve previous settings, I tend to use a read-modify-write approach.
>
> I might try something like:
>
> PINSEL0 |= (2 << 0) || (2 << 10) || (2 << 16) || (2 << 26);
>
> The bit-banding approach of the LPC17xx devices does not work for the LPC21xx family.
>
> Richard
>

I knew when I typed that statement that I was using the wrong operator... Darn!

Better, since you have the code broken into blocks to do something like:

PINSEL0 |= (2 << 0); // for P0.0
PINSEL0 |= (2 << 10); // for P0.5
etc.

Richard

I don't know if this will help you shed any light, but I noticed that of all the ports that work they have ".1" in common

i.e. P0_13 is Match 1.1 (Timer 1)
P0_0 is Match 3.1 (Timer 3)
P0_8 is Match 2.1 (Timer 2)
P0_5 is Match 0.1 (Timer 0)

thanks again,
Jay

--- In l..., "rtstofer" wrote:
>
> --- In l..., "rtstofer" wrote:
> >
> >
> >
> > --- In l..., "jaydavis95" wrote:
> > >
> > > I'm having a heckuva time getting a grip on PWM (I have reviewed all the related posts and other websites).
> > >
> > > I am able to get the PWM to work, but ONLY on the ports shown in the code below.
> > > (PO_13
> > > P0_0
> > > P0_8
> > > P0_5)
> > >
> > > but the motors do not respond at all on any other port
> > > (for example P0_7 at the end of the code.)
> > >
> > > Any help appreciated.
> > >
> > > thanks,
> > > Jay
> > >
> >
> > I have never been fond of these data structures that represent a simple register. In particular, I wonder why a ???_bit can be set to anything other than 0 or 1. But, I haven't seen the structure so I really have no idea how it works.
> >
> > Then too, PINSELx is a read/write register so, to preserve previous settings, I tend to use a read-modify-write approach.
> >
> > I might try something like:
> >
> > PINSEL0 |= (2 << 0) || (2 << 10) || (2 << 16) || (2 << 26);
> >
> > The bit-banding approach of the LPC17xx devices does not work for the LPC21xx family.
> >
> > Richard
> > I knew when I typed that statement that I was using the wrong operator... Darn!
>
> Better, since you have the code broken into blocks to do something like:
>
> PINSEL0 |= (2 << 0); // for P0.0
> PINSEL0 |= (2 << 10); // for P0.5
> etc.
>
> Richard
>