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.

Trying to get the function "bool IEC60730_OSCILLATOR_TEST_testOsc(void)" running and having trouble.

Other Parts Discussed in Thread: MSP430AFE253

I am using the MSP430AFE253 chip with no external crystal. I am trying to incorporate the iec60730 class b functionality and am having trouble getting "bool IEC60730_OSCILLATOR_TEST_testOsc(void)" to run correctly.

 

bool IEC60730_OSCILLATOR_TEST_testOsc(void)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
uint16_t freqCounter = 0;
const uint16_t freqMin = FREQUENCY_COUNT_MIN;
const uint16_t freqMax = FREQUENCY_COUNT_MAX;
/* Feed WDT in case user has WDT enabled before running CPU test */
#if ENABLED_WDT
uint16_t wdtConfig = WDTCTL & 0x00ff;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

WDTCTL = WDTPW + WDTCNTCL + wdtConfig;
#endif /* ENABLED_WDT */
frequencyMin = freqMin;
frequencyMax = freqMax;
/*
* Assign CCRn the value of CCRn_VALUE_FOR_10_mSEC to count up in
* 10 msec intervals. CCRn_VALUE_FOR_10_mSEC macro is defined in
* "IEC60730_system_config.h" file. However, the macro is calculated based
* on MAIN_CLOCK_FREQUENCY, LFXT1_FREQUENCY, MAIN_CLOCK_DIVIDER and
* LFXT1_FREQUENCY_DIVIDER and WDT_ENABLED.
*/
#if defined(USE_TA0)
#if defined(USE_CCR0)
TACCR0 = CCRn_VALUE_FOR_10_mSEC;
#endif /* USE_CCR0 */
#if defined(USE_CCR1)
TA0CCR1 = CCRn_VALUE_FOR_10_mSEC;
#endif /* USE_CCR1 */
#if defined(USE_CCR2)
TA0CCR2 = CCRn_VALUE_FOR_10_mSEC;
#endif /* USE_CCR2 */
#if defined(USE_CCR3)
TA0CCR3 = CCRn_VALUE_FOR_10_mSEC;
#endif /* USE_CCR3 */
#if defined(USE_CCR4)
TA0CCR4 = CCRn_VALUE_FOR_10_mSEC;
#endif /* USE_CCR4 */

TACTL = TASSEL_1 + MC_2 + TACLR + ID_3; // TASSEL_1 = ACLK, MC_2 = U mode, Clear Timer

/* Increase freqCounter until TAxR reaches CCRn_VALUE_FOR_10_mSEC */
#if defined(USE_CCR0)
TACCTL0 &= ~CCIFG;
// TACCTL0 |= CCIE;
P1OUT |= BIT7;
do
{
freqCounter++;
} while(!(TACCTL0 & CCIFG));

P1OUT &= ~BIT7;

I am getting stuck in the do --while loop. It seems as if  while(!(TACCTL0 & CCIFG));  never gets satisfied. The freqCounter is incrementing but it seems as if TACCTL0 isn't being checked.

It just stays in the while loop forever.

Have any ideas as to why TACCTL0 & CCIFG doesn't seem to be functioning?

Steve

  • MAIN_CLOCK_FREQUENCY is set to 12MHz.

    Steve
  • The ocillator is set for 12MHz.

    The chip is msp430afe253

    #define NUMBER_OF_CYLES_TO_INCREMENT_COUNTER 7

    //***************************************************************************************
    //Defines to provide information regarding independent clock source that will be used to
    //monitor the main clock source
    //***************************************************************************************
    #define LFXT1_FREQUENCY 12000000 // 32768
    #define LFXT1_FREQUENCY_DIVIDER 1

    //***************************************************************************************
    //Defines to provide determine the allowed frequency drift of the main clock (in +/- %)
    //***************************************************************************************
    #define PERCENT_FREQUENCY_DRIFT 3

    Below is the main function

    uint16_t frequencyMin;
    uint16_t frequencyMax;
    uint16_t freqCounter;
    bool IEC60730_OSCILLATOR_TEST_testOsc(void)
    {
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    //uint16_t freqCounter = 0;
    const uint16_t freqMin = FREQUENCY_COUNT_MIN;
    const uint16_t freqMax = FREQUENCY_COUNT_MAX;
    /* Feed WDT in case user has WDT enabled before running CPU test */
    #if ENABLED_WDT
    uint16_t wdtConfig = WDTCTL & 0x00ff;
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

    WDTCTL = WDTPW + WDTCNTCL + wdtConfig;
    #endif /* ENABLED_WDT */
    freqCounter = 0;
    frequencyMin = freqMin;
    frequencyMax = freqMax;
    /*
    * Assign CCRn the value of CCRn_VALUE_FOR_10_mSEC to count up in
    * 10 msec intervals. CCRn_VALUE_FOR_10_mSEC macro is defined in
    * "IEC60730_system_config.h" file. However, the macro is calculated based
    * on MAIN_CLOCK_FREQUENCY, LFXT1_FREQUENCY, MAIN_CLOCK_DIVIDER and
    * LFXT1_FREQUENCY_DIVIDER and WDT_ENABLED.
    */
    #if defined(USE_TA0)
    #if defined(USE_CCR0)
    TACCR0 = CCRn_VALUE_FOR_10_mSEC;
    #endif /* USE_CCR0 */
    #if defined(USE_CCR1)
    TA0CCR1 = CCRn_VALUE_FOR_10_mSEC;
    #endif /* USE_CCR1 */
    #if defined(USE_CCR2)
    TA0CCR2 = CCRn_VALUE_FOR_10_mSEC;
    #endif /* USE_CCR2 */
    #if defined(USE_CCR3)
    TA0CCR3 = CCRn_VALUE_FOR_10_mSEC;
    #endif /* USE_CCR3 */
    #if defined(USE_CCR4)
    TA0CCR4 = CCRn_VALUE_FOR_10_mSEC;
    #endif /* USE_CCR4 */

    TACTL = TASSEL_1 + MC_2 + TACLR; // TASSEL_1 = ACLK, MC_2 = U mode, Clear Timer

    /* Increase freqCounter until TAxR reaches CCRn_VALUE_FOR_10_mSEC */
    #if defined(USE_CCR0)
    TACCTL0 &= ~CCIFG;
    P1OUT |= BIT7;
    do
    {
    freqCounter++;
    } while(!(TACCTL0 & CCIFG));

    P1OUT &= ~BIT7;
    #endif /* USE_CCR0 */


    /* Stop TimerA0 */
    TACTL = MC_0;
    #endif /* USE_TA0 */

    #elif defined(__MSP430_HAS_BC2__)
    if((freqCounter >= freqMin) && (freqCounter <= freqMax) && !(BCSCTL3 & LFXT1OF))
    {
    return(SIG_CLOCK_TEST);
    }
    #endif /* if defined(__MSP430_HAS_CS__) */

    /*
    * If freqCounter is outside the permissible frequency range, the test
    * fail
    */
    return(TEST_FAILURE);
    } /* IEC60730_OSCILLATOR_TEST_testOsc */

    the reading for freqCounter is not very repeatable.

    Can you see anything that I am doing wrong? Or point me in a direction I can at least understand what is going on? Is the selected frequency wrong, to high?

    Steve

  • Steve,
    I do not see anything obvious and will need to dig into this some more. I have also reached out to the author for inputs. Where you able to identify the issue in your first post or are there two separate issues?

    Regards,
    Chris
  • Hi Steve,

    Could you please share your clock configuration? Are you configuring ACLK to be source by the VLO source?

    I suspect ACLK is not configured properly and that might be the reason the timer is not expiring. In AFE devices you need no make sure  LFXT1Sx = 10 and XTS = 0 to select VLOCLK as the source.

    Regards,

    Ivan

**Attention** This is a public forum