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.

MSP430FR6989: ADC SHT timer!!!!

Part Number: MSP430FR6989

Hello guys!

I am working on ADC portion of this device. Presently I am having trouble in figuring out how to set time for collecting data for 10 sec? How can I set the timer?

I looked in the Users guide and it said that " ADC12SHT0x and ADC12SHT1x bits in ADC12CTL0 control the interval of the sampling timer  " and SAMPCON high/low determines the time.

What is time based on? is it same like other timer(microsec)?

Do I have to run in in loop and Set the timer for "for loop"?

  • Have you successfully used the ADC module to read the voltage on a pin? I would like to know how far in the code development you are.
  • I just did basic stuffs like turning led on by converting analog to digital.
  • Yeah I have just completed that. I am able to read voltage in the pin
  • It will all depend on how many samples you would like to take during the 10s. That will determine how we approach this problem.
  • Lets do it with 100 samples per second
  • So it will be like 1000 samples.. Can you show me sample process to calculate it. Thanks
  • Sabin,

    This means you would like 100 samples/s. The way I would solve this problem is set up a timer with interrupt at 100 Hz. Then at every interriupt I would sample the adc and store the result.

    Nima Eskandari

  • Thank YOU.
    I have been trying to digitize 100hz analog signal for 10 sec with range of 1 Vpeak to peak. I have written some code for it. But I am not able to get value of ADC12MEM0 or any in resistor box. And I cant figure out how to get range of 1V peak to peak. Hoping for your help

     // NOTE: I have posted updated version of the program  in the next comment


    #include <msp430.h>
    #define STOP_WATCHDOG 0x5A80 // Stop the watchdog timer
    #define ACLK 0x0100 // Timer_A ACLK source
    #define UP 0x0010 // Timer_A Up mode
    #define ENABLE_PINS 0xFFFE // Required to use inputs and outputs
    #define ADC12_P84 0x0007 // Use input P8.4 for analog input
    #define ADC12_P92 0x000A // Use input P9.2 for analog input
    void ADC_SETUP(void);
    main()
    {
    WDTCTL = STOP_WATCHDOG; // Stop the watchdog timer
    PM5CTL0 = ENABLE_PINS; // Required to use inputs and outputs
    TA0CCR0 = 400; // Sets value of Timer_0
    TA0CTL = ACLK + UP; // Set ACLK, UP MODE for Timer_0
    TA0CCTL0 = CCIE; // Enable interrupt for Timer_0
    TA1CCR0 = 40000; // Sets value of Timer_1
    TA1CTL = ACLK + UP; // Set ACLK, UP MODE for Timer_1
    TA1CCTL0 = CCIE; // Enable interrupt for Timer_1
    ADC_SETUP();
    ADC12IER0 = ADC12IE0; // Enable ADC interrupt
    _BIS_SR(GIE); // Activate interrupts


    }


    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A(void)
    {
    ADC12CTL0 = ADC12CTL0 | ADC12ENC; // Re-enable conversion
    ADC12CTL0 = ADC12CTL0 | ADC12SC; // Start next conversion
    }

    //************************************************************************
    //* Configure Analog-to-Digital Converter peripheral**********************
    //************************************************************************


    void ADC_SETUP(void)
    {
    #define ADC12_SHT_16 0x0200 // 16 clock cycles for sample and hold
    #define ADC12_ON 0x0010 // Used to turn ADC12 peripheral on
    #define ADC12_SHT_SRC_SEL 0x0200 // Selects source for sample & hold
    #define ADC12_12BIT 0x0020 // Selects 12-bits of resolution
    #define ADC12_P84 0x0007

    ADC12CTL0 = ADC12SHT02 | ADC12_ON ; // Turn on, set sample & hold time
    ADC12CTL1 = ADC12_SHT_SRC_SEL; // Specify sample & hold clock source
    ADC12CTL2 = ADC12_12BIT; // 12-bit conversion results
    ADC12MCTL0 = ADC12_P84; // P8.4 is analog input
    }

  • I have been trying to digitize 100hz analog signal for 10 sec with range of 1 Vpeak to peak. I have written some code for it. But I am not able to get value of ADC12MEM0 or any in resistor box. 




    #include <msp430.h>
    #define STOP_WATCHDOG 0x5A80 // Stop the watchdog timer
    #define ACLK 0x0100 // Timer_A ACLK source
    #define UP 0x0010 // Timer_A Up mode
    #define ENABLE_PINS 0xFFFE // Required to use inputs and outputs
    #define ADC12_P84 0x0007 // Use input P8.4 for analog input
    #define ADC12_P92 0x000A // Use input P9.2 for analog input
    void ADC_SETUP(void);
    main()
    {
    WDTCTL = STOP_WATCHDOG;
    PM5CTL0 = ENABLE_PINS;
    TA0CCR0 = 400; // for 100 Hz=10ms and 400 count is 10 ms
    TA0CTL = ACLK + UP; // Set ACLK, UP MODE for Timer_0
    TA0CCTL0 = CCIE; // Enable interrupt for Timer_0
    TA1CCR0 = 40000; // count for 1 sec
    TA1CTL = ACLK + UP; // Set ACLK, UP MODE for Timer_1
    TA1CCTL0 = CCIE; // Enable interrupt for Timer_1
    ADC_SETUP();
    _BIS_SR(GIE); // Activate interrupts

    }






    {
    int adc_value = ADC12MEM0 & 0x0FFF; // changes to 12 bit binary
    save[i]=adc_value; //saves data
    i++;
    }
    ADC12CTL0 &= ~(ADC12ENC); //******************** (does it matter if I reset It?) //disables conversion
    }

    // This function counts for 10 seconds as it takes 1 sec to interrupt timer A1
    //Finally if it reaches 10 sec then it disables all interrupt
    #pragma vector=TIMER0_A1_VECTOR
    __interrupt void Timer_B(void


    //This is basic as other normal program
    void ADC_SETUP(void)
    {
    #define ADC12_SHT_16 0x0200 // 16 clock cycles for sample and hold
    #define ADC12_ON 0x0010 // Used to turn ADC12 peripheral on
    #define ADC12_SHT_SRC_SEL 0x0200 // Selects source for sample & hold
    #define ADC12_12BIT 0x0020 // Selects 12-bits of resolution
    #define ADC12_P84 0x0007
    ADC12CTL0 =ADC12_SHT_16 | ADC12_ON ; // Turn on, set sample & hold time
    ADC12CTL1 = ADC12_SHT_SRC_SEL; // Specify sample & hold clock source
    ADC12CTL2 = ADC12_12BIT; // 12-bit conversion results
    ADC12MCTL0 = ADC12_P84; // P8.4 is analog input
    }

  • Sabin,

    Please allow me some time to go through your code and look for any error.

    Thank you,
    Nima
  • Do I need to add other Interrupt function for ADC12?
  • /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2014, 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.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430FR69xx Demo - ADC12, Sample A1, AVcc Ref, Set P1.0 if A1 > 0.5*AVcc
    //
    //   Description: A single sample is made on A1 with reference to AVcc.
    //   Software sets ADC12SC to start sample and conversion - ADC12SC
    //   automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
    //   and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
    //   conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
    //   reti. If A1 > 0.5*AVcc, P1.0 set, else reset. The full, correct handling of
    //   and ADC12 interrupt is shown as well.
    //
    //
    //                MSP430FR6989
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 |
    //          --|RST          XOUT|-
    //            |                 |
    //        >---|P1.1/A1      P1.0|-->LED
    //
    //   William Goh
    //   Texas Instruments Inc.
    //   April 2014
    //   Built with IAR Embedded Workbench V5.60 & Code Composer Studio V6.0
    //******************************************************************************
    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop WDT
    
        // GPIO Setup
        P1OUT &= ~BIT0;                         // Clear LED to start
        P1DIR |= BIT0;                          // Set P1.0/LED to output
        P1SEL1 |= BIT1;                         // Configure P1.1 for ADC
        P1SEL0 |= BIT1;
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Configure ADC12
        ADC12CTL0 = ADC12SHT0_2 | ADC12ON;      // Sampling time, S&H=16, ADC12 on
        ADC12CTL1 = ADC12SHP;                   // Use sampling timer
        ADC12CTL2 |= ADC12RES_2;                // 12-bit conversion results
        ADC12MCTL0 |= ADC12INCH_1;              // A1 ADC input select; Vref=AVCC
        ADC12IER0 |= ADC12IE0;                  // Enable ADC conv complete interrupt
    
        while (1)
        {
            __delay_cycles(5000);
            ADC12CTL0 |= ADC12ENC | ADC12SC;    // Start sampling/conversion
    
            __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit
            __no_operation();                   // For debugger
        }
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
            case ADC12IV_NONE:        break;    // Vector  0:  No interrupt
            case ADC12IV_ADC12OVIFG:  break;    // Vector  2:  ADC12MEMx Overflow
            case ADC12IV_ADC12TOVIFG: break;    // Vector  4:  Conversion time overflow
            case ADC12IV_ADC12HIIFG:  break;    // Vector  6:  ADC12BHI
            case ADC12IV_ADC12LOIFG:  break;    // Vector  8:  ADC12BLO
            case ADC12IV_ADC12INIFG:  break;    // Vector 10:  ADC12BIN
            case ADC12IV_ADC12IFG0:             // Vector 12:  ADC12MEM0 Interrupt
                if (ADC12MEM0 >= 0x7ff)         // ADC12MEM0 = A1 > 0.5AVcc?
                    P1OUT |= BIT0;              // P1.0 = 1
                else
                    P1OUT &= ~BIT0;             // P1.0 = 0
    
                    // Exit from LPM0 and continue executing main
                    __bic_SR_register_on_exit(LPM0_bits);
                break;
            case ADC12IV_ADC12IFG1:   break;    // Vector 14:  ADC12MEM1
            case ADC12IV_ADC12IFG2:   break;    // Vector 16:  ADC12MEM2
            case ADC12IV_ADC12IFG3:   break;    // Vector 18:  ADC12MEM3
            case ADC12IV_ADC12IFG4:   break;    // Vector 20:  ADC12MEM4
            case ADC12IV_ADC12IFG5:   break;    // Vector 22:  ADC12MEM5
            case ADC12IV_ADC12IFG6:   break;    // Vector 24:  ADC12MEM6
            case ADC12IV_ADC12IFG7:   break;    // Vector 26:  ADC12MEM7
            case ADC12IV_ADC12IFG8:   break;    // Vector 28:  ADC12MEM8
            case ADC12IV_ADC12IFG9:   break;    // Vector 30:  ADC12MEM9
            case ADC12IV_ADC12IFG10:  break;    // Vector 32:  ADC12MEM10
            case ADC12IV_ADC12IFG11:  break;    // Vector 34:  ADC12MEM11
            case ADC12IV_ADC12IFG12:  break;    // Vector 36:  ADC12MEM12
            case ADC12IV_ADC12IFG13:  break;    // Vector 38:  ADC12MEM13
            case ADC12IV_ADC12IFG14:  break;    // Vector 40:  ADC12MEM14
            case ADC12IV_ADC12IFG15:  break;    // Vector 42:  ADC12MEM15
            case ADC12IV_ADC12IFG16:  break;    // Vector 44:  ADC12MEM16
            case ADC12IV_ADC12IFG17:  break;    // Vector 46:  ADC12MEM17
            case ADC12IV_ADC12IFG18:  break;    // Vector 48:  ADC12MEM18
            case ADC12IV_ADC12IFG19:  break;    // Vector 50:  ADC12MEM19
            case ADC12IV_ADC12IFG20:  break;    // Vector 52:  ADC12MEM20
            case ADC12IV_ADC12IFG21:  break;    // Vector 54:  ADC12MEM21
            case ADC12IV_ADC12IFG22:  break;    // Vector 56:  ADC12MEM22
            case ADC12IV_ADC12IFG23:  break;    // Vector 58:  ADC12MEM23
            case ADC12IV_ADC12IFG24:  break;    // Vector 60:  ADC12MEM24
            case ADC12IV_ADC12IFG25:  break;    // Vector 62:  ADC12MEM25
            case ADC12IV_ADC12IFG26:  break;    // Vector 64:  ADC12MEM26
            case ADC12IV_ADC12IFG27:  break;    // Vector 66:  ADC12MEM27
            case ADC12IV_ADC12IFG28:  break;    // Vector 68:  ADC12MEM28
            case ADC12IV_ADC12IFG29:  break;    // Vector 70:  ADC12MEM29
            case ADC12IV_ADC12IFG30:  break;    // Vector 72:  ADC12MEM30
            case ADC12IV_ADC12IFG31:  break;    // Vector 74:  ADC12MEM31
            case ADC12IV_ADC12RDYIFG: break;    // Vector 76:  ADC12RDY
            default: break;
        }
    }
    

    Please look at the structure of this example code.

    Try running this code and using the Analog pin specified to read the analog voltage. Let me know what results you get.

**Attention** This is a public forum