Yahoo Groups archive

Lpc2000

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

Message

Re: [lpc2000] PWM output

2006-02-25 by Herbert Demmel

Sten,

thank you for your valuable input. I've now changed the source code 
according to your comments and turned on power for PWM0 (although it should 
be on, the code below is the only code currently running) but it does not 
work yet.

I'm using a LPC2136 with Keil C V.2.42

Any further ideas why the stuff does not work???

Regards
Herbert

-------------

#include <LPC213x.H>                    /* LPC213x definitions  */

#define TICKS_PER_US            15

void io_alarm_out(unsigned int freq)
{
         PWMTCR = (0x01 << 0) | (0x01 << 1);      // Enter reset state and 
force counter to zero

         // match register 0 controls the cycle frequency
         PWMMR0 = 1000000 * TICKS_PER_US / freq;

         // we want to have a duty cycle of 50% so always set PWMMR5 to 
half of PWMMR0
         PWMMR5 = PWMMR0 / 2;

         // enable PWM5 output
         PWMPCR |= (0x01 << 13);

         PWMTCR = (0x01 << 0) | (0x01 << 3);      // Re-enable PWM
}

int main(void)
{
         // Turn on power control for PWM0
         PCONP |= (0x01 << 5);

         // --- PWM5 setup ---

         // Enable P0.21 to be PWM5
         PINSEL1 |= (0x01 << 10);
         // PWMTCR = 1;          // enable PWM timer, let shadow register 
disabled

         // reset PWM timer when PWMMR0 matches
         PWMMCR = 0x2;

         // gives 1000Hz
         io_alarm_out(1000);

         while (1)
                 ;
}
-------------

At 09:27 25.02.2006 +0100, you wrote:
>Sten wrote:
> > Herbert Demmel wrote:
> >
> >>Hi,
> >>
> >>I seem to miss something with setting up PWM5 output - the routine below
> >>sometimes works, sometimes not (depending non additional code - this
> >>versions below currentlly does NOT work).
> >>
> >>Any idea what I miss to setup?
> >>
> >>Thanks for your input.
> >>
> >>Regards
> >>Herbert
> >>
> >>#include <LPC213x.H>                    /* LPC213x definitions  */
> >>
> >>#define TICKS_PER_US            15
> >>
> >>void io_alarm_out(unsigned int freq)
> >>{
> >
> >
> >       PWMTCR = (1ul << 0) | (1ul << 1);      /* Enter reset state and 
> force counter to zero*/
> >
> >
> >>         // match register 0 controls the cycle frequency
> >>         PWMMR0 = 1000000 * TICKS_PER_US / freq;
> >>
> >>         // we want to have a duty cycle of 50% so always set PWMMR5 to
> >>half of PWMMR0
> >>         PWMMR5 = PWMMR0 / 2;
> >>
> >>         // enable PWM5 output
> >>         PWMPCR |= (0x01 << 13);
> >
> >
> >       PWMTCR = (1ul << 0) | (1ul << 3);      /* Re-enable PWM */
> >
> >
> >>}
> >>
> >>int main(void)
> >>{
> >>         // --- PWM5 setup ---
> >>
> >>         // Enable P0.21 to be PWM5
> >>         PINSEL1 |= (0x01 << 10);
> >>         PWMTCR = 1;             // enable PWM timer, let shadow register
> >>disabled
> >>
> >>         // reset PWM timer when PWMMR0 matches
> >
> >         //  PWMMCR = 0x2;
> >
> >>         // gives 1000Hz
> >>         io_alarm_out(1000);
> >>
> >>         while (1)
> >>                 ;
> >>}
> >>
> >
> >
> > Hallo Herbert,
> >
> > Mmmmh, don't you need to turn on PWM module in PCONP? Or do you let all 
> peripherials active on
> > startup by default?
> >
> > But bit #3 in PWMTCR enables PWM module. Description of this bit says:
> > "When one, PWM mode is enabled. PWM mode causes shadow registers..." 
> (2294's datasheet, p.233)
> >
> > After you have enabled PWM module (if bit #3 in PWMTCR is set) and set 
> up a value in a PWMMRx
> > register you just need to set the appropriated bit in PWMLER register 
> to take effect of new PWMMRx
> > value.
> >
> > You do not need using PWMLER register if you hold PWM in reset state 
> during changing PWMMRx values
> > (see changes above).
> >
> > Try it!
> >   Sten
> >
>
>Oooops, sorry! Do not comment PWMMCR in main(). But you can uncomment 
>PWMTCR statement instead.
>
>   Sten
>
>--
>/************************************************
>Do you need a tiny and efficient real time
>operating system (RTOS) with a preemtive
>multitasking for LPC2000 or AT91SAM7?
>
>    <http://nanortos.net-attack.de/>http://nanortos.net-attack.de/
>
>Or some open-source tools and code for LPC2000?
>
>    <http://www.net-attack.de/>http://www.net-attack.de/
>
>************************************************/
>
>
>SPONSORED LINKS
><http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=95&.sig=mfaAujKZXA2Z_vxre9sGnQ>Microcontrollers 
><http://groups.yahoo.com/gads?t=ms&k=Microprocessor&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=95&.sig=9jjd2D3GOLIESVQssLmLsA>Microprocessor 
><http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=95&.sig=OMnZuqMZX95mgutt4B-tDw>Intel 
>microprocessors
><http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s=95&.sig=Malspbd0T4Rq3M4Q0nHrfw>Pic 
>microcontrollers
>
>
>----------
>YAHOO! GROUPS LINKS
>
>    *  Visit your group "<http://groups.yahoo.com/group/lpc2000>lpc2000" 
> on the web.
>    *
>    *  To unsubscribe from this group, send an email to:
>    * 
> <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>lpc2000-unsubscribe@yahoogroups.com 
>
>    *
>    *  Your use of Yahoo! Groups is subject to the 
> <http://docs.yahoo.com/info/terms/>Yahoo! Terms of Service.
>
>
>----------

----------------------------------------------------------
demmel products
Radnitzkygasse 43
A-1100 Vienna / Austria / Europe
Voice: +43-1-6894700-0
Fax: +43-1-6894700-40
Email: dh@...
WWW: http://www.demmel.com


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

Attachments

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.