本帖最后由 plan_1 于 2021-6-3 17:03 编辑
现有问题就是 采用软件触发多通道采集ADC,开启了PB的所有通道,通道直接接GND都不能为0之所以用软件触发,就是不想用中断触发AD
时钟配置为clock配置工具配置的,具体见图
引脚配置也是工具生成的,如下图
#include "M487EADC.h"
uint32_t ADCpin = BIT15 | BIT14 | BIT11 | BIT10 | BIT9 | BIT8 | BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1 | BIT0;
uint32_t ADCInputModePin = 0xcfff;
//uint32_t ADCpin = BIT7|BIT6;
void M487EADC_Init(void)
{
/*复位EADC控制器*/
// EADC_CONV_RESET(EADC);
/* Set PB.0 ~ PB.3 to input mode */
PB->MODE &= ~ADCInputModePin;
// GPIO_SetMode(PB,ADCInputModePin,GPIO_MODE_INPUT);
/* Set reference voltage to external pin (3.3V) */
SYS_SetVRef(SYS_VREFCTL_VREF_PIN);
/* Enable temperature sensor */
SYS->IVSCTL |= (SYS_IVSCTL_VTEMPEN_Msk |SYS_IVSCTL_VBATUGEN_Msk);
/*ADC 结果位数选择12位ADC 结果存入RESULT (EADC_DATn[11:0]).*/
EADC->CTL &= (~EADC_CTL_RESSEL_Msk);
EADC->CTL |= EADC_CTL_RESSEL_Msk;
/* 将输入模式设置为单端并启用A/D转换器 */
EADC_Open(EADC, EADC_CTL_DIFFEN_SINGLE_END);
/*设置ADC的触发方式为软件触发*/
EADC_ConfigSampleModule(EADC, 0, EADC_SOFTWARE_TRIGGER, 0);
EADC_ConfigSampleModule(EADC, 1, EADC_SOFTWARE_TRIGGER, 1);
EADC_ConfigSampleModule(EADC, 2, EADC_SOFTWARE_TRIGGER, 2);
EADC_ConfigSampleModule(EADC, 3, EADC_SOFTWARE_TRIGGER, 3);
EADC_ConfigSampleModule(EADC, 4, EADC_SOFTWARE_TRIGGER, 4);
EADC_ConfigSampleModule(EADC, 5, EADC_SOFTWARE_TRIGGER, 5);
EADC_ConfigSampleModule(EADC, 6, EADC_SOFTWARE_TRIGGER, 6);
EADC_ConfigSampleModule(EADC, 7, EADC_SOFTWARE_TRIGGER, 7);
EADC_ConfigSampleModule(EADC, 8, EADC_SOFTWARE_TRIGGER, 8);
EADC_ConfigSampleModule(EADC, 9, EADC_SOFTWARE_TRIGGER, 9);
EADC_ConfigSampleModule(EADC, 10, EADC_SOFTWARE_TRIGGER, 10);
EADC_ConfigSampleModule(EADC, 11, EADC_SOFTWARE_TRIGGER, 11);
EADC_ConfigSampleModule(EADC, 14, EADC_SOFTWARE_TRIGGER, 14);
EADC_ConfigSampleModule(EADC, 15, EADC_SOFTWARE_TRIGGER, 15);
EADC_ConfigSampleModule(EADC, 16, EADC_SOFTWARE_TRIGGER, 16);
EADC_ConfigSampleModule(EADC, 17, EADC_SOFTWARE_TRIGGER, 17);
EADC_ConfigSampleModule(EADC, 18, EADC_SOFTWARE_TRIGGER, 18);
/*设置ADC延长采样时间。*/
// EADC_SetExtendSampleTime(EADC, 0, 0xF);
// EADC_SetExtendSampleTime(EADC, 1, 0xF);
// EADC_SetExtendSampleTime(EADC, 2, 0xF);
// EADC_SetExtendSampleTime(EADC, 3, 0xF);
// EADC_SetExtendSampleTime(EADC, 4, 0xF);
// EADC_SetExtendSampleTime(EADC, 5, 0xF);
// EADC_SetExtendSampleTime(EADC, 6, 0xF);
// EADC_SetExtendSampleTime(EADC, 7, 0xF);
// EADC_SetExtendSampleTime(EADC, 8, 0xF);
// EADC_SetExtendSampleTime(EADC, 9, 0xF);
// EADC_SetExtendSampleTime(EADC, 10, 0xF);
// EADC_SetExtendSampleTime(EADC, 11, 0xF);
// EADC_SetExtendSampleTime(EADC, 14, 0xF);
// EADC_SetExtendSampleTime(EADC, 15, 0xF);
// EADC_SetExtendSampleTime(EADC, 16, 0xF);
// EADC_SetExtendSampleTime(EADC, 17, 0x3F);
// EADC_SetExtendSampleTime(EADC, 18, 0xF);
EADC_SetTriggerDelayTime(EADC, 0, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 1, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 2, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 3, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 4, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 5, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 6, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 7, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 8, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 9, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 10, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 11, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 14, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 15, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 16, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 17, 0x3f, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
EADC_SetTriggerDelayTime(EADC, 18, 0xf, EADC_SCTL_TRGDLYDIV_DIVIDER_16);
/* 禁用GPB0-GPB11,GPB14、GPB15数字输入路径以避免泄漏电流 */
GPIO_DISABLE_DIGITAL_PATH(PB, ADCpin);
/* 开启ADC软件触发模式,参数BIT对应相应的通道 */
// EADC_START_CONV(EADC, ADCpin | BIT16 | BIT17 | BIT18);
}
然后main函数中 使用如下:
int main()
{
uint16_t Band_gap,Temperature;
// SYS_Init();
M487JIDAE_ClockConfigure_init();
M487JIDAE_PinConfigure_init();
/* Init UART to 115200-8n1 for print message */
M487UART_Init(UART0, UART0_IRQn);
M487UART_Init(UART1, UART1_IRQn);
M487UART_Init(UART2, UART2_IRQn);
M487EADC_Init();
M487TIMER_Init();
/* Connect UART to PC, and open a terminal tool to receive following message */
printf("Hello World\n");
printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);
printf("+-------------------------------------------------+\n");
printf("| PH.0(Output) PH.1(Output) PH.2(Output) |\n");
printf("+-------------------------------------------------+\n\n");
/*-----------------------------------------------------------------------------------------------------*/
/* GPIO Basic Mode Test --- Use Pin Data Input/Output to control GPIO pin */
/*-----------------------------------------------------------------------------------------------------*/
/* Configure PB.3 as Output mode and PD.8 as Input mode then close it */
GPIO_SetMode(PH, BIT0, GPIO_MODE_OUTPUT);
GPIO_SetMode(PH, BIT1, GPIO_MODE_OUTPUT);
GPIO_SetMode(PH, BIT2, GPIO_MODE_OUTPUT);
/* Configure PB.3 and PD.8 to default Quasi-bidirectional mode */
// GPIO_SetMode(PB, BIT3, GPIO_MODE_QUASI);
// GPIO_SetMode(PD, BIT8, GPIO_MODE_QUASI);
/* Got no where to go, just loop forever */
/* 开启ADC软件触发模式,参数BIT对应相应的通道 */
EADC_START_CONV(EADC, ADCpin|BIT16|BIT17|BIT18);
while(1)
{
// printf("PH0 Delay 1 second\n");
// PH0=~PH0;
// TIMER_Delay(TIMER0, 1000000);
// printf("PH1 Delay 1 second\n");
// PH1=~PH1;
// TIMER_Delay(TIMER0, 1000000);
// printf("PH2 Delay 1 second\n");
/* 查询相应通道是否转换完毕 */
if((EADC_GET_PENDING_CONV(EADC)&ADCpin) == 0)
{
printf("EADC_GET_PENDING_CONV=:%x\n",EADC_GET_PENDING_CONV(EADC));
printf("ADC0=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 0));
printf("ADC1=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 1));
printf("ADC2=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 2));
printf("ADC3=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 3));
printf("ADC4=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 4));
printf("ADC5=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 5));
printf("ADC6=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 6));
printf("ADC7=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 7));
printf("ADC8=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 8));
printf("ADC9=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 9));
printf("ADC10=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 10));
printf("ADC11=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 11));
printf("ADC14=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 14));
printf("ADC15=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 15));
// printf("ADC16=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 16));
Band_gap=(uint16_t)EADC_GET_CONV_DATA(EADC, 16);
printf("Band-gap = %.2f\n", ((float)Band_gap/4095)*(float)(3.3));
Temperature=(uint16_t)EADC_GET_CONV_DATA(EADC, 17);
// printf("ADC17=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 17));
printf("Temperature = %2.1f\n", (25+(((float)Temperature/4095*3300)-675)/(-1.83)));
printf("ADC18=:%d\n",(uint16_t)EADC_GET_CONV_DATA(EADC, 18));
/* 开启ADC软件触发模式,参数BIT对应相应的通道 */
EADC_START_CONV(EADC, ADCpin|BIT16|BIT17|BIT18);
}
打印出来的结果是这样的
各个通过怎么都不能为0,用电位器调节时,只扭一半行程就4095了,还有大半圈没有到头
电路板用的是官方 NuMaker-PFM-M487,
这个问题困扰几天了,求大神解答
|
|