Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

PWM with olimex lpc2106-mt pcb - how to?

PWM with olimex lpc2106-mt pcb - how to?

2004-07-20 by killtheclock

Hi all,

I have an olimex lpc2106-mt pcb and try to program a PWM without 
success. The Docu is not especially detailed (I think). I tried a lot 
of register settings(for hours). All I get is a single 88.64 ms pulse 
on PWM4 at reset that does not change with the match register or pre-
scaler value.

This code is one example that illustrates my understanding of that 
thing:
//testing PWM4
  PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
  PWM_PR  = 0x0000;    // max prescale counter value
  PWM_MCR = 0x0002;   // reset when PWMMR0 matches
  PWM_PCR = 0x1000;   // PWM4 enable, single edge
  PWM_MR0 = 0x0f00;    // match register trigger value
  PWM_TCR = 0x0009;    // set the TC counter and enable the PWMs

I would expect a 1.92 kHz frequency from that...
Obviously I do something completly wrong.

Any help is really apreciated

Cheers, Kurt.

Re: PWM with olimex lpc2106-mt pcb - how to?

2004-07-20 by Karl Olsen

--- In lpc2000@yahoogroups.com, "killtheclock" <kurt.westphal@g...> 
wrote:

> I have an olimex lpc2106-mt pcb and try to program a PWM without 
> success. The Docu is not especially detailed (I think). I tried a 
lot 
> of register settings(for hours). All I get is a single 88.64 ms 
pulse 
> on PWM4 at reset that does not change with the match register or 
pre-
> scaler value.
> 
> This code is one example that illustrates my understanding of that 
> thing:
> //testing PWM4
>   PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
>   PWM_PR  = 0x0000;    // max prescale counter value
>   PWM_MCR = 0x0002;   // reset when PWMMR0 matches
>   PWM_PCR = 0x1000;   // PWM4 enable, single edge
>   PWM_MR0 = 0x0f00;    // match register trigger value
>   PWM_TCR = 0x0009;    // set the TC counter and enable the PWMs
> 
> I would expect a 1.92 kHz frequency from that...
> Obviously I do something completly wrong.

You also need to set PWM_MR4, and then PWM_LER before the PWM_MRx 
values take effect.

Karl Olsen

Re: PWM with olimex lpc2106-mt pcb - how to?

2004-07-21 by killtheclock

I still can't get it running. Karl showed me the way to understand 
the docu - at least I felt like understanding it...
Current code status:

//testing PWM4
  PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
  
  PWM_PR  = 0x0000;    	// max prescale counter value
  PWM_MCR = 0x0002;   	// reset TC when PWMMR0 matches
  PWM_PCR = 0x7E00;   	// enable all PWM just to get the right one
  PWM_TCR = 0x000A;	// reset TC counter (not yet needed?!)
  
  PWM_MR0 = 0x0400;    	// match register 0 trigger value
  PWM_LER |= BIT0;
  
  PWM_MR4 = 0x0150;	// match register 4 trigger value
  PWM_LER |= BIT4;		
  
  PWM_TCR = 0x0009;    	// set the TC counter and enable the PWMs

But still getting the single 88.64 ms pulse.
Any idea?

Cheers, Kurt.


--- In lpc2000@yahoogroups.com, "Karl Olsen" <kro@p...> wrote:
> --- In lpc2000@yahoogroups.com, "killtheclock" <kurt.westphal@g...> 
> wrote:
> 
> > I have an olimex lpc2106-mt pcb and try to program a PWM without 
> > success. The Docu is not especially detailed (I think). I tried a 
> lot 
> > of register settings(for hours). All I get is a single 88.64 ms 
> pulse 
> > on PWM4 at reset that does not change with the match register or 
> pre-
> > scaler value.
> > 
> > This code is one example that illustrates my understanding of 
that 
Show quoted textHide quoted text
> > thing:
> > //testing PWM4
> >   PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
> >   PWM_PR  = 0x0000;    // max prescale counter value
> >   PWM_MCR = 0x0002;   // reset when PWMMR0 matches
> >   PWM_PCR = 0x1000;   // PWM4 enable, single edge
> >   PWM_MR0 = 0x0f00;    // match register trigger value
> >   PWM_TCR = 0x0009;    // set the TC counter and enable the PWMs
> > 
> > I would expect a 1.92 kHz frequency from that...
> > Obviously I do something completly wrong.
> 
> You also need to set PWM_MR4, and then PWM_LER before the PWM_MRx 
> values take effect.
> 
> Karl Olsen

Re: [lpc2000] Re: PWM with olimex lpc2106-mt pcb - how to?

2004-07-21 by microbit

> I still can't get it running. Karl showed me the way to understand 
> the docu - at least I felt like understanding it...
> Current code status:
> 
> //testing PWM4
>   PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
>   
>   PWM_PR  = 0x0000;          // max prescale counter value
>   PWM_MCR = 0x0002;         // reset TC when PWMMR0 matches
>   PWM_PCR = 0x7E00;         // enable all PWM just to get the right one
>   PWM_TCR = 0x000A;      // reset TC counter (not yet needed?!)
>   
>   PWM_MR0 = 0x0400;          // match register 0 trigger value
>   PWM_LER |= BIT0;
>   
>   PWM_MR4 = 0x0150;      // match register 4 trigger value
>   PWM_LER |= BIT4;            
>   
>   PWM_TCR = 0x0009;          // set the TC counter and enable the PWMs
> 
> But still getting the single 88.64 ms pulse.
> Any idea?
> 
> Cheers, Kurt.

Hi Kurt,

I think the main problem is that you have to wait until you get the Match _before_
the PWM cycle is actually written. This would explain why you only get a single pulse.

Follow this procedure I use :

/* Setting the PWM cycle */
/*******************/
PWMTCR = 0x0B;                // Hold TC in reset while altering Cycle
PWMMR0 = CYCLE;             // Write the new PWM period
PWMMCR = 0x01;               // Allow the INT flag for MR0
PWMTCR = 0x09;                // Restart PWM
PWMIR |= 0x01;                 // Reset MR0 Int flag
PWMLER = 0x01;                // Enable PWM0 latch
while ( ! (PWMIR & 0x01));  // Wait for match -> new cycle complete
PWMMCR = 0;                    // Disable MR0 Int flagging

/* Setting , for example, PWM5 */
/***********************/
PWMMR5 = DUTY;              // write duty cycle
PWMLER = 0x20;                // enable PWM5 Latch

Obviously CYCLE is the total PWM cycle and PERIOD makes the
PWM's dutycycle as = DUTY / CYCLE

So if you eg. set CYCLE to 1000 and DUTY to 150 you would get a 15% dutycycle
with a frequency of PCLK / 1000 (cycle), providing Prescaler is set to ONE (=0).

There might be better ways of doing this, but this way ensures you wait long enough 
for the PWM period cycle to update, but no longer than necessary......

B rgds and good luck,
Kris


[Non-text portions of this message have been removed]

Strange behavior on P0.02/P0.03

2004-07-21 by Curt Powell

We're seeing some strange pin behavior between an lpc2106 (on an Olimex
H2106 board) and a USB FIFO (DLPUSB245M).  I'm wondering if anyone has
any ideas.  When running a simple loopback test sending data from lpc to
FIFO, bits 2 and 3 (on P0.02 and P0.03) do not get set to 1 but on the
next byte sent they do (if they would be 1 on that byte).  

Example:  Sending a sequence of 16 bytes (values 0x00-0x0f) whenever bit
2 or 3 transitions from 0 to 1 (i.e. on 0x4, 0x8, 0xc) it is 0 but on
the next byte sent it is 1.  There is no issue with a 0 -> 1 transition.

        hex     bin    actual
Sending 0x00 00000000 00000000
Sending 0x01 00000001 00000001
Sending 0x02 00000010 00000010
Sending 0x03 00000011 00000011
Sending 0x04 00000100 00000000 <- bit 2 is 0, should be 1
Sending 0x05 00000101 00000101 <- bit 2 is 1 this time
Sending 0x06 00000110 00000110
Sending 0x07 00000111 00000111
Sending 0x08 00001000 00000000 <- bit 3 is 0, should be 1
Sending 0x09 00001001 00001001 <- bit 3 is 1 this time
Sending 0x0a 00001010 00001010
Sending 0x0b 00001011 00001011
Sending 0x0c 00001100 00001000 <- bit 2 is 0, should be 1
Sending 0x0d 00001101 00001101 <- bit 2 is 1 this time
Sending 0x0e 00001110 00001110
Sending 0x0f 00001111 00001111

This doesn't happen on any of the other 6 data pins.  We were thinking
it might have something to do with the alternate functions on
P0.02/P0.03 (I2C or timer 0) but we are not using those functions and in
fact are explicitly setting P0.02/P0.03 to GPIO at the beginning of the
program.

Any ideas?

TIA,

Curt

Re: [lpc2000] Strange behavior on P0.02/P0.03

2004-07-21 by microbit

Have you pulled those pins ?
Off-the-cuff from memory they're the I2C pins, and open drain.
From your sequence xample seems like you have moments where
the pull up fails, depending on the sequence

-- Kris

----- Original Message -----
From: "Curt Powell" <curt.powell@...>
To: <lpc2000@yahoogroups.com>
Sent: Thursday, July 22, 2004 7:17 AM
Subject: [lpc2000] Strange behavior on P0.02/P0.03


> We're seeing some strange pin behavior between an lpc2106 (on an Olimex
> H2106 board) and a USB FIFO (DLPUSB245M).  I'm wondering if anyone has
> any ideas.  When running a simple loopback test sending data from lpc to
> FIFO, bits 2 and 3 (on P0.02 and P0.03) do not get set to 1 but on the
> next byte sent they do (if they would be 1 on that byte).
>
> Example:  Sending a sequence of 16 bytes (values 0x00-0x0f) whenever bit
> 2 or 3 transitions from 0 to 1 (i.e. on 0x4, 0x8, 0xc) it is 0 but on
> the next byte sent it is 1.  There is no issue with a 0 -> 1 transition.
>
>         hex     bin    actual
> Sending 0x00 00000000 00000000
> Sending 0x01 00000001 00000001
> Sending 0x02 00000010 00000010
> Sending 0x03 00000011 00000011
> Sending 0x04 00000100 00000000 <- bit 2 is 0, should be 1
> Sending 0x05 00000101 00000101 <- bit 2 is 1 this time
> Sending 0x06 00000110 00000110
> Sending 0x07 00000111 00000111
> Sending 0x08 00001000 00000000 <- bit 3 is 0, should be 1
> Sending 0x09 00001001 00001001 <- bit 3 is 1 this time
> Sending 0x0a 00001010 00001010
> Sending 0x0b 00001011 00001011
> Sending 0x0c 00001100 00001000 <- bit 2 is 0, should be 1
> Sending 0x0d 00001101 00001101 <- bit 2 is 1 this time
> Sending 0x0e 00001110 00001110
> Sending 0x0f 00001111 00001111
>
> This doesn't happen on any of the other 6 data pins.  We were thinking
> it might have something to do with the alternate functions on
> P0.02/P0.03 (I2C or timer 0) but we are not using those functions and in
> fact are explicitly setting P0.02/P0.03 to GPIO at the beginning of the
> program.
>
> Any ideas?
>
> TIA,
>
> Curt
>
>
>
>       Yahoo! Groups Sponsor
>             ADVERTISEMENT
>
>
>
>
>
> --------------------------------------------------------------------------
------
Show quoted textHide quoted text
> Yahoo! Groups Links
>
>   a.. To visit your group on the web, go to:
>   http://groups.yahoo.com/group/lpc2000/
>
>   b.. To unsubscribe from this group, send an email to:
>   lpc2000-unsubscribe@yahoogroups.com
>
>   c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>

RE: [lpc2000] Strange behavior on P0.02/P0.03

2004-07-22 by Curt Powell

Yup.  Since we weren't using i2c we didn't read the part that said
they're open-drain outputs.  10K pull-ups did the trick...
Show quoted textHide quoted text
-----Original Message-----
From: microbit [mailto:microbit@...] 
Sent: Wednesday, July 21, 2004 2:41 PM
To: lpc2000@yahoogroups.com
Subject: Re: [lpc2000] Strange behavior on P0.02/P0.03


Have you pulled those pins ?
Off-the-cuff from memory they're the I2C pins, and open drain.
>From your sequence xample seems like you have moments where
the pull up fails, depending on the sequence

-- Kris

----- Original Message -----
From: "Curt Powell" <curt.powell@...>
To: <lpc2000@yahoogroups.com>
Sent: Thursday, July 22, 2004 7:17 AM
Subject: [lpc2000] Strange behavior on P0.02/P0.03


> We're seeing some strange pin behavior between an lpc2106 (on an
Olimex
> H2106 board) and a USB FIFO (DLPUSB245M).  I'm wondering if anyone has
> any ideas.  When running a simple loopback test sending data from lpc
to
> FIFO, bits 2 and 3 (on P0.02 and P0.03) do not get set to 1 but on the
> next byte sent they do (if they would be 1 on that byte).
>
> Example:  Sending a sequence of 16 bytes (values 0x00-0x0f) whenever
bit
> 2 or 3 transitions from 0 to 1 (i.e. on 0x4, 0x8, 0xc) it is 0 but on
> the next byte sent it is 1.  There is no issue with a 0 -> 1
transition.
>
>         hex     bin    actual
> Sending 0x00 00000000 00000000
> Sending 0x01 00000001 00000001
> Sending 0x02 00000010 00000010
> Sending 0x03 00000011 00000011
> Sending 0x04 00000100 00000000 <- bit 2 is 0, should be 1
> Sending 0x05 00000101 00000101 <- bit 2 is 1 this time
> Sending 0x06 00000110 00000110
> Sending 0x07 00000111 00000111
> Sending 0x08 00001000 00000000 <- bit 3 is 0, should be 1
> Sending 0x09 00001001 00001001 <- bit 3 is 1 this time
> Sending 0x0a 00001010 00001010
> Sending 0x0b 00001011 00001011
> Sending 0x0c 00001100 00001000 <- bit 2 is 0, should be 1
> Sending 0x0d 00001101 00001101 <- bit 2 is 1 this time
> Sending 0x0e 00001110 00001110
> Sending 0x0f 00001111 00001111
>
> This doesn't happen on any of the other 6 data pins.  We were thinking
> it might have something to do with the alternate functions on
> P0.02/P0.03 (I2C or timer 0) but we are not using those functions and
in
> fact are explicitly setting P0.02/P0.03 to GPIO at the beginning of
the
> program.
>
> Any ideas?
>
> TIA,
>
> Curt
>
>
>
>       Yahoo! Groups Sponsor
>             ADVERTISEMENT
>
>
>
>
>
>
------------------------------------------------------------------------
--
------
> Yahoo! Groups Links
>
>   a.. To visit your group on the web, go to:
>   http://groups.yahoo.com/group/lpc2000/
>
>   b.. To unsubscribe from this group, send an email to:
>   lpc2000-unsubscribe@yahoogroups.com
>
>   c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
>
>




 
Yahoo! Groups Links

Re: PWM with olimex lpc2106-mt pcb - how to?

2004-07-23 by killtheclock

Now I got it:
It is really simple. The only problem was that I inited P0.8 to be 
used as TxD UART 1, PINSEL P0.8 bits set to 01. Then in the main 
program I set the bits to 10.
  PINSEL0 |= 0x20000;
That resulted in both bits set for P0.8, wich is undefined and does 
not work.

This code does work:

        //setup PWM4
	PINSEL0 &= ~BIT16; // deselect pin 0.08 GPIO function
	PINSEL0 |= BIT17;  // select pin 0.08 PWM4 function
	PWM_PCR = BIT12;   //PWM4 enable, single edge
	PWM_PR  = 0x0000;  // max prescale counter value
	PWM_MR0 = 0x400;   // MR0 must be set prior to enabling 
                           // the PWM 
	PWM_MCR = 0x02;	   // enable reset on MR0
	PWM_TCR = 0x09;    // PWM enable and counter start
        PWM_MR4 = 0x0200;  // match register 4 trigger value
        PWM_LER |= 0x10;   // latch MR4

Kris, there is no need to poll the interrupt flag when you init MR0 
before enabling PWM mode. 
The docu says (UM_LPC2106_2105_2104_1.pdf, p.152, table 117): 

"Note that the PWM Match register that determines the PWM rate (PWM 
Match 0) must be set up prior to the PWM being enabled. Otherwise a 
Match event will not occur to cause shadow register contents to 
become effective."

Thank you Kris and Karl,
regards,
Kurt.

--- In lpc2000@yahoogroups.com, "microbit" <microbit@c...> wrote:
> > I still can't get it running. Karl showed me the way to 
understand 
> > the docu - at least I felt like understanding it...
> > Current code status:
> > 
> > //testing PWM4
> >   PINSEL0 |= 0x20000;   // select pin 0.08 PWM4 function
> >   
> >   PWM_PR  = 0x0000;          // max prescale counter value
> >   PWM_MCR = 0x0002;         // reset TC when PWMMR0 matches
> >   PWM_PCR = 0x7E00;         // enable all PWM just to get the 
right one
> >   PWM_TCR = 0x000A;      // reset TC counter (not yet needed?!)
> >   
> >   PWM_MR0 = 0x0400;          // match register 0 trigger value
> >   PWM_LER |= BIT0;
> >   
> >   PWM_MR4 = 0x0150;      // match register 4 trigger value
> >   PWM_LER |= BIT4;            
> >   
> >   PWM_TCR = 0x0009;          // set the TC counter and enable the 
PWMs
> > 
> > But still getting the single 88.64 ms pulse.
> > Any idea?
> > 
> > Cheers, Kurt.
> 
> Hi Kurt,
> 
> I think the main problem is that you have to wait until you get the 
Match _before_
> the PWM cycle is actually written. This would explain why you only 
get a single pulse.
> 
> Follow this procedure I use :
> 
> /* Setting the PWM cycle */
> /*******************/
> PWMTCR = 0x0B;                // Hold TC in reset while altering 
Cycle
> PWMMR0 = CYCLE;             // Write the new PWM period
> PWMMCR = 0x01;               // Allow the INT flag for MR0
> PWMTCR = 0x09;                // Restart PWM
> PWMIR |= 0x01;                 // Reset MR0 Int flag
> PWMLER = 0x01;                // Enable PWM0 latch
> while ( ! (PWMIR & 0x01));  // Wait for match -> new cycle complete
> PWMMCR = 0;                    // Disable MR0 Int flagging
> 
> /* Setting , for example, PWM5 */
> /***********************/
> PWMMR5 = DUTY;              // write duty cycle
> PWMLER = 0x20;                // enable PWM5 Latch
> 
> Obviously CYCLE is the total PWM cycle and PERIOD makes the
> PWM's dutycycle as = DUTY / CYCLE
> 
> So if you eg. set CYCLE to 1000 and DUTY to 150 you would get a 15% 
dutycycle
> with a frequency of PCLK / 1000 (cycle), providing Prescaler is set 
to ONE (=0).
> 
> There might be better ways of doing this, but this way ensures you 
wait long enough 
> for the PWM period cycle to update, but no longer than 
necessary......
Show quoted textHide quoted text
> 
> B rgds and good luck,
> Kris
> 
> 
> [Non-text portions of this message have been removed]

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.