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.

[参考译文] TMS570LS1224:Hercules ADC -多通道的单个呼叫读取

Guru**** 2382480 points
Other Parts Discussed in Thread: HALCOGEN
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1440453/tms570ls1224-hercules-adc---single-call-read-of-multiple-channels

器件型号:TMS570LS1224
主题中讨论的其他器件:HALCOGEN

工具与软件:

尊敬的社区:

我有以下适用于 Hercules ADC 的 HALCoGen 配置... 正如预期的那样、图像中选择的引脚会影响 s_adcSelect[2U][3U]的值:

然后,我正按照官方的例子,建议:

adcStartConversion(adcREG1, adcGROUP1);
while(!adcIsConversionComplete(adcREG1, adcGROUP1));
adcGetData(adcREG1, adcGROUP1, &adc_data);


adcStartConversion 生成的代码使用2d 数组(s_adcSelect)、这使我认为所有已配置的通道都可以在一次调用中处理。 我想这可以生成 ADC 序列发生器 跳过所有选定通道、并将结果保存到键值对样式的某个数组中( PinID 转换后的值)。

void adcStartConversion(adcBASE_t *adc, uint32 group)
{
    uint32 index = (adc == adcREG1) ? 0U : 1U;

/* USER CODE BEGIN (7) */
/* USER CODE END */

    /** - Setup FiFo size */
    adc->GxINTCR[group] = s_adcFiFoSize[index][group];

    /** - Start Conversion */
    adc->GxSEL[group] = s_adcSelect[index][group];

    /**   @note The function adcInit has to be called before this function can be used. */

/* USER CODE BEGIN (8) */
/* USER CODE END */
}

然而、在 adcGetData 实现中、我没有看到对通道(引脚)有任何迭代、仅在 FIFO 大小上出现了迭代(至少我可以观察到这个情况 UINT32计数  将变量设置为等于 HALCoGen 中配置的 FIFO 大小):

uint32 adcGetData(adcBASE_t *adc, uint32 group, adcData_t * data)
{
    uint32  i;
    uint32  buf;
    uint32  mode;    
    uint32  index = (adc == adcREG1) ? 0U : 1U;

	uint32  intcr_reg = adc->GxINTCR[group];
    uint32  count = (intcr_reg >= 256U) ? s_adcFiFoSize[index][group] : (s_adcFiFoSize[index][group] - (uint32)(intcr_reg & 0xFFU));
    adcData_t *ptr = data; 

/* USER CODE BEGIN (16) */
/* USER CODE END */

    mode = (adc->OPMODECR & ADC_12_BIT_MODE);

    if(mode == ADC_12_BIT_MODE)
      {
        /** -  Get conversion data and channel/pin id */
        for (i = 0U; i < count; i++)
        {
          buf        = adc->GxBUF[group].BUF0;
		  /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
          ptr->value = (uint16)(buf & 0xFFFU);
          ptr->id    = (uint32)((buf >> 16U) & 0x1FU);
          /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
		  ptr++;
        }
      }
      else
      {
        /** -  Get conversion data and channel/pin id */
        for (i = 0U; i < count; i++)
        {
          buf        = adc->GxBUF[group].BUF0;
		  /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
          ptr->value = (uint16)(buf & 0x3FFU);
          ptr->id    = (uint32)((buf >> 10U) & 0x1FU);
          /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
		  ptr++;
        }
      }


    adc->GxINTFLG[group] = 9U;

    /**   @note The function adcInit has to be called before this function can be used.\n
    *           The user is responsible to initialize the message box.
    */

/* USER CODE BEGIN (17) */
/* USER CODE END */

    return count;
}

即使仅设置时也是如此 通道6 作为一个有源缓冲区(Launchpad 上的光晶体管连接在此处)、我得到 adcData_t->id 字段为零:

adcStartConversion(adcREG1, adcGROUP1);
while(!adcIsConversionComplete(adcREG1, adcGROUP1));
adcGetData(adcREG1, adcGROUP1, &adc_data);
printf("Pin: %u ADC: %u\n", adc_data.id, adc_data.value);


And below is my printf log:
Pin: 0 ADC: 806

我的问题是:考虑到 API 的架构、是否可以向 ADC 发送单个"调用"并让序列发生器跳过每个选定通道并返回每个通道的 PinID-AdcValue (如果可能、使用 HALCoGen 配置中的实际引脚 ID)?

谢谢!