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.

ADC problems MSP430FG4618

Other Parts Discussed in Thread: MSP430FG4618

Hello

I'm trying to use only the A15 ADC channel usign the MSP430FG4618 but I'm not getting to make it work, I hope you guys can help me configure correctly to have this done.

My ADC configuration is attached.

Best Regards,

Pascal.

 

#include "msp430fg4618.h"

void ADC_init(void);
void Clock_init(void);

unsigned int sample;

void main (void){

    WDTCTL = WDTPW | WDTHOLD; 

    ADC_init();
    
    for(;;){
        ADC12CTL0 |= ADC12SC;                   // Start conversions
   	while (!(ADC12IFG & 0x8000));           // Conversion done?
    	sample = ADC12MEM15;
    }

}

void ADC_init(void){

unsigned int i;
	
   	/* Configure ADC12 */
	P10SEL |= BIT6;                         // Enable A/D channel A0
    	ADC12CTL0 &= ~ENC;                      // Enable conversions

    	ADC12CTL0 = ADC12ON + SHT1_2 + REFON + REF2_5V;
    	ADC12CTL1 = SHS_0 + CONSEQ_2 + CSTARTADD_15;           

	ADC12MCTL15 = INCH_15 + SREF_1;
    
	for (i = 0x3600; i; i--);               // Delay for needed ref start-up.
                                            	// See datasheet for details.
    
   	ADC12CTL0 |= ENC;                       // Enable the ADC   

}

void Clock_init(void){

   /*
   Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz
   This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error
   */
   FLL_CTL0 = (DCOPLUS | XCAP14PF);       //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 14pF
   SCFI0 = (FLLD_2 | FN_8);               //Set Multiplier to 2, and DCO range to 8MHz nominal
   SCFQCTL = 121;                         //7.995392Mhz Operation with No Modulation

    // Loop until 32kHz crystal stabilizes
    do
    {
      IFG1 &= ~OFIFG;                       // Clear oscillator fault flag
	  _delay_cycles(50000);
    }
    while (IFG1 & OFIFG);                   // Test osc fault flag	

}

  • Are you able to get any of the examples to work for the MSP430FG4618 just to verify basic functionality?

     

  • Yes! But those are configured to channel A0 and MEM0, so when I try to change to A15 is not working...

    Why am I want that? This is because I'm using P10.6 and I want it as an ADC.

    Best Regards,

    Pascal.

  • Pascal Hernandez said:

    Yes! But those are configured to channel A0 and MEM0, so when I try to change to A15 is not working...

    I realize this.  I just wanted to make sure that you are able to get the examples working with the ADC properly performing conversions.  Now we need to migrate to your desired channel A15 on P10.6.

    As an experiment, would you modify one of the examples from A0 to target A15?  You can use ADC12MCTL0 and ADC12MEM0 and assign it to channel A15.  I would suggest converting the code example msp430xG46x_adc12_07.c to target A15.

    See if this generates the results you desire and then you can tailor your code accordingly.

     

    #include "msp430xG46x.h"

    volatile unsigned int Results[8];
    unsigned int Index;

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                         // Stop watchdog timer
      P10SEL |= 0x01;                                                           // Enable A/D channel A15 pin
      ADC12CTL0 = ADC12ON + SHT0_8 + MSC;       // Turn on ADC12, set sampling time
      ADC12CTL1 = SHP + CONSEQ_2;                        // Use sampling timer, set mode
      ADC12IE = 0x01;                                                        // Enable ADC12IFG.0
      ADC12MCTL0 = INCH_15 + SREF_1;                  // Setup ADC12MCTL0 to convert channel A15 and use Vref+, AVss
      ADC12CTL0 |= ENC;                                                // Enable conversions
      __enable_interrupt();                                               // Enable interrupts
      ADC12CTL0 |= ADC12SC;                                      // Start conversion
      __bis_SR_register(LPM0_bits);                            // LPM0
    }

    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    {
      Results[Index++] = ADC12MEM0;                         // Move result, IFG is cleared
      Index &= 0x07;                                                          // Modulo pointer
      __no_operation();                                                   // SET BREAKPOINT HERE
    }

  • Hello,

    Thanks for your help! I made it in a different way (because I can not use interrupts) and this was the results.

     

    #include "msp430xG46x.h"
    
    volatile unsigned int i;
    
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog
     
      	ADC12CTL0 &= ~ENC;                     	// Disable Conversions    
      
      	ADC12CTL0 = REFON + REF2_5V + ADC12ON + SHT0_2 + MSC;
                                                // turn on 2.5V ref, set samp time
                                                // Multiple sample and conversion
      	ADC12CTL1 = SHP + CONSEQ_3;             // Use sampling timer
      											// Sequence of channels
      	ADC12MCTL0 = SREF_1 + INCH_1;           // Vr+=Vref+
      											// Input Channel A1 = OA0
      											// FINAL ANALOG OUTPUT
     	ADC12MCTL1 = SREF_1 + INCH_3;     		// Vr+=Vref+
      											// Input Channel A3 = OA1 
      											// TRANSIMPEDANCE OUTPUT  											
     	ADC12MCTL2 = SREF_1 + INCH_15 + EOS;     // Vr+=Vref+
      											// Input Channel A3 = OA1 
      											// Battery Input
    
      	_delay_cycles(3600);					// Delay for needed ref start-up.
                                                // See datasheet for details.
    							                
      	ADC12CTL0 |= ENC;                       // Enable conversions
     	ADC12CTL0 |= ADC12SC;                   // Start conversions
    
    
      while (1)
      {
        ADC12CTL0 |= ADC12SC;                   // Start conversions
        while (!(ADC12IFG & 0x8003));           // Conversion done?
        ADC12MEM1;                              // Access result
        ADC12MEM2;                              // Access result
        ADC12MEM3;                              // Access result
        __no_operation();                       // SET BREAKPOINT HERE
      }
    }
    
    

     

    Best Regards,

    Pascal.

     

     

**Attention** This is a public forum