How to count external pulses with SCTimer?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jan 17, 2019 by ATHMESH NANDAKUMAR
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

    /* 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.
    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