// enable clock to and reset peripheral Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT); Chip_SYSCTL_PeriphReset(RESET_SCT); /* From the manual: * The SCT can be used as standard counter/timer with external capture * inputs and match outputs without using the state logic. To operate the * SCT without states, configure the SCT as follows: * • Write zero to the STATE register (zero is the default). * • Write zero to the STATELD and STATEV fields in the EVCTRL registers * for each event. * • Write 0x1 to the EVn_STATE register of each event. Writing 0x1 * enables the event. * In effect, the event is allowed to occur in a single state which * never changes while the counter is running. */ Chip_SCT_Init(LPC_SCT); Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_1, SCT_INP_IN1); LPC_SCT->STATE_U = 0; LPC_SCT->EV[0].CTRL &= 0xfff03fff; LPC_SCT->EV[0].STATE = 1; Chip_SCT_Config(LPC_SCT, 0x0415); // 0000 0100 0001 0101 Chip_SCT_SetControl(LPC_SCT, 0x0008); // 0000 0000 0000 1000 |
//input capture PIO0_17 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_MODE_PULLDOWN)); Chip_SCT_Init(LPC_SCT0); //unified 32bit counter, SYNC all inputs, SCT0 input counter LPC_SCT0->CONFIG = SCT_CONFIG_32BIT_COUNTER | (1<<9) | SCT_CONFIG_CLKMODE_INCLK ; LPC_INMUX->SCT0_INMUX[0] = SCT0_INMUX_PIO0_17;//SCT0_IN0 = 2 = P0IO_17 LPC_SCT0->CAPCTRL[1].U = (SCT_EVT_1);//set capture control event //event 1: capture rising LPC_SCT0->EVENT[1].STATE = (SCT_EVT_1); // event happens in state LPC_SCT0->EVENT[1].CTRL = (0) | // capture, not used (0 << 5) | // OUTSEL[5] = selects input (0 << 6) | // IOSEL[9:6] = 0 select SCT0_IN0 (1 << 10) | // IOCOND[11:10] = 1 rising (2 << 12) | // COMBMODE[13:12] = IO condition (1 << 14) | // STATELD[14] = STATEV is loaded (1 << 15); // STATEV[19:15] = new state 1 LPC_SCT0->STATE =1;//start state LPC_SCT0->EVFLAG = (SCT_EVT_1); //reset flags Chip_SCT_ClearControl(LPC_SCT0, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);//and start } |