Forums

Selecting PWM Function forcing output low by default?

Started by lpcphil November 1, 2006
Hi, I'm using the LPC213X and the PWM controller using PWM2 as a
double-edge controlled output. It seems that no matter what I do, as
soon as the GPIO pin (P0.7) is configured for PWM2, the output goes
hard low. This is very undesirable for my application. I need this
pin to stay high and I cannot seem to figure out if there is anyway to
prevent this from happening. The following code is an example of my
issue:

IO0SET = 0x80;
IO0DIR = 0x80; // at this point, my output is forced high
PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM function
// the line immediatly goes low

PWMPCR = 0x00000404; // double edge for PWM2
PWMPR = 0x00000000; // no prescale
PWMMR0 = 100; // just an example period and duty cycle
PWMMR1 = 40;
PWMMR2 = 10;
PWMMCR = 0x00000002; // continuous operation (no stop no interrupt)
PWMTCR = 0x02; // cnt reset
PWMTCR = 0x09; // start pwm

Now at this point, the PWM is as expected.

Thanks for the help
Philip

An Engineer's Guide to the LPC2100 Series

Hi Philip,

Am I right in thinking that you want the pin to go
directly from to without a
period of ?

If that is the case, why can't you just delay linking
the pin to the pwm module until after you have set up
the pwm module?
In other words move your
> PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM function
until after the line
> PWMTCR = 0x09; // start pwm

Hope this helps,
Danish
--- In l..., "lpcphil" wrote:
>
> Hi, I'm using the LPC213X and the PWM controller using PWM2 as a
> double-edge controlled output. It seems that no matter what I do, as
> soon as the GPIO pin (P0.7) is configured for PWM2, the output goes
> hard low. This is very undesirable for my application. I need this
> pin to stay high and I cannot seem to figure out if there is anyway to
> prevent this from happening. The following code is an example of my
> issue:
>
> IO0SET = 0x80;
> IO0DIR = 0x80; // at this point, my output is forced high
> PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM function
> // the line immediatly goes low
>
> PWMPCR = 0x00000404; // double edge for PWM2
> PWMPR = 0x00000000; // no prescale
> PWMMR0 = 100; // just an example period and duty cycle
> PWMMR1 = 40;
> PWMMR2 = 10;
> PWMMCR = 0x00000002; // continuous operation (no stop no interrupt)
> PWMTCR = 0x02; // cnt reset
> PWMTCR = 0x09; // start pwm
>
> Now at this point, the PWM is as expected.
>
> Thanks for the help
> Philip
>
Danish,

Thanks for the reply. As soon as the PINSEL command executes, the
IO line will drop to LOW. When the timer starts on the next
instruction, the line then jumps back up to HIGH. So you end up
getting a period where the signal is low before the PWM kicks in.
Moving it helps, but it still doesn't solve the problem unfortunatly.

If you have any other suggestions, I'm all ears.

Thanks,
Philip
--- In l..., "Danish Ali" wrote:
>
> Hi Philip,
>
> Am I right in thinking that you want the pin to go
> directly from to without a
> period of ?
>
> If that is the case, why can't you just delay linking
> the pin to the pwm module until after you have set up
> the pwm module?
> In other words move your
> > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
function
> until after the line
> > PWMTCR = 0x09; // start pwm
>
> Hope this helps,
> Danish
> --- In l..., "lpcphil" wrote:
> >
> > Hi, I'm using the LPC213X and the PWM controller using PWM2 as a
> > double-edge controlled output. It seems that no matter what I
do, as
> > soon as the GPIO pin (P0.7) is configured for PWM2, the output
goes
> > hard low. This is very undesirable for my application. I need
this
> > pin to stay high and I cannot seem to figure out if there is
anyway to
> > prevent this from happening. The following code is an example
of my
> > issue:
> >
> > IO0SET = 0x80;
> > IO0DIR = 0x80; // at this point, my output is forced high
> > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
function
> > // the line immediatly goes low
> >
> > PWMPCR = 0x00000404; // double edge for PWM2
> > PWMPR = 0x00000000; // no prescale
> > PWMMR0 = 100; // just an example period and duty cycle
> > PWMMR1 = 40;
> > PWMMR2 = 10;
> > PWMMCR = 0x00000002; // continuous operation (no stop no
interrupt)
> > PWMTCR = 0x02; // cnt reset
> > PWMTCR = 0x09; // start pwm
> >
> > Now at this point, the PWM is as expected.
> >
> > Thanks for the help
> > Philip
>
--- In l..., "lpcphil" wrote:
>
> Danish,
>
> Thanks for the reply. As soon as the PINSEL command executes, the
> IO line will drop to LOW. When the timer starts on the next
> instruction, the line then jumps back up to HIGH. So you end up
> getting a period where the signal is low before the PWM kicks in.

How long (about) is the low period ??

Can you maybe load the PWM counter with a value so the compare is
true ?

If necessary, an external gate and GPIO pin could keep it from
going low ?

boB

> Moving it helps, but it still doesn't solve the problem
unfortunatly.
>
> If you have any other suggestions, I'm all ears.
>
> Thanks,
> Philip
> --- In l..., "Danish Ali" wrote:
> >
> > Hi Philip,
> >
> > Am I right in thinking that you want the pin to go
> > directly from to without a
> > period of ?
> >
> > If that is the case, why can't you just delay linking
> > the pin to the pwm module until after you have set up
> > the pwm module?
> > In other words move your
> > > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
> function
> > until after the line
> > > PWMTCR = 0x09; // start pwm
> >
> > Hope this helps,
> > Danish
> > --- In l..., "lpcphil" wrote:
> > >
> > > Hi, I'm using the LPC213X and the PWM controller using PWM2 as
a
> > > double-edge controlled output. It seems that no matter what I
> do, as
> > > soon as the GPIO pin (P0.7) is configured for PWM2, the output
> goes
> > > hard low. This is very undesirable for my application. I need
> this
> > > pin to stay high and I cannot seem to figure out if there is
> anyway to
> > > prevent this from happening. The following code is an example
> of my
> > > issue:
> > >
> > > IO0SET = 0x80;
> > > IO0DIR = 0x80; // at this point, my output is forced high
> > > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
> function
> > > // the line immediatly goes low
> > >
> > > PWMPCR = 0x00000404; // double edge for PWM2
> > > PWMPR = 0x00000000; // no prescale
> > > PWMMR0 = 100; // just an example period and duty cycle
> > > PWMMR1 = 40;
> > > PWMMR2 = 10;
> > > PWMMCR = 0x00000002; // continuous operation (no stop no
> interrupt)
> > > PWMTCR = 0x02; // cnt reset
> > > PWMTCR = 0x09; // start pwm
> > >
> > > Now at this point, the PWM is as expected.
> > >
> > > Thanks for the help
> > > Philip
> > >
>
Hi Philip,

The behaviour you describe is not what I expected.
(Which is not to say that it is not true...)

I don't understand your description
> As soon as the PINSEL command executes, the
> IO line will drop to LOW. When the timer starts on the next
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> instruction, the line then jumps back up to HIGH.
^^^^^^^^^^^

Why does the timer start on the _next_ instruction?
I though I had asked for the PINSEL to be done after
all the setups for the PWM were complete. And so I ssumed
that the PWM was running correctly.

Perhaps the PWM does one full cycle of LOW before giving
the correct waveform.
So delay PINSEL until then:
Set up the PWM to reset and interrupt.
When you get the interrupt, you can assume that the PWM
output is running correctly, so only there do you do
the PINSEL. And since you don't need that interrupt again,
also reprogram the PWM so that it resets without interrupt.

Regards,
Danish
--- In l..., "lpcphil" wrote:
>
> Danish,
>
> Thanks for the reply. As soon as the PINSEL command executes, the
> IO line will drop to LOW. When the timer starts on the next
> instruction, the line then jumps back up to HIGH. So you end up
> getting a period where the signal is low before the PWM kicks in.
> Moving it helps, but it still doesn't solve the problem unfortunatly.
>
> If you have any other suggestions, I'm all ears.
>
> Thanks,
> Philip
> --- In l..., "Danish Ali" wrote:
> >
> > Hi Philip,
> >
> > Am I right in thinking that you want the pin to go
> > directly from to without a
> > period of ?
> >
> > If that is the case, why can't you just delay linking
> > the pin to the pwm module until after you have set up
> > the pwm module?
> > In other words move your
> > > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
> function
> > until after the line
> > > PWMTCR = 0x09; // start pwm
> >
> > Hope this helps,
> > Danish
> > --- In l..., "lpcphil" wrote:
> > >
> > > Hi, I'm using the LPC213X and the PWM controller using PWM2 as a
> > > double-edge controlled output. It seems that no matter what I
> do, as
> > > soon as the GPIO pin (P0.7) is configured for PWM2, the output
> goes
> > > hard low. This is very undesirable for my application. I need
> this
> > > pin to stay high and I cannot seem to figure out if there is
> anyway to
> > > prevent this from happening. The following code is an example
> of my
> > > issue:
> > >
> > > IO0SET = 0x80;
> > > IO0DIR = 0x80; // at this point, my output is forced high
> > > PINSEL0 = 0x00008000; // now, I convert the I/O pin to PWM
> function
> > > // the line immediatly goes low
> > >
> > > PWMPCR = 0x00000404; // double edge for PWM2
> > > PWMPR = 0x00000000; // no prescale
> > > PWMMR0 = 100; // just an example period and duty cycle
> > > PWMMR1 = 40;
> > > PWMMR2 = 10;
> > > PWMMCR = 0x00000002; // continuous operation (no stop no
> interrupt)
> > > PWMTCR = 0x02; // cnt reset
> > > PWMTCR = 0x09; // start pwm
> > >
> > > Now at this point, the PWM is as expected.
> > >
> > > Thanks for the help
> > > Philip
> > >
>