TI中文支持网
TI专业的中文技术问题搜集分享网站

急!ADCProcessorTrigger不起作用 TM4C123GH6PM

配置好ADC后调用ADCProcessorTrigger,然后观察ADC_PSSI的值,发现ADC_PSSI始终为零,

直接用HWREG(ADC0_BASE+ADC_0_PSSI)  来写寄存器ADC_PSSI的值依然为零,

配置ADC的函数为:

void InitADC()
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeADC(GPIO_PORTD_BASE,GPIO_PIN_2);

    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

    ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
    ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 24);

    ADCIntEnable(ADC0_BASE,3);
    IntEnable(INT_ADC0SS3_TM4C123);
    IntMasterEnable();

    ADCIntClear(ADC0_BASE,3);
    ADCSequenceEnable(ADC0_BASE,3);
}

然后在main里的:

while(1)

{

    //        ADCProcessorTrigger(ADC0_BASE, 3);

   HWREG(ADC0_BASE + ADC_0_PSSI) |= ((3 & 0xffff0000) | (1 << (3 & 0xf)));

   while(!ADCIntStatus(ADC0_BASE, 3, false))
        {
        }
    ADCIntClear(ADC0_BASE, 3);
    ADCSequenceDataGet(ADC0_BASE, 3, Buffer);
    SysCtlDelay(SysCtlClockGet() / 12);

}

启动采样

但是无论是运行ADCProcessorTrigger还是运行HWREG,ADC_PSSI的值都不会变化,再往后执行,则在

   while(!ADCIntStatus(ADC0_BASE, 3, false))这一句跑飞

我认为问题应该出在ADCProcessorTrigger这一步上,

急求解答!

谢谢!

step by step:

楼主,

  建议参考TIvaware下的…\examples\peripherals\adc下的范例代码;

Tianli Zhang:

回复 step by step:

完全按照例程写的,可是不行,没法用ADCProcessorTrigger触发采样,

我刚刚又发现,如果先写ADC_PSSI_SYNCWAIT,再写ADC_PSSI_SYNCWAIT,那么ADC_PSSI_SSn是可以写进1的,但是直接写ADC_PSSI_SSn就不行,

于是我就想先写ADC_PSSI_SYNCWAIT再写ADC_PSSI_SSn然后再把ADC_PSSI_SYNCWAIT clear掉来启动采样,但是,

把ADC_PSSI_SYNCWAIT clear掉的同时ADC_PSSI_SSn也被 clear了…

结果还是无法采样

急用,真心求解答,谢谢!

Michael Sun:

回复 Tianli Zhang:

例程的代码没有问题的。

再分享一个给你,用ADC采集内部温度传感器的:

#include <stdint.h>#include <stdbool.h>#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "driverlib/debug.h"#include "driverlib/sysctl.h"#include "driverlib/adc.h"

#ifdef DEBUGvoid__error__(char *pcFilename, uint32_t ui32Line){}#endif

int main(void){ uint32_t ui32ADC0Value[4]; volatile uint32_t ui32TempAvg; volatile uint32_t ui32TempValueC; volatile uint32_t ui32TempValueF;

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1);

while(1) { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1);

while(!ADCIntStatus(ADC0_BASE, 1, false)) { }

ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 – ((2475 * ui32TempAvg)) / 4096)/10; ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; }}

采集的输入不一样,但是原理流程都是一样的,仔细对照修改吧。

赞(0)
未经允许不得转载:TI中文支持网 » 急!ADCProcessorTrigger不起作用 TM4C123GH6PM
分享到: 更多 (0)