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.

MSP430 ADC & LCD ISSUES. CAN SOMEBODY HELP ?



I had bought MSP-EXP430FR4133  to try out some codes and build  small products based on it.I did go through the sample codes provided in MSP430ware.

I wanted to do a ADC on P8.1 and then display the Numeric code ( 0 to 1023 ) on to the LCD provided along with the Launchpad.

Apparently the LCD displays random values instead of the 10 Bit ADC one.Can some body help ?

Code is as below.

#include <msp430fr4133.h>
unsigned int sensor[2];
unsigned int splitchar[4]= { 0,0,0,0 };
unsigned int i;
unsigned int j;

const char digit[10] ={
    0xFC,                                                      // "0"
    0x60,                                                      // "1"
    0xDB,                                                      // "2"
    0xF3,                                                      // "3"
    0x67,                                                      // "4"
    0xB7,                                                      // "5"
    0xBF,                                                      // "6"
    0xE4,                                                      // "7"
    0xFF,                                                      // "8"
    0xF7                                                       // "9"
};

ADC - CODES

  // Configure ADC A8
    SYSCFG2 |= ADCPCTL8 ;
  
 // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    // Configure ADC10
    ADCCTL0 |= ADCSHT_1 | ADCMSC | ADCON ;                    // ADCON, S&H=16 ADC clks
    ADCCTL1 |= ADCSHP | ADCCONSEQ_0 |  ADCDIV_2;              // ADCCLK = MODOSC; sampling timer
    ADCCTL2 |= ADCRES;                                        // 10-bit conversion results
    ADCIE |= ADCIE0;

LCD CODE

   // Configure LCD pins
    SYSCFG2 |= LCDPCTL;                                        // R13/R23/R33/LCDCAP0/LCDCAP1 pins selected
    LCDPCTL0 = 0xFFFF;
    LCDPCTL1 = 0x07FF;
    LCDPCTL2 = 0x00F0;                                         // L0~L26 & L36~L39 pins selected
    LCDCTL0 = LCDSSEL_0 | LCDDIV_7;                            // flcd ref freq is xtclk

    // LCD Operation - Mode 3, internal 3.08v, charge pump 256Hz
    LCDVCTL = LCDCPEN | LCDREFEN | VLCD_6 | (LCDCPFSEL0 | LCDCPFSEL1 | LCDCPFSEL2 | LCDCPFSEL3);

    LCDMEMCTL |= LCDCLRM;                                      // Clear LCD memory

    LCDCSSEL0 = 0x000F;                                        // Configure COMs and SEGs
    LCDCSSEL1 = 0x0000;                                        // L0, L1, L2, L3: COM pins
    LCDCSSEL2 = 0x0000;

    LCDM0 = 0x21;                                              // L0 = COM0, L1 = COM1
    LCDM1 = 0x84;                                              // L2 = COM2, L3 = COM3

WHILE LOOP - CODE

    while(1)	{

    	  	ADCMCTL0 |= ADCINCH_8  | ADCSREF_0;
    	    	ADCCTL0 |= ADCENC | ADCSC ;		              // Sampling and conversion start
    	        while(ADCCTL1 & ADCBUSY);
    	        sensor[0] = ADCMEM0;
    	        _delay_cycles(10000);

    				sensor[1]=sensor[0];

    				for (i = 0 ; i<=3 ; i++ )	{
    					splitchar[i] |= sensor[1] % 10;
    					ADCMEM0 = splitchar[i];
    					sensor[1] |= sensor[1] / 10;
    					_delay_cycles(10000);
    				}


    				LCDMEM[pos6] = digit[(splitchar[0])];
				LCDMEM[pos5] = digit[(splitchar[1])];
    				LCDMEM[pos4] = digit[(splitchar[2])];
				LCDMEM[pos3] = digit[(splitchar[3])];

    			    LCDCTL0 |= LCD4MUX | LCDON;                                // Turn on LCD, 4-mux selected

    			    PMMCTL0_H = PMMPW_H;                                       // Open PMM Registers for write
    			    PMMCTL0_L |= PMMREGOFF_L;                                  // and set PMMREGOFF


    }

  • Hi Bharath!

    What do you mean with "random values"? Do they change surprisingly?
    First thing to do: Find out if the values come randomly from the ADC and the output of them work fine, or if the ADC is right and the output is wrong.
    So start putting fixed values into the LCD output and have a look if they still change.

    Dennis
  • Why are you writing to ADCMEM0? Why are you using |= for splitchar?
  • Agree with Clemens,

    those parts of your code do not make sense. Imagine we get a value from the ADC - let's say 1017. We want to seperate the single digits, then we could do the following:

    unsigned char splitchar[4]= { 0, 0, 0, 0 };
    
    unsigned int sensor = 1017;
    
    const char digit[10] =
    {
      0xFC,                                                      // "0"
      0x60,                                                      // "1"
      0xDB,                                                      // "2"
      0xF3,                                                      // "3"
      0x67,                                                      // "4"
      0xB7,                                                      // "5"
      0xBF,                                                      // "6"
      0xE4,                                                      // "7"
      0xFF,                                                      // "8"
      0xF7                                                       // "9"
    };
    
    ...
    
    splitchar[0] = sensor / 1000; // 1 in first position of splitchar - thousands
    sensor %= 1000;               // sensor is now (0)17
    splitchar[1] = sensor / 100;  // 0 in second position of splitchar - hundreds
    sensor %= 100;                // sensor is now 17
    splitchar[2] = sensor / 10;   // 1 in third position of splitchar - tens
    splitchar[3] = sensor % 10;   // 7 in fourth position of splitchar - ones
    
    ...
    
    ... = digit[(splitchar[0])];
    ... = digit[(splitchar[1])];
    ... = digit[(splitchar[2])];
    ... = digit[(splitchar[3])];

    Or use sprintf, although it is a little bit oversized for that.

    Dennis

  • To link the multiple duplicate posts together, it looks like the same question was posted here:
    e2e.ti.com/.../410453
    and here:
    e2e.ti.com/.../410572
    Just in case there's different info in each post, and to make this easier for later users that come upon these threads.
    Next time please try to keep your questions about the same issue/topic in the same thread (but still good to start a new thread if it is a question on a new topic) - this makes it easier for people to help you and easier for later users that want to read your post to learn and get help when they run into the same problem. Thanks!
    Regards,
    Katie

**Attention** This is a public forum