// PWM output: 16bit_timer1 //init_timer16(1, 14399); // 14399 gives 5kHz with 72MHz clock. // Timer set up for 5KHz 20% DC PWM on MAT0 and // 2.5kHz toggling signal with phase offset at MAT1. // This is not for any specific application, just for testing. LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); // Enable clock to timer 1 //LPC_IOCON->PIO1_8 &= ~0x07; /* Timer1_16 I/O config */ //LPC_IOCON->PIO1_8 |= 0x01; /* Timer1_16 CAP0 - set bit 1*/ // default: 0xD0 = 0b11010000 (at boot) - after this: 0b11010001 - means MAT0 enabled + pull up + some undocumented bits. // Frankly there is no reason for pull-up on output. //LPC_IOCON->PIO1_9 &= ~0x07; // - remove bits 0,1 & 2 LPC_IOCON->PIO1_9 &= ~0x1F; // - remove bits 0,1 & 2 and pull resistors LPC_IOCON->PIO1_9 |= 0x01; /* Timer1_16 MAT0 */ //- set bit 1 //LPC_IOCON->PIO1_10 &= ~0x07; LPC_IOCON->PIO1_10 &= ~0x1F; // - remove bits 0,1 & 2 and pull resistors LPC_IOCON->PIO1_10 |= 0x02; /* Timer1_16 MAT1 */ /* Enable the TIMER1 Interrupt */ // NVIC_EnableIRQ(TIMER_16_1_IRQn); // No interrupt needed. LPC_TMR16B1->MCR = 0x0400; /* Reset at MR3*/ //LPC_TMR16B1->MCR |= 0x0400; /* MR1 setup*/ LPC_TMR16B1->MR0 = 11421; /* Match register 0 - Turn on time: 2879 = 20% duty cycle */ LPC_TMR16B1->MR1 = 7000; /* Match register 1 - no PWM - toggle test */ //LPC_TMR16B1->MR2 = 0; /* Match register 2 - not used */ LPC_TMR16B1->MR3 = 14399; /* Match register 3 - cycle length */ LPC_TMR16B1->EMR = 0xC2; /* External Match register Settings for PWM channel have no effect.*/ LPC_TMR16B1->PWMC = 0x01; /* PWMC register -MAT0 is PWM. */ // PIO1_9 = TC16B1_MAT0 GPIOSetDir( 1, 9, 1 ); // Set as output // PIO1_10 = TC16B1_MAT1 GPIOSetDir( 1, 10, 1 ); // set as output LPC_TMR16B1->TCR = 1; // Enable timer 1 |
[SIZE=2]void setPWM(void) { // PWM output: 16bit_timer1 // init_timer16(1, 14399); // 14399 gives 5kHz with 72MHz clock. // Timer set up for 5KHz 20% DC PWM on MAT0 and // 2.5kHz toggling signal with phase offset at MAT1. // This is not for any specific application, just for testing. LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); // Enable clock to timer 1 LPC_IOCON->PIO1_9 |= 0x01; /* Timer1_16 MAT0 */ //- set bit 1 /* Enable the TIMER1 Interrupt */ // NVIC_EnableIRQ(TIMER_16_1_IRQn); // No interrupt needed. LPC_TMR16B1->MCR = 0x0400; /* Reset at MR3*/ LPC_TMR16B1->MR0 = 11421; /* Match register 0 - Turn on time: 2879 = 20% duty cycle */ LPC_TMR16B1->MR3 = 14399; /* Match register 3 - cycle length */ LPC_TMR16B1->PWMC = 0x01; /* PWMC register -MAT0 is PWM. */ GPIOSetDir( 1, 9, 1 ); // Set as output LPC_TMR16B1->TCR = 1; // Enable timer 1 }[/SIZE] |