/*******************************************************************************************
*******************************************************************************************/ #include "hw_memmap.h" #include "hw_types.h" #include "hw_ints.h" #include "hw_adc.h" #include "src/interrupt.h" #include "src/sysctl.h" #include "src/gpio.h" #include "src/adc.h" #include "src/pwm.h"
unsigned int wait_for_ADCINT = 1;
int main(void) { unsigned int i; SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_6MHZ); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 125KSps采样率 ADCSequenceDisable(ADC_BASE, 0); // 禁能所有采样序列 ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); // 采样序列0为处理器触发 &&&&1 ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC_BASE, 0, 2, ADC_CTL_CH3); ADCSequenceStepConfigure(ADC_BASE, 0, 3, ADC_CTL_CH4); ADCSequenceStepConfigure(ADC_BASE, 0, 4, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC_BASE, 0, 5, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC_BASE, 0, 6, ADC_CTL_CH3); ADCSequenceStepConfigure(ADC_BASE, 0, 7, (ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END));
ADCSequenceEnable(ADC_BASE, 0); ADCIntEnable(ADC_BASE, 0); IntEnable(INT_ADC0); IntMasterEnable(); // 使能总中断
for (;;){ if(wait_for_ADCINT ==1){ ADCProcessorTrigger(ADC_BASE, 0); wait_for_ADCINT = 0; } } }
void ADCIntHandler(void){ static unsigned long ADC_Value[8]; unsigned short int n; ADCIntClear(ADC_BASE, 0); for(n=0;n<8;n++){ ADC_Value[n] = HWREG(ADC_BASE + ADC_O_SSFIFO0); } wait_for_ADCINT =1 ; }
这段代码目的: 软件触发,用序列0 对4个通道进行ADC 转换, 期望在中断中读出8次转换结果。 实际未能进入中断服务程序来观察转换结果,望 ZLGARM 或者那位帮助一下,
软件由“ADC过采样技术 应用文档”仿制而来。 |