Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ADC code not working for MSP430

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
Here is the requirement...

The sensor connected to channel A15 (Port pin P7.7) is to be read as ADC input and its equivalent count to display.

I have written a code for it but unfortunately I dont get nothing in the count Register.

Code:
UINT16_T u16Count;
  
  P7SEL |= 0x80;	//P7.7 = A15 channel is connected to TempSensor
  //P7DIR |= 0x80;  
  /* Initialize ADC12 */
  ADC12CTL0 = ADC12ON+ADC12SHT0_2+ADC12REF2_5V;       // Turn on ADC12, set sampling time,            //internal reference 2.5V
  ADC12CTL1 = ADC12SHP + ADC12CONSEQ_2 + ADC12SSEL1;  // Use sampling timer, set clock src          
  ADC12MCTL15 = ADC12INCH_15 + ADC12SREF_1;  // Vr+ = VeREF+ (int) and Vr-=AVss
  ADC12CTL1 = ADC12RES_2;
  Delay_ms(50);
  ADC12CTL0 |= ADC12ENC + ADC12SC;          // Enable and start conversions
 while (!(ADC12IFG & ADC12IFG15));
 // while (!(ADC12IFG ));
  u16Count = ADC12MEM15;

the execution doesnt cross while loop which means ADC12IFG15 flag is not set.

Any suggestion?
 

you arre trying to use inbuild Sensor or u have connected external one ?
Also, have you enabled ADC112 bit in ADC12CTL0 register.
 
ADC is enabled

An external sensor is interfaced.

Now, the flag which indicates that corresponding ADC12MEMx memory register is loaded with a conversion result is set but the ADC12MEMx contains 0000. Wondering what is going wrong now... :-?
 

there is no register setting to the external sensor....it is simple RTD.
 

MSP430F5418A and CCS4 compiler.

Initially I used single reading on a channel, now I am trying sequence reading on a channel. And to my surprise all readings are 0 :-( .

I have simply connected a 120 Ohm resistor to the signal conditioning circuit whose o/p is given to ADC channel.

https://www.ti.com/product/msp430f5418A

- - - Updated - - -

Code:
P7SEL |= BIT7;                     	   // Enable VeREF+ & A/D channel A15 
P7DIR &= 0xEF; 
/* Initialize ADC12_A */ 
  ADC12CTL0 = ADC12ON+ADC12SHT0_12+ADC12MSC; // Turn on ADC12, set sampling time
                                            // set multiple sample conversion
  ADC12CTL1 = ADC12CSTARTADD_15+ADC12SHP+ADC12CONSEQ_2;       // Use sampling timer, set mode
  ADC12IE = ADC12IE15;                           // Enable ADC12IFG.15
  ADC12CTL2 = ADC12RES_2;
  
  ADC12CTL0 |= ADC12ENC;                   // Enable conversions
  ADC12CTL0 |= ADC12SC;                    // Start conversion-software trigger

- - - Updated - - -

Code:
// ADC12 interrupt service routine
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
static UINT8_T Buf[10];
static UINT8_T Index=0;

     switch(__even_in_range(ADC12IV,36))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6:                                  // Vector  6:  ADC12IFG0
    
      
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12: break;                           // Vector 12:  ADC12IFG3
  case 14: break;                           // Vector 14:  ADC12IFG4
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30: break;                           // Vector 30:  ADC12IFG12
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  case 36: 
  Buf[Index] = ADC12MEM15;             // Move results
    Index++;                                // Increment results index, modulo; Set Breakpoint1 here
   
    if (Index == 10)
      Index = 0;                            // Reset the index; Set Breakpoint here 
  break;
  default: break; 
  }
}


This is the code and ISR
 

Couple of suggestions -
1) First check that board is out of reset - RST is pulled up...
2) From the code or data sheet I am not able to find out how you are deriving the ADC clock...In most of the case there will be a register to set-up that ... I think you need to study the Operating mode of chip very clearly...
3) Reference voltage....try to check that proper reference voltage is available on the Pin of IC ... measure using multimeter...

I hope these points will give you some clue...

Good Luck
 

I guess that the RTD is not able to get the input. Signal conditioning problem. The value must be less than Threshold Voltage (Ref. voltage) so it is reading ZERO.
 
I could resolve the problem.

The sampling frequency was set as 8MHz however, CPU ADC supports max freq of 4MHz. Now, it is working. :p
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top