MSP430F5529 ADC Reference

Publisher:技术掌门Latest update time:2019-03-14 Source: eefocusKeywords:MSP430F5529 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

MSP430F5529 ADC Reference Notes


1.ADC12_A initialization parameters

typedef struct ADC_MemMap

{

  union

  {

    uint16_t CTL0;

    struct

    {

      uint16_t SC             :1;  /* ADC12 Start Conversion */

      uint16_t ENC            :1;  /* ADC12 Enable Conversion */

      uint16_t TOVIE          :1;  /* ADC12 Timer Overflow interrupt enable */

      uint16_t OVIE           :1;  /* ADC12 Overflow interrupt enable */

      uint16_t ON             :1;  /* ADC12 On/enable */

      uint16_t ADCREFON       :1;  /* ADC12 Reference on */

      uint16_t REF2_5V        :1;  /* ADC12 Ref 0:1.5V / 1:2.5V */

      uint16_t MSC            :1;  /* ADC12 Multiple SampleConversion */

      uint16_t SHT0           :4;  /* ADC12 Sample Hold 0 Select  */

      uint16_t SHT1           :4;  /* ADC12 Sample Hold 1 Select  */

    };

  };

  union

  {

    uint16_t CTL1;

    struct

    {

      uint16_t ADBUSY         :1;    /* ADC12 Busy */

      uint16_t CONSEQ         :2;    /* ADC12 Conversion Sequence Select  */

      uint16_t SSEL           :2;    /* ADC12 Clock Source Select  */

      uint16_t DIV            :3;    /* ADC12 Clock Divider Select  */

      uint16_t ISSH           :1;    /* ADC12 Invert Sample Hold Signal */

      uint16_t SHP            :1;    /* ADC12 Sample/Hold Pulse Mode */

      uint16_t SHS            :2;    /* ADC12 Sample/Hold Source  */

      uint16_t CSTARTADD      :4;    /* ADC12 Conversion Start Address  */

    };

  };

  union

  {

    uint16_t CTL2;

    struct

    {

      uint16_t REFBURST       :1;    /* ADC12+ Reference Burst */

      uint16_t ADCREFOUT      :1;    /* ADC12+ Reference Out */

      uint16_t SR             :1;    /* ADC12+ Sampling Rate */

      uint16_t DF             :1;    /* ADC12+ Data Format */

      uint16_t RES            :2;    /* ADC12+ Resolution  */

      uint16_t TCOFF          :1;    /* ADC12+ Temperature Sensor Off */

      uint16_t PDIV :1; /* ADC12+ predivider 0:/1 1:/4 */

    };

  };

  uint16_t RESERVED_1[2];

  uint16_t IFG;

  uint16_t IE;

  uint16_t IV;

  struct

  {

      uint8_t INCH            :4;     /* ADC12 Input Channel Select*/

      uint8_t REF             :3;     /* ADC12 Select Reference  */

      uint8_t EOS             :1;     /* ADC12 End of Sequence */

  }MCTL[16];

  uint16_t MEM[16];

}volatile * ADC_MemMapPtr;


#define ADC12_SSEL_ADC12OSC       0

#define ADC12_SSEL_ACLK           1                   

#define ADC12_SSEL_MCLK           2

#define ADC12_SSEL_SMCLK          3   


#define ADC12_SREF_0            0

#define ADC12_SREF_1            1

#define ADC12_SREF_2            2

#define ADC12_SREF_3            3

#define ADC12_SREF_4            4

#define ADC12_SREF_5            5

#define ADC12_SREF_6            6

#define ADC12_SREF_7            7


#define ADC_BASE_PTR                     ((ADC_MemMapPtr)__MSP430_BASEADDRESS_ADC12_PLUS__)


1.1 Initialized channels and pins

typedef enum

{

  ADC_CH0        =BIT0,  //P6.0

  ADC_CH1        =BIT1,  //P6.1

  ADC_CH2        =BIT2,  //P6.2

  ADC_CH3 = BIT3, //P6.3

  ADC_CH4        =BIT4,  //P6.4

  ADC_CH5        =BIT5,  //P6.5

  ADC_CH6        =BIT6,  //P6.6

  ADC_CH7        =BIT7,  //P6.7

  ADC_CH8 =BIT8, //VeREF+ //External positive reference

  ADC_CH9 =BIT9, //VeREF- //External negative reference

  ADC_CH10 =BITA, //On-chip temperature sensor

  ADC_CH11 =BITB, //(AVCC-AVSS)/2

  ADC_CH12       =BITC,  //P7.0

  ADC_CH13       =BITD,  //P7.1

  ADC_CH14       =BITE,  //P7.2

  ADC_CH15 =BITF, //P7.3

  ADC_CH_NUM =16u, //Number of channels

}ADC_CHn; //Channel


1.2 Reference voltage

typedef enum

{

  ADC_VREF_1_5V , //Internal 1.5V

  ADC_VREF_2_5V , //Internal 2.5V

  ADC_VREF_3_3V , //supply voltage as reference voltage

  ADC_VREF_External, //Use external reference voltage

}ADC_VREF; //reference voltage


It is worth noting that the reference manual explains as follows 

 3 

The sampling voltage of the microcontroller is not allowed to exceed the reference voltage: 

Nadc=4095∗Vin−VR−VR+−VR−

Nadc=4095∗Vin−VR−VR+−VR−


According to the reference formula, it must be less than the reference voltage. If it exceeds the reference voltage, the output can only reach the maximum reference voltage, and the microcontroller may also be burned out.

1.3 Conversion Accuracy

typedef enum

{

  ADC_8bit, //8-bit precision, maximum value 256-1

  ADC_10bit, //10-bit precision, maximum value 1024-1

  ADC_12bit, //12-bit precision, maximum value 4096-1

}ADC_Resolution; //Accuracy


2 Initialization

/*******************************************************************************

* Function name: ADC_Init(uint16_t ch,ADC_VREF Vref,ADC_Resolution nBit)

* Function description: ADC initializes one or more ADC channels

* Parameter Description:

            uint16_t ch : channel to initialize

            ADCVREF Vref : reference voltage

            ADC_Resolution nBit : Conversion accuracy

* Function returns: None

********************************************************************************/

void ADC_Init(uint16_t ch,ADC_VREF Vref,ADC_Resolution nBit)

{

  ADC12->ENC = DISABLE; //Reset this bit first, otherwise some registers cannot be operated after setting it

  uint16_t SREF_RegValue = 0u;

  switch(Vref) //Select reference voltage

  {

  case ADC_VREF_1_5V:

    REFCTL0 &=~ REFMSTR; //Give control of REF reference voltage to ADC

    ADC12->ADCREFON = BIT_SET;

    ADC12->REF2_5V = RESET;

    SREF_RegValue = ADC12_SREF_1; //Use the internal reference voltage

    break;

  case ADC_VREF_2_5V:

    REFCTL0 &=~ REFMSTR;

    ADC12->ADCREFON = BIT_SET;

    ADC12->REF2_5V = BIT_SET;

    SREF_RegValue = ADC12_SREF_1; //Use the internal reference voltage

    break;

  case ADC_VREF_External:      

    P5SEL |= BIT0;       //VeREF+

    P5SEL |= BIT1;       //VeREF-

    SREF_RegValue = ADC12_SREF_2; //Use external reference voltage

  case ADC_VREF_3_3V:

    SREF_RegValue = ADC12_SREF_0; //Use the power supply voltage as the reference voltage,

    break;

  default :break;

  }

  // Initialize the channel

  uint16_t CH_Mask = 0x01;

  for(uint8_t CH_Num=0; CH_Num < ADC_CH_NUM; CH_Num++)

  {

    if(ch & CH_Mask) //Channel to be initialized

    {

      if((CH_Mask & InitialedChannel_Bit) == 0) //If the channel has not been initialized               

      {

        ADC12->MCTL[InitialedChannel_Num].INCH = CH_Num;

        ADC12->MCTL[InitialedChannel_Num].REF = SREF_RegValue; //reference voltage selection, channel setting

        ADC_Channel_Bit[InitialedChannel_Num] = CH_Mask; //Set the channel initialization flag InitialedChannel_Bit |= CH_Mask; //Set the initialized channel flag

        InitialedChannel_Num ++; //Initialized channel number plus 1

      }

      else //If the channel has been initialized before, you need to reset it here and only set the channel reference voltage

      {

        ADC12->MCTL[ADC_GetChanelNum((ADC_CHn)CH_Mask)].REF = SREF_RegValue; //Change reference voltage            

      }

    }

    CH_Mask <<= 1;

  }

  if(InitialedChannel_Num > 1) //When there are multiple channels, add the end bit of the sequence channel

  {

    for(int i=0; i<(InitialedChannel_Num-1); i++) //Clear all previous channel sequence end bits

    {

      ADC12->MCTL[i].EOS = RESET;

    }

    ADC12->MCTL[InitialedChannel_Num-1].EOS = BIT_SET; //The last channel plus the sequence channel conversion end bit

  }

  //General configuration

  ADC12->SHT0 = M0_M7_SAMPLE_HOLD_TIME; //0-7 channel sampling and holding time

  ADC12->SHT1 = M8_M15_SAMPLE_HOLD_TIME; //8-15 channel sampling and holding time

  ADC12->ON = BIT_SET;/ Sampling time, AD core is turned on

  ADC12->MSC = BIT_SET;

  ADC12->SSEL = ADC12_SSEL_ADC12OSC; //Clock selection

  ADC12->SHP = BIT_SET;

  //When there are multiple channels, set it to the sequential channel single conversion mode, and when there is a single channel, set it to the single channel single conversion mode   

  ADC12->CONSEQ = (InitialedChannel_Num > 1) ? BIT_SET : RESET;        

  //Set ADC accuracy

  ADC12->RES = nBit;    

  //Start the clock

  UCS->MODOSC_REQEN = BIT_SET; //ADC uses MODCLK, so configure the clock here, about 5MHz

  //Configure the channel as the second function

  if(ch & 0x00ff)

  {

     GPIO_MultiBits_Init(P6,(ch & 0x00ff),GPI | SEL);

  }

  if(ch & 0xf000)

  {

     GPIO_MultiBits_Init(P7,((ch & 0xf000)>>12),GPI | SEL);

  }

  if(ch & ADC_CH10) //If the temperature sensor channel is used, turn on the temperature sensor

  {

    ADC12->TCOFF = RESET;

  }

  ADC12->ENC = ENABLE; //This bit must be set after initialization is completed

  //DELAY_MS(5); //Delay to wait for reference voltage to be established

}


Here the sampling and holding interval


//Macro definition ADC12MEM8 to ADC12MEM15 sampling and holding time 0-15

#define M8_M15_SAMPLE_HOLD_TIME  3

//Macro definition ADC12MEM0 to ADC12MEM7 sampling and holding time 0-15

#define M0_M7_SAMPLE_HOLD_TIME   3


be careful 

1. After initialization, the accuracy of all channels is the same, that is, the conversion accuracy of all channels depends only on the accuracy of the last configuration. 

2. The internal reference voltage of all channels can only use one of 1.5V or 2.5V


Example of use:


ADC_Init(ADC_CH1+ADC_CH3,ADC_VREF_1_5V,ADC_10bit);        

// Initialize two channels at the same time, using the internally provided 1.5V reference voltage, 10-bit accuracy

1

2

3. Sampling Examples

/*!

*     COPYRIGHT NOTICE

*     Copyright (c) 2016,CTGU-GB

*     All rights reserved.

*

*

* @file       main.c

* @brief MSP430F5529 platform main program


* @author     CTGU-GB

* @version    v2.7

* @date       2016-11-26

*/

#include "include.h"

double adcDataTest[20];

/*******************************************************************************

* Function name: ADC_Filter(u32 num,double *adcDataStorage)

* Function description: ADC filter function

* Author: klaus Email: xcf2016a@outlook.com

* Parameter description: uint8_t num: number of input filter data

* double *adcDataStorage: filter array

* Function returns: filtering result

********************************************************************************/

double ADC_Filter(uint8_t num,double *adcDataStorage)

{

  uint8_t i,j,k;

  uint8_t noswap=1;

  double adc_sum_tmp=0,adc_ave_tmp=0;


  for(i=0;i

      for(j=0;j

      {

          if(adcDataStorage[j]>adcDataStorage[j+1]){

              adcDataStorage[j]=adcDataStorage[j]+adcDataStorage[j+1];

              adcDataStorage[j+1]=adcDataStorage[j]-adcDataStorage[j+1];

              adcDataStorage[j]=adcDataStorage[j]-adcDataStorage[j+1];

              noswap=0;

          }

       }

      if(noswap) break;

  }

  for(k=2;k

  //adc_sum_tmp -= (adcDataStorage[0]+adcDataStorage[1]+adcDataStorage[num-2]+adcDataStorage[num-1]);    

  adc_ave_tmp=adc_sum_tmp/(num-4);

  adc_sum_tmp=0;


  return adc_ave_tmp;

}


void main()

{

  DisableInterrupts(); //Disable total interrupts


  LED_Init(LED_ALL); //LED light initialization

  OLED_Init();


  ADC_Init(ADC_CH2,ADC_VREF_3_3V,ADC_10bit); //Initialize channel, P6.1


  while(1)

  {  


    int i;

    for(i=0;i<20;i++)

    {

      adcDataTest[i]=ADC_ReadChanelOnce(ADC_CH2)*3.3/1023;

      DELAY_MS(10);

    }

    double ad = ADC_Filter(20,adcDataTest);

    OLED_PrintfAt(FONT_ASCII_8X16,0,0,"ADValue:\n%.3f V",ad); //Print at the specified position


  }

}

Keywords:MSP430F5529 Reference address:MSP430F5529 ADC Reference

Previous article:How to read IIC bus data in IIC silent mode using IIC_Recv
Next article:MSP430 Interrupt Parameters

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号