CC2530 ADC study notes

CC2530 ADC study notes

The ADC of CC2530 supports up to 14-bit (actually 12-bit) analog-to-digital conversion. It includes an analog multiplexer with up to 8 independently configurable channels and a reference voltage generator.
The block diagram of the ADC is as follows:

It can be seen from the figure that the AD of CC2530 has various input channels such as AIN0~AIN7, VDD/3, temperature sensor, etc.
The sampling precision of CC2530 has four kinds: 7Bit, 9Bit, 10Bit, 12Bit. The sampling precision of ADC can be changed by configuring the ADCCON2 register and ADCCON3 register.

1. GPIO configuration

Since the AIN pin of the ADC is set at the P0 port, the register of the P0 port needs to be configured. The registers that need to be configured are: APCFG register, P0SEL register, P0DIR register (GPIO of CC2530 is input state by default).

register name Register introduction
APCFG P0.0~P0.7 analog IO function configuration
P0SEL P0.0~P0.7 peripheral function selection
P0DIR P0.0~P0.7 pin direction

Note: P0.0 corresponds to AIN0, P0.7 corresponds to AIN7;

Routine:

/** ADC AIN通道引脚定义 */
#define USE_P0_0_AS_ADC_CH0 (0x01)
#define USE_P0_1_AS_ADC_CH1 (0x02)
#define USE_P0_2_AS_ADC_CH2 (0x04)
#define USE_P0_3_AS_ADC_CH3 (0x08)
#define USE_P0_4_AS_ADC_CH4 (0x10)
#define USE_P0_5_AS_ADC_CH5 (0x20)
#define USE_P0_6_AS_ADC_CH6 (0x40)
#define USE_P0_7_AS_ADC_CH7 (0x80)

/**
 *******************************************************************************
 * @brief   ADC通道初始化函数
 * @param   [in/out]  channel    初始化通道
 * @return  [in/out]  void
 * @note    NONE
 *******************************************************************************
 */
void MCU_ADC_CH_Init( uint8 channel )
{
    APCFG |= channel;
    P0SEL |= channel;
    //P0DIR &= ~channel;
    //P0INP |= channel;
}

2. ADC configuration

ADC has 6 control registers, they are: ADCL register, ADCH register, ADCCON1 register, ADCCON2 register, ADCCON3 register, TR0 register.

1. Introduction to ADC data register

The ADCL register and ADCH register save the result of AD conversion, and the data is represented in 2's complement form. The following table shows the sampling accuracy and valid data analysis table:

Sampling accuracy valid data (low to high)
7 Bit Bits 0 to 6 of the ADCH register
9 Bit Bit 6 of ADCL register to Bit 6 of ADCH register
10 Bit Bit 5 of ADCL register to Bit 6 of ADCH register
12 Bit Bit 3 of ADCL register to Bit 6 of ADCH register

routine

/**
 *******************************************************************************
 * @brief       读取AD转换数值
 * @param       [in/out]  void
 * @return      [in/out]  bool    程序运行状态
 * @note        ADC工作在单次转换模式
 *******************************************************************************
 */
bool Rd_ADC_Data( uint16 *data, uint8 convert_bit )
{
    uint16 temp = (uint16)(ADCH << 8);
    temp |= (uint16)ADCL;

    if( !MCU_ADC_FLAG )
    {
        return false;
    }

    switch(convert_bit)
    {
        case ADC_CONVERT_7BIT:
            temp >>= 8;
            *data = temp & ~(1 << 8);
            break;
        case ADC_CONVERT_9BIT:
            temp >>= 5;
            *data = temp & ~(1 << 10);
            break;
        case ADC_CONVERT_10BIT:
            temp >>= 4;
            *data = temp & ~(1 << 11);
            break;
        case ADC_CONVERT_12BIT:
            temp >>= 2;
            *data = temp & ~(1 << 13);
            break;
        default:
            return false;
            break;
    }

    return true;
}

2. ADCCON1 register introduction

name Features take up space parameter enumeration
EOC ADC conversion complete flag 1 Bit -
- - - 0 (conversion not complete)
- - - 1 (conversion completed)
ST The software turns on the conversion bit 1 Bit -
- - - 0 (ADC has no conversion task)
- - - 1 (software trigger ADC conversion signal)
STSEL Configure AD conversion trigger signal 2 Bit
- - - 00 (P2.0 pin triggers AD conversion)
- - - 01 (ADC is always in conversion state, not waiting for trigger signal)
- - - 10 (timer 0 channel 1 comparison event triggers AD conversion)
- - - 11 (ST trigger AD conversion)
RCTRL Controls the 16-bit random number generator 2 Bit not introduce
- Reserve 2 Bit -

3. ADCCON2, ADCCON3 register introduction

name Features take up space parameter enumeration
REF ADC conversion reference voltage 2 Bit -
- - - 00 (use internal reference voltage)
- - - 01 (Use the external point voltage on the AIN7 pin as the reference voltage)
- - - 10 (use AVDD5 as reference voltage)
- - - 11 (use AIN6-AIN7 differential input external voltage as reference voltage)
DIV ADC conversion decimation rate (conversion time and conversion accuracy) 2 Bit -
- - - 00 (conversion precision is 7)
- - - 01 (conversion precision is 9)
- - - 10 (conversion precision is 10)
- - - 11 (conversion precision is 12)
CH ADC sampling channel 4 Bit -
- - - 0000 (configure ADC sampling channel as AIN0)
- - - 0001 (configure ADC sampling channel as AIN1)
- - - 0010 (configure ADC sampling channel as AIN2)
- - - 0011 (configure ADC sampling channel as AIN3)
- - - 0100 (configure ADC sampling channel as AIN4)
- - - 0101 (configure ADC sampling channel as AIN5)
- - - 0110 (configure ADC sampling channel as AIN6)
- - - 0111 (configure ADC sampling channel as AIN7)
- - - 1000 (configure ADC sampling channel as AIN0-AIN1 voltage)
- - - 1001 (configure ADC sampling channel as AIN2-AIN3 voltage)
- - - 1010 (configure ADC sampling channel as AIN4-AIN5 voltage)
- - - 1011 (configure ADC sampling channel as AIN6-AIN7 voltage)
- - - 1100(GND)
- - - 1101 (positive reference voltage)
- - - 1110 (temperature sensor)
- - - 1111(VDD/3)

Configure the ADCCON2 register to complete the cyclic AD conversion, and configure the ADCCON3 register to complete the single AD conversion.

Routine:

// AD参考电压配置
#define ADC_SREF_VREF       (0x00)
#define ADC_SREF_AIN7       (0x01)
#define ADC_SREF_AVDD       (0x02)
#define ADC_SREF_AIN6_AIN7  (0x03)

// AD转换精度
#define ADC_CONVERT_7BIT    (0x00)
#define ADC_CONVERT_9BIT    (0x10)
#define ADC_CONVERT_10BIT   (0x20)
#define ADC_CONVERT_12BIT   (0x30)

// AD转换通道
#define ADC_CONVERT_CH0     (0x00)
#define ADC_CONVERT_CH1     (0x01)
#define ADC_CONVERT_CH2     (0x02)
#define ADC_CONVERT_CH3     (0x03)
#define ADC_CONVERT_CH4     (0x04)
#define ADC_CONVERT_CH5     (0x05)
#define ADC_CONVERT_CH6     (0x06)
#define ADC_CONVERT_CH7     (0x07)
// AD转换差分输入信号
#define ADC_CONVERT_CH0_CH1 (0x08)
#define ADC_CONVERT_CH2_CH3 (0x09)
#define ADC_CONVERT_CH4_CH5 (0x0A)
#define ADC_CONVERT_CH6_CH7 (0x0B)
// AD转换其它信号
#define ADC_CONVERT_GND     (0x0C)
#define ADC_CONVERT_VREF    (0x0D)
#define ADC_CONVERT_TEMP    (0x0E)
#define ADC_CONVERT_VDD_3   (0x0F)

// 启动ADC转换
#define MCU_ADC_START()     ( ADCCON1 |= 0x70 )
// ADC转换完成标识
#define MCU_ADC_FLAG        ( ADCCON1 & 0x80 )
// 使能AD转换中断
#define enable_adc_isr()    (IEN0 |= 0x02)
//失能AD转换中断
#define disable_adc_isr()   (IEN0 &= ~0x02)

/**
 *******************************************************************************
 * @brief       ADC启动单次转换函数
 * @param       [in/out]  channel        转换通道
 * @param       [in/out]  convert_bit    转换数据打小
 * @return      [in/out]  void
 * @note        None
 *******************************************************************************
 */
void MCU_ADC_SIGNAL_START( uint8 adc_ref, uint8 channel, uint8 convert_bit )
{
    ADCCON3 = adc_ref | channel | convert_bit;
    enable_adc_isr();
    MCU_ADC_START();
}

3. References

[1]. CC2530 data sheet

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325721519&siteId=291194637