Forums

LPC2366 PWM ~1uS low going glitch

Started by bobtransformer July 27, 2010
Hi guys...

In my timer0 interrupt, when I try to turn the PWM output back into
a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
low going glitch. Even if I read the pin first to make sure
I am not catching the PWM in the middle of a LOW portion of a
cycle first. The external circuitry does not want to see this short glitch.

Any thoughts ?? A better way maybe ?

Thanks,
boB

The PWM starts out running just fine, double edge PWM mode,
outputting on PWM2 and PWM5

Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference

if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
{
FIO1SET = (0x01 << 20); //P1.20 High
PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
}
Then, later I put it back to PWM mode after the pin has been high
a while. (I believe I even get a glitch once in a while doing
this)

PINSEL3 |= PIN_P1_20_PWM_1_2;

An Engineer's Guide to the LPC2100 Series

--- In l..., "alexander_ribero" wrote:
> Hi:
>
> What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
>
> Regards,
>
> Alex.

Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
sounded a wee bit fast for a pulldown resistor.

Next thing to try I think is to NOT actually change the
pin function to FGPIO but instead to keep it as PWM
and force the counter or compare value to make the PWM output
high... Then disable the PWM clock. Something like that.

Aside from that, I'm not aware of a bug or glitch that would
cause the pin to go low momentarily when changing pin functions...
(not saying it couldn't happen). But it's not every single time
that this low glitch happens.

I thought for sure that I was just changing from PWM to FGPIO
when PWM was in that low output state and cutting it short in
my timer0 interrupt, but, as long as the FIOxPIN command reads
the pin correctly, I should be OK I would think.
boB

>
> --- In l..., "bobtransformer" wrote:
> >
> > Hi guys...
> >
> > In my timer0 interrupt, when I try to turn the PWM output back into
> > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > low going glitch. Even if I read the pin first to make sure
> > I am not catching the PWM in the middle of a LOW portion of a
> > cycle first. The external circuitry does not want to see this short glitch.
> >
> > Any thoughts ?? A better way maybe ?
> >
> > Thanks,
> > boB
> >
> > The PWM starts out running just fine, double edge PWM mode,
> > outputting on PWM2 and PWM5
> >
> > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> >
> > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > {
> > FIO1SET = (0x01 << 20); //P1.20 High
> > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > }
> >
> >
> > Then, later I put it back to PWM mode after the pin has been high
> > a while. (I believe I even get a glitch once in a while doing
> > this)
> >
> > PINSEL3 |= PIN_P1_20_PWM_1_2;
>

Hi:

What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?

Regards,

Alex.

--- In l..., "bobtransformer" wrote:
>
> Hi guys...
>
> In my timer0 interrupt, when I try to turn the PWM output back into
> a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> low going glitch. Even if I read the pin first to make sure
> I am not catching the PWM in the middle of a LOW portion of a
> cycle first. The external circuitry does not want to see this short glitch.
>
> Any thoughts ?? A better way maybe ?
>
> Thanks,
> boB
>
> The PWM starts out running just fine, double edge PWM mode,
> outputting on PWM2 and PWM5
>
> Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
>
> if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> {
> FIO1SET = (0x01 << 20); //P1.20 High
> PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> }
> Then, later I put it back to PWM mode after the pin has been high
> a while. (I believe I even get a glitch once in a while doing
> this)
>
> PINSEL3 |= PIN_P1_20_PWM_1_2;
>

--- In l..., "bobtransformer" wrote:
>
> --- In l..., "alexander_ribero" wrote:
> >
> >
> > Hi:
> >
> > You're in the right track.
> >
> > I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.
> >
> > PWM1MR0 = PWM_CYCLE;
> > PWM1MR2 = PWM_CYCLE;
> > PWM1MR3 = PWM_CYCLE;
> > PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
> >
> >
> > Regards,
> >
> > Alex.
> Thanks Alex... That's exactly the sort of "or something like
> that" stuff I was looking for...
>
> However, when I try this, the PWM2 and PWM5 outputs go
> LOW rather than HIGH when I...
> PWM1MR4 = PWM_MAX;
> PWM1MR5 = PWM_MAX;
> PWM1LER = 0x30; //4 and 5 LER
>
> for PWM 5 (same thing for PWM 2)
> Maybe I am just off enough to be making this do the opposite
> of what I wanted it to do.
>
> Thanks,
> boB
>

Then again, maybe I have to select single edge rather than
double edge in PWMSELx to be able to SET the output latch...

boB

>
> > --- In l..., "bobtransformer" wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > --- In l..., "alexander_ribero" wrote:
> > > >
> > > >
> > > > Hi:
> > > >
> > > > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> > > >
> > > > Regards,
> > > >
> > > > Alex.
> > >
> > >
> > >
> > > Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> > > sounded a wee bit fast for a pulldown resistor.
> > >
> > > Next thing to try I think is to NOT actually change the
> > > pin function to FGPIO but instead to keep it as PWM
> > > and force the counter or compare value to make the PWM output
> > > high... Then disable the PWM clock. Something like that.
> > >
> > > Aside from that, I'm not aware of a bug or glitch that would
> > > cause the pin to go low momentarily when changing pin functions...
> > > (not saying it couldn't happen). But it's not every single time
> > > that this low glitch happens.
> > >
> > > I thought for sure that I was just changing from PWM to FGPIO
> > > when PWM was in that low output state and cutting it short in
> > > my timer0 interrupt, but, as long as the FIOxPIN command reads
> > > the pin correctly, I should be OK I would think.
> > >
> > >
> > > boB
> > >
> > >
> > >
> > >
> > > >
> > > > --- In l..., "bobtransformer" wrote:
> > > > >
> > > > > Hi guys...
> > > > >
> > > > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > > > low going glitch. Even if I read the pin first to make sure
> > > > > I am not catching the PWM in the middle of a LOW portion of a
> > > > > cycle first. The external circuitry does not want to see this short glitch.
> > > > >
> > > > > Any thoughts ?? A better way maybe ?
> > > > >
> > > > > Thanks,
> > > > > boB
> > > > >
> > > > > The PWM starts out running just fine, double edge PWM mode,
> > > > > outputting on PWM2 and PWM5
> > > > >
> > > > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > > > >
> > > > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > > > {
> > > > > FIO1SET = (0x01 << 20); //P1.20 High
> > > > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > > > }
> > > > >
> > > > >
> > > > > Then, later I put it back to PWM mode after the pin has been high
> > > > > a while. (I believe I even get a glitch once in a while doing
> > > > > this)
> > > > >
> > > > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > > > >
> > > >
> > >
>

--- In l..., "alexander_ribero" wrote:
>
> Hi:
>
> What about PWM1MR0?
>
> I believe you need to set it up too.
>
> Regards
>
> Alex.
I'm not sure I understand all I know about this, Alex :)

I was trying to set PWM5 and PWM2 separately, and so
I would do MR1 and MR2 for PWM2 and then
MR4 and MR5 for PWM5's output. Do you think I need
to set them all at the same time ?

I am using another PWM output in single edge mode for
an unrelated PWM output. (PWM3,4 or 6)

After looking at the schematic drawing of the PWM architecture,
it looked like in order to get the MRx = MR0 to set the outputs high, I needed to set PWM5 and PWM2 for single edge mode while
setting the match registers up. Does it look like that to you ?

I ~think~ it looks like it might be sort of doing what I want,
some times... No glitch but some other possible problems, which I
think might be the order in which I do the setting up and un-setting
up of those registers. But I'm not sure. It's definitely different from what I was doing before so I think you are sending me in the right direction. i.e. it looks like there is hope for this.

I have some extra protection against the PWM outputs going low for
longer than so many microseconds, (CPLD), and that protection is tripping and keeping me from running this for very long. I have to disable that I think to help debug this.

More work and staring at code and manuals tomorrow.

Thanks a mega-million ! I really appreciate the help.

boB

>
> --- In l..., "bobtransformer" wrote:
> >
> >
> >
> > --- In l..., "alexander_ribero" wrote:
> > >
> > >
> > > Hi:
> > >
> > > You're in the right track.
> > >
> > > I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.
> > >
> > > PWM1MR0 = PWM_CYCLE;
> > > PWM1MR2 = PWM_CYCLE;
> > > PWM1MR3 = PWM_CYCLE;
> > > PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
> > >
> > >
> > > Regards,
> > >
> > > Alex.
> >
> >
> > Thanks Alex... That's exactly the sort of "or something like
> > that" stuff I was looking for...
> >
> > However, when I try this, the PWM2 and PWM5 outputs go
> > LOW rather than HIGH when I...
> >
> >
> > PWM1MR4 = PWM_MAX;
> > PWM1MR5 = PWM_MAX;
> > PWM1LER = 0x30; //4 and 5 LER
> >
> > for PWM 5 (same thing for PWM 2)
> >
> >
> > Maybe I am just off enough to be making this do the opposite
> > of what I wanted it to do.
> >
> > Thanks,
> > boB
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > --- In l..., "bobtransformer" wrote:
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --- In l..., "alexander_ribero" wrote:
> > > > >
> > > > >
> > > > > Hi:
> > > > >
> > > > > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> > > > >
> > > > > Regards,
> > > > >
> > > > > Alex.
> > > >
> > > >
> > > >
> > > > Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> > > > sounded a wee bit fast for a pulldown resistor.
> > > >
> > > > Next thing to try I think is to NOT actually change the
> > > > pin function to FGPIO but instead to keep it as PWM
> > > > and force the counter or compare value to make the PWM output
> > > > high... Then disable the PWM clock. Something like that.
> > > >
> > > > Aside from that, I'm not aware of a bug or glitch that would
> > > > cause the pin to go low momentarily when changing pin functions...
> > > > (not saying it couldn't happen). But it's not every single time
> > > > that this low glitch happens.
> > > >
> > > > I thought for sure that I was just changing from PWM to FGPIO
> > > > when PWM was in that low output state and cutting it short in
> > > > my timer0 interrupt, but, as long as the FIOxPIN command reads
> > > > the pin correctly, I should be OK I would think.
> > > >
> > > >
> > > > boB
> > > >
> > > >
> > > >
> > > >
> > > > >
> > > > > --- In l..., "bobtransformer" wrote:
> > > > > >
> > > > > > Hi guys...
> > > > > >
> > > > > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > > > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > > > > low going glitch. Even if I read the pin first to make sure
> > > > > > I am not catching the PWM in the middle of a LOW portion of a
> > > > > > cycle first. The external circuitry does not want to see this short glitch.
> > > > > >
> > > > > > Any thoughts ?? A better way maybe ?
> > > > > >
> > > > > > Thanks,
> > > > > > boB
> > > > > >
> > > > > > The PWM starts out running just fine, double edge PWM mode,
> > > > > > outputting on PWM2 and PWM5
> > > > > >
> > > > > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > > > > >
> > > > > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > > > > {
> > > > > > FIO1SET = (0x01 << 20); //P1.20 High
> > > > > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > > > > }
> > > > > >
> > > > > >
> > > > > > Then, later I put it back to PWM mode after the pin has been high
> > > > > > a while. (I believe I even get a glitch once in a while doing
> > > > > > this)
> > > > > >
> > > > > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > > > > >
> > > > >
> > > >
> > >
>

Hi:

What about PWM1MR0?

I believe you need to set it up too.

Regards

Alex.

--- In l..., "bobtransformer" wrote:
>
> --- In l..., "alexander_ribero" wrote:
> >
> >
> > Hi:
> >
> > You're in the right track.
> >
> > I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.
> >
> > PWM1MR0 = PWM_CYCLE;
> > PWM1MR2 = PWM_CYCLE;
> > PWM1MR3 = PWM_CYCLE;
> > PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
> >
> >
> > Regards,
> >
> > Alex.
> Thanks Alex... That's exactly the sort of "or something like
> that" stuff I was looking for...
>
> However, when I try this, the PWM2 and PWM5 outputs go
> LOW rather than HIGH when I...
> PWM1MR4 = PWM_MAX;
> PWM1MR5 = PWM_MAX;
> PWM1LER = 0x30; //4 and 5 LER
>
> for PWM 5 (same thing for PWM 2)
> Maybe I am just off enough to be making this do the opposite
> of what I wanted it to do.
>
> Thanks,
> boB
> > --- In l..., "bobtransformer" wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > --- In l..., "alexander_ribero" wrote:
> > > >
> > > >
> > > > Hi:
> > > >
> > > > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> > > >
> > > > Regards,
> > > >
> > > > Alex.
> > >
> > >
> > >
> > > Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> > > sounded a wee bit fast for a pulldown resistor.
> > >
> > > Next thing to try I think is to NOT actually change the
> > > pin function to FGPIO but instead to keep it as PWM
> > > and force the counter or compare value to make the PWM output
> > > high... Then disable the PWM clock. Something like that.
> > >
> > > Aside from that, I'm not aware of a bug or glitch that would
> > > cause the pin to go low momentarily when changing pin functions...
> > > (not saying it couldn't happen). But it's not every single time
> > > that this low glitch happens.
> > >
> > > I thought for sure that I was just changing from PWM to FGPIO
> > > when PWM was in that low output state and cutting it short in
> > > my timer0 interrupt, but, as long as the FIOxPIN command reads
> > > the pin correctly, I should be OK I would think.
> > >
> > >
> > > boB
> > >
> > >
> > >
> > >
> > > >
> > > > --- In l..., "bobtransformer" wrote:
> > > > >
> > > > > Hi guys...
> > > > >
> > > > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > > > low going glitch. Even if I read the pin first to make sure
> > > > > I am not catching the PWM in the middle of a LOW portion of a
> > > > > cycle first. The external circuitry does not want to see this short glitch.
> > > > >
> > > > > Any thoughts ?? A better way maybe ?
> > > > >
> > > > > Thanks,
> > > > > boB
> > > > >
> > > > > The PWM starts out running just fine, double edge PWM mode,
> > > > > outputting on PWM2 and PWM5
> > > > >
> > > > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > > > >
> > > > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > > > {
> > > > > FIO1SET = (0x01 << 20); //P1.20 High
> > > > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > > > }
> > > > >
> > > > >
> > > > > Then, later I put it back to PWM mode after the pin has been high
> > > > > a while. (I believe I even get a glitch once in a while doing
> > > > > this)
> > > > >
> > > > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > > > >
> > > >
> > >
>

--- In l..., "bobtransformer" wrote:
>
> --- In l..., "alexander_ribero" wrote:
> >
> > Hi:
> >
> > What about PWM1MR0?
> >
> > I believe you need to set it up too.
> >
> > Regards
> >
> > Alex.
> I'm not sure I understand all I know about this, Alex :)
>
> I was trying to set PWM5 and PWM2 separately, and so
> I would do MR1 and MR2 for PWM2 and then
> MR4 and MR5 for PWM5's output. Do you think I need
> to set them all at the same time ?
For the record, I noticed that, for example, PWM5 gets its
SET from MR4 compare, but PWM5 gets its RESET from MR5
matching the counter, so when I set MR5 = PWM_MAX + some_number,
then it will NOT reset (at least not right away)...

Still more to go, but it's looking much better (there is hope).

boB

>
> I am using another PWM output in single edge mode for
> an unrelated PWM output. (PWM3,4 or 6)
>
> After looking at the schematic drawing of the PWM architecture,
> it looked like in order to get the MRx = MR0 to set the outputs high, I needed to set PWM5 and PWM2 for single edge mode while
> setting the match registers up. Does it look like that to you ?
>
> I ~think~ it looks like it might be sort of doing what I want,
> some times... No glitch but some other possible problems, which I
> think might be the order in which I do the setting up and un-setting
> up of those registers. But I'm not sure. It's definitely different from what I was doing before so I think you are sending me in the right direction. i.e. it looks like there is hope for this.
>
> I have some extra protection against the PWM outputs going low for
> longer than so many microseconds, (CPLD), and that protection is tripping and keeping me from running this for very long. I have to disable that I think to help debug this.
>
> More work and staring at code and manuals tomorrow.
>
> Thanks a mega-million ! I really appreciate the help.
>
> boB
>
> >
> > --- In l..., "bobtransformer" wrote:
> > >
> > >
> > >
> > > --- In l..., "alexander_ribero" wrote:
> > > >
> > > >
> > > > Hi:
> > > >
> > > > You're in the right track.
> > > >
> > > > I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.
> > > >
> > > > PWM1MR0 = PWM_CYCLE;
> > > > PWM1MR2 = PWM_CYCLE;
> > > > PWM1MR3 = PWM_CYCLE;
> > > > PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
> > > >
> > > >
> > > > Regards,
> > > >
> > > > Alex.
> > >
> > >
> > > Thanks Alex... That's exactly the sort of "or something like
> > > that" stuff I was looking for...
> > >
> > > However, when I try this, the PWM2 and PWM5 outputs go
> > > LOW rather than HIGH when I...
> > >
> > >
> > > PWM1MR4 = PWM_MAX;
> > > PWM1MR5 = PWM_MAX;
> > > PWM1LER = 0x30; //4 and 5 LER
> > >
> > > for PWM 5 (same thing for PWM 2)
> > >
> > >
> > > Maybe I am just off enough to be making this do the opposite
> > > of what I wanted it to do.
> > >
> > > Thanks,
> > > boB
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > > --- In l..., "bobtransformer" wrote:
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --- In l..., "alexander_ribero" wrote:
> > > > > >
> > > > > >
> > > > > > Hi:
> > > > > >
> > > > > > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> > > > > >
> > > > > > Regards,
> > > > > >
> > > > > > Alex.
> > > > >
> > > > >
> > > > >
> > > > > Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> > > > > sounded a wee bit fast for a pulldown resistor.
> > > > >
> > > > > Next thing to try I think is to NOT actually change the
> > > > > pin function to FGPIO but instead to keep it as PWM
> > > > > and force the counter or compare value to make the PWM output
> > > > > high... Then disable the PWM clock. Something like that.
> > > > >
> > > > > Aside from that, I'm not aware of a bug or glitch that would
> > > > > cause the pin to go low momentarily when changing pin functions...
> > > > > (not saying it couldn't happen). But it's not every single time
> > > > > that this low glitch happens.
> > > > >
> > > > > I thought for sure that I was just changing from PWM to FGPIO
> > > > > when PWM was in that low output state and cutting it short in
> > > > > my timer0 interrupt, but, as long as the FIOxPIN command reads
> > > > > the pin correctly, I should be OK I would think.
> > > > >
> > > > >
> > > > > boB
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > >
> > > > > > --- In l..., "bobtransformer" wrote:
> > > > > > >
> > > > > > > Hi guys...
> > > > > > >
> > > > > > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > > > > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > > > > > low going glitch. Even if I read the pin first to make sure
> > > > > > > I am not catching the PWM in the middle of a LOW portion of a
> > > > > > > cycle first. The external circuitry does not want to see this short glitch.
> > > > > > >
> > > > > > > Any thoughts ?? A better way maybe ?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > boB
> > > > > > >
> > > > > > > The PWM starts out running just fine, double edge PWM mode,
> > > > > > > outputting on PWM2 and PWM5
> > > > > > >
> > > > > > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > > > > > >
> > > > > > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > > > > > {
> > > > > > > FIO1SET = (0x01 << 20); //P1.20 High
> > > > > > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > > Then, later I put it back to PWM mode after the pin has been high
> > > > > > > a while. (I believe I even get a glitch once in a while doing
> > > > > > > this)
> > > > > > >
> > > > > > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
>

Hi:

You're in the right track.

I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.

PWM1MR0 = PWM_CYCLE;
PWM1MR2 = PWM_CYCLE;
PWM1MR3 = PWM_CYCLE;
PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
Regards,

Alex.
--- In l..., "bobtransformer" wrote:
> --- In l..., "alexander_ribero" wrote:
> >
> >
> > Hi:
> >
> > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> >
> > Regards,
> >
> > Alex.
>
> Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> sounded a wee bit fast for a pulldown resistor.
>
> Next thing to try I think is to NOT actually change the
> pin function to FGPIO but instead to keep it as PWM
> and force the counter or compare value to make the PWM output
> high... Then disable the PWM clock. Something like that.
>
> Aside from that, I'm not aware of a bug or glitch that would
> cause the pin to go low momentarily when changing pin functions...
> (not saying it couldn't happen). But it's not every single time
> that this low glitch happens.
>
> I thought for sure that I was just changing from PWM to FGPIO
> when PWM was in that low output state and cutting it short in
> my timer0 interrupt, but, as long as the FIOxPIN command reads
> the pin correctly, I should be OK I would think.
> boB
> >
> > --- In l..., "bobtransformer" wrote:
> > >
> > > Hi guys...
> > >
> > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > low going glitch. Even if I read the pin first to make sure
> > > I am not catching the PWM in the middle of a LOW portion of a
> > > cycle first. The external circuitry does not want to see this short glitch.
> > >
> > > Any thoughts ?? A better way maybe ?
> > >
> > > Thanks,
> > > boB
> > >
> > > The PWM starts out running just fine, double edge PWM mode,
> > > outputting on PWM2 and PWM5
> > >
> > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > >
> > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > {
> > > FIO1SET = (0x01 << 20); //P1.20 High
> > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > }
> > >
> > >
> > > Then, later I put it back to PWM mode after the pin has been high
> > > a while. (I believe I even get a glitch once in a while doing
> > > this)
> > >
> > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > >
>

--- In l..., "alexander_ribero" wrote:
> Hi:
>
> You're in the right track.
>
> I just recalled that in my LPC2366 project, I had to stop the PWM module, not by setting the Counter Enable bit in the PWM1TCR to 0, but by setting all the Match registers to maximum (to what the PWM1MR0 is set) AND setting the PWM Latch Enable register bits as well, to assure that the PWM stop always at a HIGH level.
>
> PWM1MR0 = PWM_CYCLE;
> PWM1MR2 = PWM_CYCLE;
> PWM1MR3 = PWM_CYCLE;
> PWM1LER = LER0_EN | LER2_EN | LER3_EN ;
> Regards,
>
> Alex.
Thanks Alex... That's exactly the sort of "or something like
that" stuff I was looking for...

However, when I try this, the PWM2 and PWM5 outputs go
LOW rather than HIGH when I...
PWM1MR4 = PWM_MAX;
PWM1MR5 = PWM_MAX;
PWM1LER = 0x30; //4 and 5 LER

for PWM 5 (same thing for PWM 2)
Maybe I am just off enough to be making this do the opposite
of what I wanted it to do.

Thanks,
boB

> --- In l..., "bobtransformer" wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> > --- In l..., "alexander_ribero" wrote:
> > >
> > >
> > > Hi:
> > >
> > > What is the PINMODE setting for the GPIO pin you are using? Maybe you have the pull-down resistor enabled, and there is a moment (the 1us) between switching the pin from PWM to GPIO, and then setting it high?
> > >
> > > Regards,
> > >
> > > Alex.
> >
> >
> >
> > Thanks Alex. What a great suggestion ! Looks like all my PINMODEs are set to 00 (pull up enabled) though. I thought that 1 microsecond
> > sounded a wee bit fast for a pulldown resistor.
> >
> > Next thing to try I think is to NOT actually change the
> > pin function to FGPIO but instead to keep it as PWM
> > and force the counter or compare value to make the PWM output
> > high... Then disable the PWM clock. Something like that.
> >
> > Aside from that, I'm not aware of a bug or glitch that would
> > cause the pin to go low momentarily when changing pin functions...
> > (not saying it couldn't happen). But it's not every single time
> > that this low glitch happens.
> >
> > I thought for sure that I was just changing from PWM to FGPIO
> > when PWM was in that low output state and cutting it short in
> > my timer0 interrupt, but, as long as the FIOxPIN command reads
> > the pin correctly, I should be OK I would think.
> >
> >
> > boB
> >
> >
> >
> >
> > >
> > > --- In l..., "bobtransformer" wrote:
> > > >
> > > > Hi guys...
> > > >
> > > > In my timer0 interrupt, when I try to turn the PWM output back into
> > > > a GPIO (Fast GPIO) and set it high, I sometimes get a 1 microsecond
> > > > low going glitch. Even if I read the pin first to make sure
> > > > I am not catching the PWM in the middle of a LOW portion of a
> > > > cycle first. The external circuitry does not want to see this short glitch.
> > > >
> > > > Any thoughts ?? A better way maybe ?
> > > >
> > > > Thanks,
> > > > boB
> > > >
> > > > The PWM starts out running just fine, double edge PWM mode,
> > > > outputting on PWM2 and PWM5
> > > >
> > > > Here I set the pin high IF it is high already to try to avoid catching the PWM in a low going part of the cycle. I don't think the order of these operations made any difference
> > > >
> > > > if(FIO1PIN & (0x01 << 20) ) //Wait until high (did not help)
> > > > {
> > > > FIO1SET = (0x01 << 20); //P1.20 High
> > > > PINSEL3 &= 0xfcff; // ~(0x0300) GPIO
> > > > }
> > > >
> > > >
> > > > Then, later I put it back to PWM mode after the pin has been high
> > > > a while. (I believe I even get a glitch once in a while doing
> > > > this)
> > > >
> > > > PINSEL3 |= PIN_P1_20_PWM_1_2;
> > > >
> > >
>