LPC11c24: The same settings for LPC_TIMER16_0 and LPC_TIMER16_1 sets different values.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC11c24: The same settings for LPC_TIMER16_0 and LPC_TIMER16_1 sets different values.

1,099 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hetii on Sat Jun 14 12:12:29 MST 2014
Hi.

I use such code to set two timer for PWM purpose to control LED brigthness.


static void t16b0_Init(){
int pr = SystemCoreClock / (4 * 1000000) - 1; //12 Mhz - 1 = 11 for prescale
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO0_9, (IOCON_FUNC2 | IOCON_MODE_PULLUP));//MAT1
// Initialize timers.
Chip_TIMER_Init(LPC_TIMER16_0);

// Configure Prescale
Chip_TIMER_PrescaleSet(LPC_TIMER16_0, pr);       //PR  = 11
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 2); //MCR = Reset on MR2
Chip_TIMER_SetMatch(LPC_TIMER16_0, 2, 255);      //MR2 = Period 255uS
Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, 1);        //MR1 = Duty cycles  set on 1
Chip_TIMER_CountWrite(LPC_TIMER16_0, (1<<1));    //PWMC - enable PWM signal on MAT1
Chip_TIMER_Enable(LPC_TIMER16_0);          //TCR  - and run...
}

static void t16b1_Init(){
int pr = SystemCoreClock / (4 * 1000000) - 1;
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_10, (IOCON_FUNC2 | IOCON_MODE_PULLUP));  //MAT1
// Initialize timers.
Chip_TIMER_Init(LPC_TIMER16_1);

// Configure Prescale
Chip_TIMER_PrescaleSet(LPC_TIMER16_1, pr);       //PR  = 11
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_1, 2); //MCR = Reset on MR2
Chip_TIMER_SetMatch(LPC_TIMER16_1, 2, 255);      //MR2 = Period 255uS
Chip_TIMER_SetMatch(LPC_TIMER16_1, 1, 1);        //MR1 = Duty cycles  set on 1
Chip_TIMER_CountWrite(LPC_TIMER16_1, (1<<1));    //PWMC - enable PWM signal on MAT1
Chip_TIMER_Enable(LPC_TIMER16_1);          //TCR  - and run...
}


As you can see in attached picuters, register are sets with different values, and my timer from LPC_TIMER16_1, don`t work till I set MCR to 0x80;

As I check the initial value for CT16B0 is 0x00 and for CT16B1 is 0x10.

Then API set MCR by |= operand, and because of that i got there different values.

#define _BIT(n) (1 << (n))
#define TIMER_INT_ON_MATCH(n)   (_BIT(((n) * 3)))

/**
 * @briefFor the specific match counter, enables reset of the terminal count register when a match occurs
 * @parampTMR: Pointer to timer IP register address
 * @parammatchnum: Match timer, 0 to 3
 * @returnNothing
 */
STATIC INLINE void Chip_TIMER_ResetOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum)
{
pTMR->MCR |= TIMER_RESET_ON_MATCH(matchnum);
}


Regards.
标签 (1)
0 项奖励
回复
0 回复数