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.

ADC10 - Seven segment display

Other Parts Discussed in Thread: MSP430G2231

Hello all,

I've been trying to do an analog to digital conversion using MSP430 Launchpad. First I tried to reach every single bit in the ADC10MEM register but I gave up on that. Now, the thing I've been trying is to segmentize the ADC10MEM register, i.e, I will divide the value to 10 levels, and display the output on a seven segment display. The code is the following:

#include "msp430g2231.h"

void ConfigureAdc(void)
{
/* Configure ADC Channel */
ADC10CTL1 = INCH_5 + ADC10DIV_3 ;                                                         // Channel 5, ADC10CLK/4
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;           //Vcc & Vss as reference
ADC10AE0 |= BIT5;                                                                                              //P1.5 ADC option
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;                // Stop WDT
BCSCTL1 = CALBC1_1MHZ;                         // Set range
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);                               // SMCLK = DCO = 1MHz
P1DIR |= 0xdf;                                                  //All ports except P1.5 to output
P1SEL |= BIT5;                                                //ADC Input pin P1.5
P1OUT &= ~(0xdf);                                            // 0 initialization

ConfigureAdc();
__enable_interrupt();                                              // Enable interrupts.

while(1)
{
__delay_cycles(1000);                                          // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;                    // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);                  // LPM0 with interrupts enabled


/* the part I divided ADC10MEM to 10 */

if(ADC10MEM > 922)
P1OUT = 0x4;                                       //these hex numbers are to display numbers from 9 to 0 in the seven segment
else if(ADC10MEM > 820)
P1OUT = 0x0;
else if(ADC10MEM > 718)
P1OUT = 0xF;
else if(ADC10MEM > 616)
P1OUT = 0x20;
else if(ADC10MEM > 514)
P1OUT = 0x24;
else if(ADC10MEM > 412)
P1OUT = 0x4C;
else if(ADC10MEM > 310)
P1OUT = 0x6;
else if(ADC10MEM > 207)
P1OUT = 0x12;
else if(ADC10MEM > 105)
P1OUT = 0x4F;
else
P1OUT = 0x1;
}
}


// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
}

As I tried this with voltages in a range from 0 to 3.3  I got High from P1.2 and L from all others everytime and this is none of the outputs I gave to the seven segment in the if statements.

I looked at all the example codes that TI published, I also read the User's manuals many times but could not find a way out.

Any help is appreciated,

Best regards

Günay Turan 

  • G��� Turan said:

    /* the part I divided ADC10MEM to 10 */

    if(ADC10MEM > 922)
    P1OUT = 0x4;                                       //these hex numbers are to display numbers from 9 to 0 in the seven segment

    As I tried this with voltages in a range from 0 to 3.3  I got High from P1.2 and L from all others everytime and this is none of the outputs I gave to the seven segment in the if statements.

    Günay Turan 

    It's your first output of your if statements, [Edit: that's being executed] i.e, the first output statement if(ADC10MEM > 922) P1OUT = 0x4 which is the same as 0x04 (only P1.2 high).

    And BIT5 is your A/D Chan5 and you seem to be using it also as an output.

  • Thank you so much Joseph.

    My apologies for the late return to thank you. 

    Best regards.

**Attention** This is a public forum