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

TM4C,TIMER触发ADC配制方法

TIMER触发ADC配制方法一直进不去中断,麻烦看看有没有问题呢,用ADC_TRIGGER_PROCESSOR方式可以进中断,ADC_TRIGGER_TIMER方式就不行

void ADC_INIT(void)
{
//初始化ADC0/PE3
//SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);//设置采样速度,默认1MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//ADCSequenceDisable(ADC0_BASE,0); //配置前先禁止采样序列
//设置ADC参考电压为外部3V,TM4C123GH6PM只能使用内部参考电压,3.3V
//ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);//若ADC_REF_INT,则指使用内部3V参考电压
//配置ADC采集序列,ADC_TRIGGER_PROCESSOR是软件触发,ADC_TRIGGER_TIMER是定时器触发
ADCSequenceConfigure(ADC0_BASE, 0,ADC_TRIGGER_TIMER, 0);
//ADCSequenceConfigure(ADC0_BASE, 0,ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 );//PE3/IC
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1 );//PE2/IB
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 );//PE1IA
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 );//PE0/VREF
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4 );//PD3/UA
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5 );//PD2/UB
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH6 | ADC_CTL_IE |ADC_CTL_END);//PD1/UC
//ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH7 | ADC_CTL_IE |ADC_CTL_END);//PD0未使用

IntMasterEnable();
IntEnable(INT_ADC0SS0); //使能ADC采样序列中断
ADCIntEnable(ADC0_BASE, 0);
//中断触发方式设置ADC_INT_SS0、ADC_INT_DMA_SS0、ADC_INT_DCON_SS0
ADCIntEnableEx(ADC0_BASE,ADC_INT_SS0);//分别代表普通序列触发、DMA触发和数字比较器触发
ADCIntClear(ADC0_BASE, 0);
ADCSequenceEnable(ADC0_BASE, 0);//使能ADC采集序列

TimerControlTrigger(ADC0_BASE,TIMER_A,true);
}

void ADC0IntHandler(void)
{
ADCIntClear(ADC0_BASE, 0);
while(!ADCIntStatus(ADC0_BASE, 0, false));//等待采集结束
ADCSequenceDataGet(ADC0_BASE, 0, ADC0_Value);
if (ADC_Ready_Flag == 0)
{
RMS_IC.Save[Cnt_Period] = ADC0_Value[0];
RMS_IB.Save[Cnt_Period] = ADC0_Value[1];
RMS_IA.Save[Cnt_Period] = ADC0_Value[2];
RMS_VR.Save[Cnt_Period] = ADC0_Value[3];
RMS_VA.Save[Cnt_Period] = ADC0_Value[4];
RMS_VB.Save[Cnt_Period] = ADC0_Value[5];
RMS_VC.Save[Cnt_Period] = ADC0_Value[6];
Cnt_Period++;
if (Cnt_Period == 255)
{
Cnt_Period = 0;
ADC_Ready_Flag = 1;
}
}
//TimerControlTrigger(ADC0_BASE,TIMER_A,true);
}

void TIMER0(void)
{
//uint32_t timer0period;
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//使能TIMER0
//TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT);//单次计数模式
//TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP);//周期性计数模式,递增计数
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);//周期性计数模式
//timer0period=SysCtlClockGet() / 12800 ;//目标值是:系统频率/n,那每秒就进n次中断
//timer0period=SysCtlClockGet() / 50 ;//50HZ,0.02S进一次中断
TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet() / 12800-1);
TimerADCEventSet(TIMER0_BASE,TIMER_ADC_TIMEOUT_A);//超时触发采样设置
TimerADCEventGet(TIMER0_BASE);//获取是否超时触发ADC
//IntEnable(INT_TIMER0A);//TIMEOUT标志位触发中断
//TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //使能TIMER0A中断
//IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);//TIMER0A开始计数,当计数值等于TimerLoadSet,触发中断
}

void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);//清除标志位
a[k]=k;
k++;
if(k==256)
{
k=0;
}

}

JunZhu Dou:

ADCSequenceConfigure(ADC0_BASE, 0,ADC_TRIGGER_TIMER, 0);

TimerControlTrigger(ADC0_BASE,TIMER_A,true);

这两句放在ADC初始化里

TimerADCEventSet(TIMER0_BASE,TIMER_ADC_TIMEOUT_A);//超时触发采样设置,这一句应该放在定时器初始化里

TimerADCEventGet(TIMER0_BASE);//获取是否超时触发ADC,这一句应该放在哪里?还是这句不需要?

除了这四句,还需要什么配置么?

xyz549040622:

回复 JunZhu Dou:

这么明显的错误都会犯,TIM配置中加ADC的的基本地址。

JunZhu Dou:

回复 xyz549040622:

老大你也不早点提醒我。。。我找的好苦啊

xyz549040622:

回复 JunZhu Dou:

我只注意看你的配置了,这么基本的,根本没注意看。

赞(0)
未经允许不得转载:TI中文支持网 » TM4C,TIMER触发ADC配制方法
分享到: 更多 (0)