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) { // 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); } 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) ; } ---------------------- demmel products Radnitzkygasse 43 A-1100 Vienna / Austria / Europe Voice: +43-1-6894700-0 Fax: +43-1-6894700-40 Email: dh@dh@.... WWW: http://www.demmel.com
PWM output
Started by ●February 24, 2006
Reply by ●February 25, 20062006-02-25
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 -- /************************************************ 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/ Or some open-source tools and code for LPC2000? http://www.net-attack.de/ ************************************************/
Reply by ●February 25, 20062006-02-25
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/ Or some open-source tools and code for LPC2000? http://www.net-attack.de/ ************************************************/
Reply by ●February 25, 20062006-02-25
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/" target="_blank" rel="nofollow">http://nanortos.net-attack.de/>http://nanortos.net-attack.de/ > >Or some open-source tools and code for LPC2000? > > <http://www.net-attack.de/" target="_blank" rel="nofollow">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&.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&.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&.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&.sig=Malspbd0T4Rq3M4Q0nHrfw>Pic >microcontrollers > > >---------- >>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@dh@.... WWW: http://www.demmel.com
Reply by ●February 25, 20062006-02-25
Sten, Sorry, the code now works, I just forgot to enable the "Run application after download" in my test program, so the test program never started (my original application did and had the problem not to start the PWM). Thanks a lot Herbert At 12:53 25.02.2006 +0100, you wrote: >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/" target="_blank" rel="nofollow">http://nanortos.net-attack.de/>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/" target="_blank" rel="nofollow">http://www.net-attack.de/>http://www.net-attack.de/>http://www.net-attack.de/ > > > >************************************************/ > > > > > >SPONSORED LINKS > ><<http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1=Microcontroller > s&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=mfaAujKZXA2Z_vxre9sGnQ>http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.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&.sig=9jjd2D3GOLIESVQssLmLsA>http://groups.yahoo.com/gads?t=ms&k=Microprocessor&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=9jjd2D3GOLIESVQssLmLsA>Microprocessor > > ><<http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1=Microcontr > ollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=OMnZuqMZX95mgutt4B-tDw>http://groups.yahoo.com/gads?t=ms&k=Intel+microprocessors&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=OMnZuqMZX95mgutt4B-tDw>Intel > > >microprocessors > ><<http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1=Microcontro > llers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=Malspbd0T4Rq3M4Q0nHrfw>http://groups.yahoo.com/gads?t=ms&k=Pic+microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.sig=Malspbd0T4Rq3M4Q0nHrfw>Pic > > >microcontrollers > > > > > >---------- > >>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@dh@.... >WWW: <http://www.demmel.com" target="_blank" rel="nofollow">http://www.demmel.com>http://www.demmel.com > > > > > > >SPONSORED LINKS ><http://groups.yahoo.com/gads?t=ms&k=Microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel+microprocessors&w4=Pic+microcontrollers&c=4&s&.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&.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&.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&.sig=Malspbd0T4Rq3M4Q0nHrfw>Pic >microcontrollers > > >---------- >>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@dh@.... WWW: http://www.demmel.com