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.

MSP430F5438A ADC12 (Final Help)

Other Parts Discussed in Thread: MSP430F5418A, MSP430F5438A, MSP430F5438

Hi,

I was wondering does anyone have like 5 mins and is experienced with the same microprocessor? I would just like for someone to please help me with a code to get input analog channels 13 and 14 working by ADC12. I'm pretty sure the coding would take 5 mins max. I have tried forums and adjusted my code 50 millions times and it seems correct but the ADC12 just does not work at all. This is my code but it does not work at all. It doesn't make any since because I've referenced and checked it a million times. It should work. I'm just running the ADC12 in a sequence for channels 13 and 14. Although I'm running it multiple times it is only running once every while loops starts. The values I get are not changing no matter what I plug into the pins and sometimes it does not even read. Can someone if possible type a code for me to do this and make sure it works? I have an MSP430-EXPF5438 board. Here is my code, and I am posting it. I have gotten help but to no avail.

#define NumberOfResults 400

volatile unsigned int results1[NumberOfResults];

volatile unsigned int results2[NumberOfResults];

void main (void)

{

int index = 0;

while(1)

{

/*Turns off the watch dog so the infinite loop to rst the program.*/
    WDTCTL = WDTPW + WDTHOLD;
   
    P7SEL = BIT5 | BIT6; //Set P7.5(A13) & P7.6(A14) to analog input.
   
    ADC12CTL0 = 0; //Set everything in CTL0 to 0, also making sure ENC is disabled to set the parameters.
    ADC12CTL1 = 0; //Set everything in CTL1 to 0.
   
    /*Setting Control 0: Sample and hold cycle for ADC12MEM8 through ADC12MEM15 is 256 CLK cycles,
     * multiscan is enabled, 2.5[V] as the reference point, reference on, turns on the ADC.*/
    ADC12CTL0 |= ADC12SHT11 | ADC12MSC | ADC12REF2_5V | ADC12REFON | ADC12ON;
   
    /*Setting Control 1: Starting conversion from P7.5(A13), SAMPCON signal is sourced from the sampling timer,
     * repeat-sequence-of-channels.*/
    ADC12CTL1 |= ADC12CSTARTADD3 | ADC12CSTARTADD2 | ADC12CSTARTADD0 | ADC12CONSEQ0 | ADC12SHP;//ADC12SHP + ADC12CONSEQ_1;
   
    ADC12CTL2 |= ADC12RES1;// | ADC12REFBURST;
   
    ADC12MCTL13 = 0; //Set everything in CTL13 to 0.
    ADC12MCTL14 = 0; //Set everything in CTL14 to 0.
   
    /*Setting the */
    ADC12MCTL13 |= ADC12SREF0 | ADC12INCH3 | ADC12INCH2 | ADC12INCH0;
    ADC12MCTL14 |= ADC12SREF0 | ADC12INCH3 | ADC12INCH2 | ADC12INCH1 | ADC12EOS;

    ADC12CTL0 |= ADC12ENC;

     while(index < NumberOfResults){
            ADC12CTL0 |= ADC12SC;
            while(ADC12CTL1 & ADC12BUSY){ //Runs forever, why?
                //Do nothing until the conversion sequence is finished.
            }
            results1[index] = ADC12MEM13;
            results2[index] = ADC12MEM14;
            index = index + 1;
        }

} //End of while (1) loop

} //End of Program

Every time I check ADC12MEM13 and 14, there are no correct conversion values. Can someone please design a code that works? I'm pretty sure this would only take 5 mins because this is the newest code that I've typed and it doesn't work either. : (

 

Thanks,

Dav

  • Well it's again me, trying to help you. I have modified your code, I have connected a 1Hz sine wave (1.5 Vpp and 1.25V offset) to my MSP430F5418A (which is quite similar) and it works.

     

     

    #define NumberOfResults 400

    volatile unsigned int results1[NumberOfResults];

    volatile unsigned int results2[NumberOfResults];

    void main (void)

    {

           int index = 0;
          
           /*Turns off the watch dog so the infinite loop to rst the program.*/
           WDTCTL = WDTPW + WDTHOLD;
          
          
           REFCTL0 &= ~(REFMSTR); // TODO: check if this is needed in MSP430F5438A
          
           P7SEL = BIT5 | BIT6; //Set P7.5(A13) & P7.6(A14) to analog input.
          
           /*Setting Control 0: Sample and hold cycle for ADC12MEM8 through ADC12MEM15 is 256 CLK cycles,
            * multiscan is enabled, 2.5[V] as the reference point, reference on, turns on the ADC.*/
           ADC12CTL0 = ADC12SHT1_8  | ADC12MSC | ADC12REF2_5V | ADC12REFON | ADC12ON;
          
          
           /*Setting Control 1: Starting conversion from MCTL13, SAMPCON signal is sourced from the sampling timer,
            * single-sequence-of-channels, divide clock by 4 to work around silicon bug ADC27. */
           ADC12CTL1 = ADC12CSTARTADD_13 | ADC12CONSEQ_1 | ADC12SHP | ADC12DIV_3;
          
           ADC12CTL2 = ADC12RES_2;
          
           /*Setting the ADC channel control */
           ADC12MCTL13 = ADC12SREF_1 | ADC12INCH_13;
           ADC12MCTL14 = ADC12SREF_1 | ADC12INCH_14 | ADC12EOS;
          
           ADC12CTL0 |= ADC12ENC;
          
           _delay_cycles(100000); // wait some time to let reference settle

           while(1)
           {
                 index = 0;
                
                
                 while(index < NumberOfResults)
                 {
                        ADC12CTL0 |= ADC12SC;
                        while(ADC12CTL1 & ADC12BUSY)
                        {
                               //Do nothing until the conversion sequence is finished.
                        }
                        results1[index] = ADC12MEM13;
                        results2[index] = ADC12MEM14;
                        index = index + 1;
                 }
          
           } //End of while (1) loop

    } //End of Program


    Note that you probably have to remove the line with REFCTL0 as it's not implemented in MSP430F5438 devices (if I understand the user guide correctly). I've set a breakpoint on the line index = 0; in the while loop and it runs fine and it samples fine.

    Also a clock division by 2 should be enough to work around that errata - with division by 4 you are on the safe side if you don't need a very high sampling rate.

     

  • THANKS BERNHARD! The conversion seems to work now, the current at least changes accordingly. The input channel 13 is actually not working. Its still randomizing different value and not displaying the correct value for voltage(MEM13) but at least the current(MEM14) works. Would you know why? And when I just turn the board on both MEM13 and 14 are 0 which is correct but when I touch P7.5 (A13) the LED light that I programmed to turn on when there is power turns on? I know that leaving a pin not connected it can read noise. P7.6 works, thanks again Bernhard. I just need A13 to read correctly and everything should be good to go.

  • So it seems that the ports are set up properly for A13. It does show signs of reaction when you touch it.

    However, there might be a problem with the external hardware. maybe you partially fried the pin?

    You say this pin is 'voltage', the other is 'current' (and working). What voltage? min/max? impedance?

    If Bernhard says that he has tested it and it works, then I think ishoudl work. For both channels. There is no reason why A14 will work and A13 won't.
    So most likely it's a hardware problem.

    Bernhard, the 5438 doe snto have a REF module. The references are controlled by ADC12.

    The 5438A, however, does have a REF module and the control of the references in the ADC12 module is disabled by default. A very incompatible change for a chip that should be used as replacement. And a severe pitfalls for everyone who wants to use his non-A code on this replacement. :( (and it's not the only difference)

     

  • Jens-Michael Gross said:
    If Bernhard says that he has tested it and it works, then I think ishoudl work. For both channels. There is no reason why A14 will work and A13 won't.
    So most likely it's a hardware problem.

    For my test I tied both pins to the same input (the output of a frequency generator) and the readings were fine for both of them.

    Jens-Michael Gross said:

    Bernhard, the 5438 doe snto have a REF module. The references are controlled by ADC12.

    The 5438A, however, does have a REF module and the control of the references in the ADC12 module is disabled by default. A very incompatible change for a chip that should be used as replacement. And a severe pitfalls for everyone who wants to use his non-A code on this replacement. :( (and it's not the only difference)

    This is driving me nuts...  This A and non-A differences are so confusing and I really don't like this double control over the reference as well, it took me a while to see why my implementation wasn't working as expected because the 5418A has the reference control register, so I had to disable it there to use the ADC12 bits - argh!

     

  • Bernhard Weller said:

    This is driving me nuts...  This A and non-A differences are so confusing and I really don't like this double control over the reference as well, it took me a while to see why my implementation wasn't working as expected because the 5418A has the reference control register, so I had to disable it there to use the ADC12 bits - argh!

    For the REF module, if REFMSTR would be clear by default, all would be well. Who's using the REF module would have to enable it first, else all is on teh ADC12 module as it always was.
    But someone decided to not do it. For some unknown reason.

    When starting with PC, I used GEOS with its Motif UI (pre-Win aera). It did have the close button on the top left corner, while on the top right corner of each window the resize buttons were.
    When Windows was introduced, guess how often i closed the wndow when I just wanted to maximize it?
    It is understaneable because these were two different products from different manufacturers. But I don't understand it for produces from the same manufacturer. (this includes several Mirosoft products where defaults suddenly changed in a harmful way). Especially when being backwards compatible doesn't introduce major implementation efforts.

**Attention** This is a public forum