PWM help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM help

853 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andrew24 on Mon Mar 15 08:36:07 MST 2010
HI,

I need help with my pwm. I do not know what is wrong with my program? Can anyboby help me? 
Maybe somebody knows any good codes, forums, tutorials for LPC13xx PWM? Thanks for your help.


#ifdef __USE_CMSIS
#include "LPC13xx.h"
#endif

  void initTimer32B0( void ) {
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10); //enable clock to Timer32B1

LPC_IOCON->JTAG_nTRST_PIO1_2 = (LPC_IOCON->JTAG_nTRST_PIO1_2 & ~0x7) | 0x3;//enable CT32B1_MAT1 ;

LPC_TMR32B1->MCR |= (0<<4)|(0<<5);     //

LPC_TMR32B1->TCR |= (0<<0)|(1<<1);     //reset counter
LPC_TMR32B1->PR = 0x00;      // prescale
LPC_TMR32B1->MCR = (1<<10)|(1<<9); //reset TC on MC3 match
LPC_TMR32B1->MR3 = 100;   //set period -
LPC_TMR32B1->MR1 = 50;   //set duty cycle
//LPC_TMR32B1->EMR = 0xC40;     // 0b110001000000
LPC_TMR32B1->PWMC = (0x01<<1) ;    //enable PWM on MAT1 output
LPC_TMR32B1->IR = 0x0F;//interrupt for all MATx
LPC_TMR32B1->EMR = 0xC40;     // 0b110001000000 
LPC_TMR32B1->TCR = 1;     //counter enable
  }

int main(void) {


// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
while(1) {
  i++ ;
}
return 0 ;
}
0 Kudos
Reply
2 Replies

810 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by brucesegal on Tue Mar 16 19:58:31 MST 2010
Change this:

LPC_TMR32B1->TCR |= (0<<0)|(1<<1); //reset counter
LPC_TMR32B1->PR = 0x00; // prescale

to this:

LPC_TMR32B1->TCR |= (0<<0)|(1<<1); //reset counter
LPC_TMR32B1->TCR = 0;  
LPC_TMR32B1->PR = 0x00; // prescale

The user guide states that the counter remain reset until TCR[1] is returned to zero. I'm guessing its more than just the TC and PR that are held reset but I haven't experimented to see exactly which other registers are affected. .
0 Kudos
Reply

810 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Brinkand on Tue Mar 16 00:50:14 MST 2010
I can't see any obvious problems in Your code, but guess You have a confict with the JTAG port. Can You use any of the other timers?

Compare with my code, which works:

http://knowledgebase.nxp.trimm.net/showthread.php?t=126
0 Kudos
Reply