|
本帖最后由 leafy 于 2016-12-28 14:50 编辑
int main(void)
{
int i;
// 外设使能配置
PSCInit();
// GPIO 管脚复用配置
GPIOBankPinMuxSet();
// GPIO 管脚初始化
GPIOBankPinInit();
// 定时器 / 计数器初始化
TimerInit();
// DSP 中断初始化
InterruptInit();
// 定时器 / 计数器中断初始化
TimerInterruptInit();
//AD7606初始化
AD7606Reset();
// 主循环
for(; ;)
{
if(conv_flg==1)//一个sample已经被读完,存在了DOUT[0]-DOUT[7]当中,都是int型的数据。
{
for(i=0;i<8;i++)
AdcSample = (20.0/65536.0)* DOUT;//数字量转换为模拟量,输入范围是正负10V,精度为16位
//相当于将20V分成了65536份,公式为A=(20.0/65536.0)*D;A为模拟量值,D为数字量值;
//如果输入范围是正负5V则公式为A=(10.0/65536.0)*D
conv_flg=0;
CH1_Sample[adc_cnt] = AdcSample[0];//存放每个通道的历史数值
CH2_Sample[adc_cnt] = AdcSample[1];
CH3_Sample[adc_cnt] = AdcSample[2];
CH4_Sample[adc_cnt] = AdcSample[3];
CH5_Sample[adc_cnt] = AdcSample[4];
CH6_Sample[adc_cnt] = AdcSample[5];
CH7_Sample[adc_cnt] = AdcSample[6];
CH8_Sample[adc_cnt] = AdcSample[7];
adc_cnt++;
/* if(adc_cnt>Num-1)
{
for(h=0;h<256;h++)
CH1_Sample[h]=0;
adc_cnt=0;
}
*/
}
}
}
/* while(1)
{
//一个sample已经被读完,存在了DOUT[0]-DOUT[7]当中,都是int型的数据。
if(conv_flg==1)
{
for(i=0;i<8;i++)
AdcSample = (20.0/65536.0)* DOUT;
CH1_Sample[adc_cnt] = AdcSample[0];
CH2_Sample[adc_cnt] = AdcSample[1];
CH3_Sample[adc_cnt] = AdcSample[2];
CH4_Sample[adc_cnt] = AdcSample[3];
CH5_Sample[adc_cnt] = AdcSample[4];
CH6_Sample[adc_cnt] = AdcSample[5];
CH7_Sample[adc_cnt] = AdcSample[6];
CH8_Sample[adc_cnt] = AdcSample[7];
adc_cnt++;
conv_flg=0;
if(adc_cnt>255)
adc_cnt=0;
}
}
*/
/****************************************************************************/
/* */
/* PSC 初始化 */
/* */
/****************************************************************************/
void PSCInit(void)
{
// 使能 GPIO 模块
// 对相应外设模块的使能也可以在 BootLoader 中完成
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
}
/****************************************************************************/
/* */
/* GPIO 管脚复用配置 */
/* */
/****************************************************************************/
void GPIOBankPinMuxSet(void)
{
// 配置相应的7个 GPIO 口功能为普通输入输出口
GPIOBank1Pin14PinMuxSetup();
GPIOBank1Pin13PinMuxSetup();
GPIOBank1Pin12PinMuxSetup();
GPIOBank1Pin11PinMuxSetup();
GPIOBank1Pin10PinMuxSetup();
GPIOBank1Pin9PinMuxSetup();
GPIOBank8Pin7PinMuxSetup();
}
/****************************************************************************/
/* */
/* GPIO 管脚初始化 */
/* */
/****************************************************************************/
void GPIOBankPinInit(void)
{
// OMAPL138 及 DSP C6748 共有 144 个 GPIO
// 以下为各组 GPIO BANK 起始管脚对应值
// 范围 1-144
// GPIO0[0] 1
// GPIO1[0] 17
// GPIO2[0] 33
// GPIO3[0] 49
// GPIO4[0] 65
// GPIO5[0] 81
// GPIO6[0] 97
// GPIO7[0] 113
// GPIO8[0] 129
GPIODirModeSet(SOC_GPIO_0_REGS, 31, GPIO_DIR_INPUT); // GPIO1[14]
GPIODirModeSet(SOC_GPIO_0_REGS, 30, GPIO_DIR_INPUT); // GPIO1[13]
GPIODirModeSet(SOC_GPIO_0_REGS, 136, GPIO_DIR_INPUT); // GPIO8[7]
GPIODirModeSet(SOC_GPIO_0_REGS, 29, GPIO_DIR_OUTPUT); // GPIO1[12]
GPIODirModeSet(SOC_GPIO_0_REGS, 28, GPIO_DIR_OUTPUT); // GPIO1[11]
GPIODirModeSet(SOC_GPIO_0_REGS, 27, GPIO_DIR_OUTPUT); // GPIO1[10]
GPIODirModeSet(SOC_GPIO_0_REGS, 26, GPIO_DIR_OUTPUT); // GPIO1[9]
}
/****************************************************************************/
/* */
/* 定时器 / 计数器初始化 */
/* */
/****************************************************************************/
void TimerInit(void)
{
// 配置 定时器 / 计数器 2 为 64 位模式
TimerConfigure(SOC_TMR_2_REGS, TMR_CFG_64BIT_CLK_INT);
// 设置周期
TimerPeriodSet(SOC_TMR_2_REGS, TMR_TIMER12, TMR_PERIOD_LSB32);
TimerPeriodSet(SOC_TMR_2_REGS, TMR_TIMER34, TMR_PERIOD_MSB32);
// 使能 定时器 / 计数器 2
TimerEnable(SOC_TMR_2_REGS, TMR_TIMER12, TMR_ENABLE_CONT);
}
/****************************************************************************/
/* */
/* 定时器 / 计数器中断初始化 */
/* */
/****************************************************************************/
void TimerInterruptInit(void)
{
// 注册中断服务函数
IntRegister(C674X_MASK_INT4, TimerIsr);
// 映射中断到 DSP 可屏蔽中断
IntEventMap(C674X_MASK_INT4, SYS_INT_T64P2_TINTALL);
// 使能 DSP 可屏蔽中断
IntEnable(C674X_MASK_INT4);
// 使能 定时器 / 计数器 中断
TimerIntEnable(SOC_TMR_2_REGS, TMR_INT_TMR12_NON_CAPT_MODE);
}
/****************************************************************************/
/* */
/* DSP 中断初始化 */
/* */
/****************************************************************************/
void InterruptInit(void)
{
// 初始化 DSP 中断控制器
IntDSPINTCInit();
// 使能 DSP 全局中断
IntGlobalEnable();
}
/****************************************************************************/
/* */
|
|