概述
新手小白,刚刚开始学习DSP,将自己的过程记录下来。(自用记录,防止遗忘!)
1. 首先要了解GPIO模块
查阅手册可知,ADC转换的外部触发有以下5种,故若采用GPIO触发,需用到XINT2引脚。
– S/W - software immediate start
– All ePWMs - ADCSOC A or B
– GPIO XINT2
– CPU Timers 0/1/2
– ADCINT1/2
同时得知280049M的XINT2号引脚与input5 相连。因此在设置触发时,只需要将XINT2进行相关配置即可产生出发。
2. 在确认完相关手册信息后,再对GPIO进行初始化配置,结合上一章软件触发的程序进行修改即可。
下面是对GPIO15号引脚进行直接输入高电平触发(该程序可初步实现上电一次出发一次,但存在抖动等因素,具有非准确性,其实可以加一个延时函数,消抖动即可。后面本人采用了两个GPIO直接进行拉高拉低上电,解放双手。。。)
#include "driverlib.h"
#include "device.h"
uint16_t a1[1024] = {0};
uint16_t a2[1024] = {0};
uint16_t a3[1024] = {0};
uint16_t a4[1024] = {0};
uint16_t a5[1024] = {0};
uint16_t a6[1024] = {0};
uint16_t i = 0 ,j = 0 ;
uint16_t p = 0 ,q = 0 ;
uint16_t u = 0 ,v = 0 ;
void initADCs(void);
void initADCSOCs(void);
void initExintGPIO(void);
int testCount=0;
interrupt void xint2ISR(void)
{
testCount++;
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}
void main(void)
{
Device_init(); //初始化设备时钟和外设
Device_initGPIO(); //禁用引脚锁并启用内部上拉
Interrupt_initModule(); //初始化PIE并清除PIE寄存器。禁用CPU中断。
Interrupt_initVectorTable(); //用指向shell中断的指针初始化PIE向量表ISR服务程序。
// 初始化ADC,初始化SOC
initADCs();
initADCSOCs();
initExintGPIO();
EINT; //打开全局中断
ERTM; //当使用仿真器调试时 开启DEBUG中断
while(1)
{
// 等待ADC转换完成,并清除中断标志位
while(ADC_getInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1) == false)
{
}
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
while(ADC_getInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1)== false)
{
}
ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
while(ADC_getInterruptStatus(ADCC_BASE, ADC_INT_NUMBER1) == false)
{
}
ADC_clearInterruptStatus(ADCC_BASE, ADC_INT_NUMBER1);
a1[i++] = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
// if(i >= sizeof(a1) / sizeof(a1[0])) //(400/4=100)同i>=100,此方法不用修改两处,只用将定义数组处的数组内数据随意修改即可。
//存储结果
if(i >= 1024)
{
i=0;
}
a2[j++] = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER1);
if(j >= 1024)
{
j=0;
}
a3[p++] = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER0);
if(p >= 1024)
{
p=0;
}
a4[q++] = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER1);
if(q >= 1024)
{
q=0;
}
a5[u++] = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER0);
if(u >= 1024)
{
u=0;
}
a6[v++] = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER1);
if(v >= 1024)
{
v=0;
}
}
}
// 初始化ADC
void initADCs(void)
{
// ADC使用片内参考3.3V
// Setup VREF as internal
ADC_setVREF(ADCA_BASE, ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
ADC_setVREF(ADCB_BASE, ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
ADC_setVREF(ADCC_BASE, ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
// ADC时钟4分频
// Set ADCCLK divider to /4
ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0);
ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
ADC_setPrescaler(ADCC_BASE, ADC_CLK_DIV_4_0);
// 设置转换结束时触发中断
// Set pulse positions to late
ADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV);
ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
ADC_setInterruptPulseMode(ADCC_BASE, ADC_PULSE_END_OF_CONV);
// 启动AD并延迟1ms
// Power up the ADCs and then delay for 1 ms
ADC_enableConverter(ADCA_BASE);
ADC_enableConverter(ADCB_BASE);
ADC_enableConverter(ADCC_BASE);
DEVICE_DELAY_US(1000); //在ADC转换前要延迟一段时间
}
void initExintGPIO(void)
{
Interrupt_register(INT_XINT2, &xint2ISR);
Interrupt_enable(INT_XINT2); // 使能 XINT2 中断
GPIO_setPinConfig(GPIO_15_GPIO15); // GPIO15 复用为GPIO功能
GPIO_setDirectionMode(15, GPIO_DIR_MODE_IN); // GPIO15 设置为输入
GPIO_setQualificationMode(15, GPIO_QUAL_SYNC); //GPIO15 的时钟周期同系统时钟周期
GPIO_setInterruptPin(15, GPIO_INT_XINT2); // XINT2 connected to GPIO15
// GPIO_setInterruptType(GPIO_INT_XINT2, GPIO_INT_TYPE_FALLING_EDGE); //下降沿
GPIO_setInterruptType(GPIO_INT_XINT2, GPIO_INT_TYPE_RISING_EDGE); // XINT2 对应GPIO 15 ,上升沿触发(因为电压起初是低电平)
GPIO_enableInterrupt(GPIO_INT_XINT2); //使能XINT2 中断
}
// 初始化ADCSOC
void initADCSOCs(void)
{
// 采样窗口持续10个系统时钟
// - SOC0 will convert pin A0 with a sample window of 10 SYSCLK cycles.
// - SOC1 will convert pin A1 with a sample window of 10 SYSCLK cycles.
//
// ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN0, 10);
// ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN1, 10);
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_GPIO, ADC_CH_ADCIN0, 10);
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_GPIO, ADC_CH_ADCIN1, 10);
// 设置中断为ADCINT1,并启用
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
// 采样窗口持续10个系统时钟
// - SOC0 will convert pin B0 with a sample window of 10 SYSCLK cycles.
// - SOC1 will convert pin B1 with a sample window of 10 SYSCLK cycles.
//
// ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN0, 10);
// ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN1, 10);
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_GPIO, ADC_CH_ADCIN0, 10);
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_GPIO, ADC_CH_ADCIN1, 10);
// 设置中断为ADCINT1,并启用
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
// ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN15, 10);
// ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN15, 10);
ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_GPIO, ADC_CH_ADCIN15, 10);
ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_GPIO, ADC_CH_ADCIN15, 10);
// 设置中断为ADCINT1,并启用
// Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
// sure its flag is cleared.
ADC_setInterruptSource(ADCC_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER1);
ADC_enableInterrupt(ADCC_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCC_BASE, ADC_INT_NUMBER1);
}
最后
以上就是务实牛排为你收集整理的F280049M外部GPIO触发ADC数据采集的全部内容,希望文章能够帮你解决F280049M外部GPIO触发ADC数据采集所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复