This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: Using MSP432 Internal Comparator to Measure Frequency

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi, I want to use MSP432internal comparator to measure external input signal's frequency.If I can measure time between two zero crossing points, I can get the frequency.

I think I can use COMP_E in MSP432, I find an COMP_E introduction saying "Output provided to Timer_A capture input", how can I use CIMP_E to trigger Timer_A?Is Timer_A capture mode using the COMP_E in MSP432? If so, how can I set Timer_A capture level?

  • If you refer  to the TimerA Signal Connnection tables on page 128,

    http://www.ti.com/lit/ds/symlink/msp432p401r.pdf#page=128

    , you can see that the comparator output and timer input share the connection.   This is how the output is provided to the capture input (it can also be configured to the timer input).  

    The comparator and the timer are configured separately.  The comparator will define the voltage level at which the digital capture signal is sent to the timer.  

    Please refer to the TRM to get a better undertanding of the timer configuration. 

    http://www.ti.com/lit/ug/slau356h/slau356h.pdf#page=782

    Also, there are examples for using the comparator and timer here:

    http://dev.ti.com/tirex/#/?link=Software%2FSimpleLink%20MSP432P4%20SDK%2FExamples%2FDevelopment%20Tools%2FMSP432P401R%20LaunchPad%20-%20Red%202.x%20(Red)%2FDriverLib%2Fcomp_e_output_toggle_vcomp_vrefhalfvcc

    http://dev.ti.com/tirex/#/?link=Software%2FSimpleLink%20MSP432P4%20SDK%2FExamples%2FDevelopment%20Tools%2FMSP432P401R%20LaunchPad%20-%20Red%202.x%20(Red)%2FDriverLib%2Ftimer_a_continuous_vlo_period_capture%2FNo%20RTOS%2FCCS%20Compiler%2Ftimer_a_continuous_vlo_period_capture%2Ftimer_a_continuous_vlo_period_capture.c

    Please note that there are several timers to choose from.

    Regards,

    Chris

  • Thank's for replying!
    Does it mean that if I want change Timer_A capture trigger electrical level, I should use module block with internal COUT(CCR2、CCR3), and configured the COMP_E module's reference voltage?
  • I run this example

    timer_a_continuous_vlo_period_capture.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    /*
    * -------------------------------------------
    * MSP432 DriverLib - v3_21_00_05
    * -------------------------------------------
    *
    * --COPYRIGHT--,BSD,BSD
    * Copyright (c) 2016, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    * --/COPYRIGHT--*/
    /*******************************************************************************
    * MSP432 Timer_A - VLO Period Capture
    *
    * Description: Capture a number of periods of the VLO clock and store them in
    * an array. When the set number of periods is captured the program is trapped
    * and the LED on P1.0 is toggled. At this point halt the program execution read
    * out the values using the debugger.
    * ACLK = VLOCLK = 14kHz (typ.), MCLK = SMCLK = default DCO = 3MHz
    *
    * MSP432P401
    * ------------------
    * /|\| |
    * | | |
    * --|RST P1.0 |---> P1.0 LED
    * | P2.4 |--- TA0.1
    * | | |
    * | P4.2 |--- ACLK
    * | |
    * Author: Timothy Logan
    *******************************************************************************/
    /* DriverLib Includes */
    #include "driverlib.h"
    /* Standard Includes */
    #include <stdint.h>
    #define NUMBER_TIMER_CAPTURES 20
    /* Timer_A Continuous Mode Configuration Parameter */
    const Timer_A_ContinuousModeConfig continuousModeConfig =
    {
    TIMER_A_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The comments say ACLK = 14KHz, P4.2 output. I connect P4.2 and P2.4, when LED(P1.0) toggle, I stop to read the timerAcaptureValues array.

    I can see a series of "313 626 939 1253 1566...", indecading Timer_A counting 313 number per rising edge.

    See that the Timer_A count at a rate of 3MHz:

    /* Timer_A Continuous Mode Configuration Parameter */
    const Timer_A_ContinuousModeConfig continuousModeConfig =
    {
            TIMER_A_CLOCKSOURCE_SMCLK,           // SMCLK Clock Source
            TIMER_A_CLOCKSOURCE_DIVIDER_1,       // SMCLK/1 = 3MHz
            TIMER_A_TAIE_INTERRUPT_DISABLE,      // Disable Timer ISR
            TIMER_A_SKIP_CLEAR                   // Skup Clear Counter
    };

    So 313 number represents 3000000/313 =  9584.6645Hz, not the ACLK 14KHz.Why?

  • Thank you for pointing this out.  The comments in the code example are incorrect.  Please refer to the datasheet for the specified device performance.  

    Regards,

    Chris

  • Thanks a lot!

**Attention** This is a public forum