void SENT_init(void) { /* reset flags */ timeout_flag = false; Chip_GPIO_SetPinDIRInput(LPC_GPIO, 1, 6); Chip_SCT_Init(LPC_SCT0); Chip_SCT_Config(LPC_SCT0, (SCT_CONFIG_32BIT_COUNTER)); //use a unified counter LPC_SCT0->COUNT_U = 0;//set counter to 0 LPC_SCT0->EVEN = 0x01;//enable event 0 LPC_SCT0->REGMODE |= (1 << 0);//register 0 is a capture register LPC_SCT0->CAPCTRL[0].U |= (1 << 0);//event 0 causes capture 0 LPC_SCT0->EVENT[0].STATE = 0xFFFFFFFF;//happens in every state LPC_SCT0->EVENT[0].CTRL = (0 << 0) | //use capture register 0 (0x2 << 10) |//detect falling edges (0x2 << 12) |//use I/O condition only (1 << 14) |//STATEV is loaded (0 << 15);//new state: 0 Chip_INMUX_SelectSCT0Src(0, SCT0_INMUX_PIO1_6); Chip_SCT_EnableEventInt(LPC_SCT0, SCT_EVT_0); /* Enable an Interrupt on the Capture Event */ NVIC_EnableIRQ(SCT0_IRQn); timerFreq = Chip_Clock_GetSysTickClockRate(); NVIC_SetPriority(SENT_TIMER_NVIC_NAME, SENT_TIMER_INTERRUPT_PRIORITY); // interrupt priority Chip_SCT_ClearControl(LPC_SCT0, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);//start counter } |
void SENT_TIMER_TIMER_IRQ_HANDLER(void) { if (LPC_SCT0->EVFLAG & 0x01) { LPC_SCT0->EVFLAG = 0x01;//Clear interrupt flag /* read timer counter */ newCapValue = LPC_SCT0->CAP[0].U; sentDelay = newCapValue - oldCapValue; oldCapValue = newCapValue; } } |
/* Use main oscilator for rates above 100Kh */ Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRCA_SYSOSC); |
Hi,
How can you find the no of revolutions using capture register?
Chip_GPIO_SetPinDIRInput(LPC_GPIO, 1, 6); |