lpcware

How to count external pulses with SCTimer?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
Content originally posted in LPCWare by rsg on Tue May 31 13:37:48 MST 2016
Ugh!  All I want to do is configure the SCT peripheral to count rising edges of a tach signal that is input on a pin.  I would like to read the count periodically to determine the RPM of a motor.  I don't need all these states and transitions!  As is often the case with fancy peripherals, it seems the simplest uses get no documentation!

So far, this is the extent of my code; the count never seems to change.  Any help would be greatly appreciated!
    // 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

Outcomes