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/MSP430F6736: Analog Value display

Part Number: MSP430F6736
Other Parts Discussed in Thread: MSP-TS430PZ100B, , MSP430WARE

Tool/software: Code Composer Studio

Hello team,

I wanted to display an analog value on the screen (monitor) using MSP430F6736 and MSPFET. I have a MSP-TS430PZ100B board.

I want to use the internal ADC of the micro-controller and get the analog value from the analog input pin A0 and display that value on the screen.

What steps do I need to follow?

Thank you.

  • Hi,

    for the two integrated modules you intent to use (10-Bit A/D Converter and the LCD Controller) I advise you to first have a look at the MSP430x5xx and MSP430x6xx Family User's Guide Chapter 27 for 10-Bit A/D Converter and Chapter 35 for the LDC_C module.

    This document will help you to understand how the modules work and how to correctly configure them for your application.

    Besides, we provide a set of code examples which will help you to get started. They are part of the MSP430Ware which is automatically downloaded with Code Composer Studio (CCS). In CCS you can also find them in the Resource Explorer, browsing to MSP430Ware -> Devices -> MSP430x5xx_x6xx ->MSP430F6736-> Peripheral Examples -> Register Level. There you'll find multiple examples for both ADC10 and LCDC.

    Please have a look at those to indications and let me know if you have additional questions.

    Best regards,

    Britta

  • Is there anyway that I can display the values on an excel sheet on the PC screen?
    Like generating a text file or an excel sheet using C programming and MSP430?

    Thank you.
  • Sure, you could write a program on the PC to capture the values from the serial port and create a file.

    If this will happen with the debugger attached, you might be able to use the rudimentary stdio facilities built into CCS.
  • I am using the following example code:

    
    #include <msp430.h>
    #include <stdio.h>
    
    unsigned int ADC_Result;
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                     // Stop WDT
    
    
        // Setup P1.2 for A0
        P1SEL |= BIT2;                                // Set P1.2 to non-IO
        __disable_interrupt();                        // Disable interrupts; Port Map cnfg
        PMAPKEYID = PMAPKEY;                          // Enable access Port Mapping regs
        P1MAP2 = PM_ANALOG;                           // Enable A0
        PMAPKEYID = 0;                                // Disable access Port Mapping regs
        __enable_interrupt();                         // Re-enable all interrupts
        P1DIR |= BIT0;                                // Set P1.0 to output direction
        P1OUT &= ~BIT0;                               // Clear P1.0
    
        // By default, REFMSTR=1 => REFCTL is used to configure the internal reference
        while (REFCTL0 & REFGENBUSY) ;                // If ref generator busy, WAIT
        REFCTL0 |= REFVSEL_0 | REFON;                 // Select internal ref = 1.5V
                                                      // Internal Reference ON
        // Setup ADC10
        ADC10CTL0 = ADC10SHT_2 | ADC10ON;             // S&H=16 ADC clks, Enable ADC10
        ADC10CTL1 |= ADC10SHP;                        // ADCCLK = MODOSC; sampling timer
        ADC10CTL2 |= ADC10RES;                        // 10-bit conversion results
        ADC10IE |= ADC10IE0;                          // Enable ADC conv cmplete interrupt
        ADC10MCTL0 |= ADC10INCH_0 | ADC10SREF_1;      // A0 ADC input select; Vref=1.5V
    
        // Configure TA0 to provide delay for reference settling ~75us
        TA0CCR0 = 80;                                 // Delay to allow Ref to settle
        TA0CCTL0 |= CCIE;                             // Compare-mode interrupt.
        TA0CTL = TASSEL_2 | MC_1;                     // TACLK = SMCLK, Up mode.
        __bis_SR_register(LPM0_bits | GIE);           // Enter LPM0 w/ interrupt
        TA0CCTL0 &= ~CCIE;                            // Disable timer interrupt
    
        while (1)
        {
            __delay_cycles(5000);                     // Delay between conversions
    
            ADC10CTL0 |= ADC10ENC | ADC10SC;          // Sampling and conversion start
    
            __bis_SR_register(LPM0_bits | GIE);       // Enter LPM0 w/ interrupt
            __no_operation();                         // For debug only
    
            if (ADC_Result > 0x01FF)                   // ADC10MEM = A0 > 0.5V?
            {
                P1OUT |= 0x01;                       // Clear P1.0 LED off
                printf("ADC result: %d\n",ADC_Result);
            }
            else
            {
                P1OUT &= ~0x01;                        // Set P1.0 LED on
                printf("ADC result: %d\n",ADC_Result);
            }
    
        }
    }
    
    // ADC10 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch (__even_in_range(ADC10IV, 12))
        {
            case  ADC10IV_NONE: break;                // No interrupt
            case  ADC10IV_ADC10OVIFG: break;          // conversion result overflow
            case  ADC10IV_ADC10TOVIFG: break;         // conversion time overflow
            case  ADC10IV_ADC10HIIFG: break;          // ADC10HI
            case  ADC10IV_ADC10LOIFG: break;          // ADC10LO
            case  ADC10IV_ADC10INIFG: break;          // ADC10IN
            case  ADC10IV_ADC10IFG:                   // ADC10
                ADC_Result = ADC10MEM0;               // Store ADC10 channel 0 result
                printf("ADC result: %d\n",ADC_Result);
    
                __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 on return
                break;
            default: break;
        }
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void TA0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TA0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        TA0CTL = 0;                                   // Reset TA0
        __bic_SR_register_on_exit(LPM0_bits);         // Exit LPM0 on return
    }
    

    I am displaying the ADC_Result value on the screen, but I am unable to get the exact value of the input that I am giving in the ADC_Result register. 

    for instance, if I am giving 0.5V as an input I should get 171 as a digital value in the ADC_Result register but I am getting 415,851,515.... the values are fluctuating and not settling to a constant value that is desired.

    Is there any error in the code?

    thank you

  • Hi,

    one thing I've perceived is that you stated you'd expect a digital value of around 171 for an input of 0.5 V. Please check if this tkaes into account that you've configured the internal reference to 1.5V.

    Please also check if you allow enough time to actually charge the internal capacitors to the input voltage so that the reading is valid. Could it be that some sample results don't reflect the input voltage as the capacitors did not charge to the full level? Also can you verify the input voltage to make sure it's stable? Does it provide enough current to charge the capacitors used for the A/D conversion?

    Within the while() you compare the ADC_Result to 0x1FF and your comment says you intend to compare to a voltage of 0.5V. This is not consistent to your statement before (expecting a digital reading of 171). Please carefully check for reference voltage setting and thus determine what value to expect.

    Let me know if any of those hints help you to figure out the exact issue.

    Thanks and best regards,
    Britta
  • Hi Britta,

    Line 33 shows a delay command for the ref to settle. Does that solve the case?
    I am using a power supply for providing the input so I am not 100% sure whether it is stable or not. I see that the circuit isn't drawing current from the supply. I am providing enough current.

    within the while(), I am comparing the values of the ADC in order to turn the LED on and off. So what is in there does not matter to my final ADC result as it is just checking whether the ADC value is above a certain limit or not.

    line 81 stores the converted digital value into the ADC_Result register where I need to get the desired output. I have put breakpoints and found out that I am not getting the desired value.

    Is there any change that I need to make in the code in order to get the desired output?


    As far as reference voltage is concerned:

    ADC10MCTL0 |= ADC10INCH_0 | ADC10SREF_1; // A0 ADC input select; Vref=1.5V

    does this command serve the purpose?


    Thank you.
  • Hi Keval,

    from what I see your code is pretty similar to the code example we provide with minor changes to the conditions for LED on/ off.

    So I don't believe there are issues with the code.

    You problem is that you don't receive the desired value after A/D conversion. You stated that you're not sure your input is stable. Please check the input voltage to make sure it's not the source of the issue. Is your input voltage fixed to the ADC input? Did you take the "Sample Timing Considerations" (Section 27.2.5.3 of the Family User's Guide SLAU208 into account?). Maybe you're not fully charging the the input capacitor and therefor don't get the expected result.

    Best regards,

    Britta

**Attention** This is a public forum