Stopwatch Timer using FRDM-KL43Z

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopwatch Timer using FRDM-KL43Z

644 Views
ashokfair
Contributor IV

This tutorial explain the implementation of simple stopwatch timer using FRDM-KL43Z board. FRDM-KL43Z comes with segment LCD display. we going to use this SLCD to display the time (4 digits, 0-99 sec). Project is based on the MCUXpresso IDE with SDK 2.3.0 version (SDK_2.3.0_FRDM-KL43Z.zip)

 

I have configured PIT module to generate system ticks for every 10ms.

/* Set timer period for channel 0 */
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(10000U, PIT_SOURCE_CLOCK));

The value of the system ticks will be displayed on the slcd screen

    setFloat4Digit(SysTickCount,1);

SW1 button is used for Start/Stop the timer

SW3 button is used for Reset the timer

206843_206843.jpgIMG_2386.jpg

 

Download the source attached in this post

Labels (1)
0 Kudos
1 Reply

233 Views
mjbcswitzerland
Specialist V

Hello Ashok

There is a stopwatch in the uTasker project (also works on FRDM-KL43Z).
I have attached a video showing it operating in the uTasker FRDM-KL43Z simulator and also a binary file that can be loaded to the board. The second button is used to freeze the time and when pressed again it allows the counter to be shown again (lap timing)

It runs in the 10ms tick interrupt and the code is as below (it does minimum switch de-bouncing and the generic SLCD interface [for all Kinetsi boards with SLCD] is fnTimeDisplay()).

Regards

Mark

// Called at 10ms intervals from the tick interrupt
//
extern void fnStopWatchApplication(void)
{
    static int iTimerState = 0;
    static unsigned char ulCount_ms = 0;
    static unsigned char ulCount_s = 0;
    int iStopKeyState = (_READ_PORT_MASK(A, SWITCH_1) == 0);
    if (_READ_PORT_MASK(C, SWITCH_3) == 0) {                             // start key pressed
        // Start counting
        //
        if (1 != iTimerState) {                                          // if not running
            ulCount_ms = ulCount_s = 0;                                  // reset
            iTimerState = 1;                                             // start running
        }
    }
    switch (iTimerState) {
    case 0:
        break;
    case 4:
        if (0 == iStopKeyState) {
            iTimerState = 1;
        }
        // Fall through intentionally
        //
    case 1:                                                              // stop watch running
        fnTimeDisplay(ulCount_s, ulCount_ms, 0);
        if ((1 == iTimerState) && (1 == iStopKeyState)) {                // if stop is pressed
            iTimerState = 2;
        }
        // Fall through intentionally
        //
    case 2:                                                              // stopped
        if ((2 == iTimerState) && (0 == iStopKeyState)) {                // if stop is released again
            iTimerState = 3;
        }
        // Fall through intentionally
        //
    case 3:
        if ((3 == iTimerState) && (0 != iStopKeyState)) {                // if stop is pressed again
            iTimerState = 4;
        }
        if (++ulCount_ms > 99) {                                         // keep running in background
            ulCount_ms = 0;
            if (++ulCount_s > 99) {
                iTimerState = 2;                                         // freeze at maximum value
            }
        }
        break;
    }
}

Kinetis: http://www.utasker.com/kinetis.html
Kinetis KL43:
- http://www.utasker.com/kinetis/FRDM-KL43Z.html
- http://www.utasker.com/kinetis/TWR-KL43Z48M.html

SLCD: http://www.utasker.com/docs/uTasker/uTasker_SLCD.pdf


Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

Professional Kinetis support, one-on-one training and complete fast-track project solutions: http://www.utasker.com/support.html

0 Kudos