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.

Having a problem understanding the ADC12

I have a Launchpad (the USB 5529 version) that I have been trying to use to get up to speed on the MSP430 (I am coming from a PIC world).  I've looked at the example code that you can get CC to generate, but I am having issues understanding how to get the ADC to do what I want.

All I really want to do is sample a pin as fast as is reasonable and toggle a pin so I can figure out how fast I am going. 

My code looked like:

	WDTCTL = WDTPW + WDTHOLD;		// Halt the dog

    // MSP430 USB requires a Vcore setting of at least 2.  2 is high enough
	// for 8MHz MCLK, below.
    PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);

    //for the ADC
    REFCTL0 &= ~REFMSTR;                      // Reset REFMSTR to hand over control to
	 //Enable ADC12, enable internal ref, set to 2.5V, 4 ADC clock cycles sample/hold
	  ADC12CTL0 = ADC12ON + ADC12REFON + ADC12REF2_5V + ADC12SHT0_0;
                                              // Internal ref = 1.5V
	  //Repeat multiple channels, ACLK, clock divider is /1, use the sampling timer
	  ADC12CTL1 = ADC12SSEL_1 + ADC12DIV_0 + ADC12SHP;
	  //12 bit resolution -> 13 clock cycle conversion
	  ADC12CTL2 = ADC12RES_3;
    ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10;  // ADC i/p ch A10 = temp sense i/p

	ADC12IE = 0x001;                          // ADC_IFG upon conv result-ADCMEMO
	__delay_cycles(100);                       // delay to allow Ref to settle
	ADC12CTL0 |= ADC12ENC;

and I sit in a while look waiting on my flag to be set in the interrupt routine.  Is anyone able to spot my issue or point me to some code that helps clear it up?

Thanks!

  • Jason Matusiak said:
    ADC12CTL0 |= ADC12ENC;

    After this line, do you ever actually start the conversion by setting ADC12SC?

    Jason Matusiak said:
    ADC12CTL1 = ADC12SSEL_1 + ADC12DIV_0 + ADC12SHP;

    Any reason why you use ACLK as conversion clock? By default, ACLK is sourced by REFO, which is 32kHz. This is far below the minimum conversion clock required for reliable conversion. Note that this clock selection does not define the sampling frequency (conversion trigger frequency). It controls the timing of the S&H stage as well as of the 13 conversion steps. Well, with ADC12SHP and ADC12MSC set, the clock source indirectly controls sampling frequency for repeated single and sequence conversions. However, with the default ADC12SHS_0 it still requires an initial trigger by ADC12SC.
    Still, the clock has to be between 400kHz and 6MHz (or so) to reach the specified performance (precision etc.)

  • I am VERY sorry for my late reply, I never got email notification that someone responded.  I cleaned things up a little bit in between and now it is sampling OK (you were right about me not starting the sample), but I might still be doing it too slow. 

    I was reusing code I found online, so my lack of experience was why I am not using something faster.  Realding your response and the datasheet, would the more accurate thing to do be to set:

    ADC12CTL1 = ADC12SSEL_2 + ADC12DIV_0 + ADC12SHP;

    I believe that that will have it run off of MCLK instead of ACLK?

  • Jason Matusiak said:
    ADC12CTL1 = ADC12SSEL_2 + ADC12DIV_0 + ADC12SHP;
    I believe that that will have it run off of MCLK instead of ACLK?

    It will. But it has some drawbacks (well, as usual, it depends on your application parameters):
    You cannot go into LPM>0 since the ADC requires MCLK. Also, it limits your choice for MCLK as the ADC12 has some limitations in minimum and maximum clock speed (see datasheet).

    You can simply use ADC12SSEL_0 (which is the default) and use the MODOSC which is running at the upper limit of the allowed range. Depending on the MSP specific limits and your hardware (e.g. using internal reference? Is it externally buffered?) you might want to use a /2 or /3 divider.

    As usual, the MSP offers lots of possibilities to do things. Which ones make sense and which ones don't, depends on your specific application.

  • Perfect, thank you.  By setting it to ADC12SSEL_0, I was able to get the speed I was expecting out of it.  

    I still have a lot to learn and coming from the PIC family of uC, the learning curve in the way things are setup/done, is a little daunting at times.  Thanks for the help, this perfectly solved it for me!

**Attention** This is a public forum