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 ;
}