关于ADS7865调试时序问题(使用DSP28335XINTF)
我使用ADS7865与DSP28335配合进行双通道信号采集,现输入端接地后用CCS调试,采集数据结果为随机数,怀疑是程序时序问题,但不知道具体问题在哪里。
ADS7865采用32M外部有源晶振,CS#管脚接地,RD#WR#分别连接DSP28335XINTF的XRDn、XWE0n,BUSY管脚连接DSP28335的16管脚(GPIO7/EPWM4B/MCLKRA/ECAP2),CONVST#管脚连接有问题,连接的DSP28335的152管脚(GPIO41/XA1),在使用XINTF模块时只能作为地址线,所以程序中用写地址来对CONVST进行置高置低。
现调试配置ADS7865内部DAC参考电压,发现可以成功配置,排除了读写方式的问题。
器件原理图及晶振波形图见附件。
AD程序如下,输入管脚接地,数据为随机数:
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#define LED GpioDataRegs.GPADAT.bit.GPIO20 // Basic pinout configuration example
// Configure the period for AD
Uint16 *add = (Uint16 *) 0x200002;
Uint16 temp;
//==============================================================================================
interrupt void epwm1_timer_isr(void);
void Init_epwm1_timer(void);
void init_zone7(void);
void init_Gpio(void);
//==============================================================================================
Uint16 VoltageA[5];
Uint16 VoltageB[5];
void main(void)
{
Uint16 i=0,k=0;
for(i=0;i<5;i++)
{
VoltageA[i]=0;
VoltageB[i]=0;
}
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Init_epwm1_timer(); // For this example, only initialize the ePWM Timers
// Step 5. User specific code:
// This example is a basic pinout
init_Gpio();
init_zone7();
// IER |= M_INT3;
// Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
// PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
i=0;
while(GpioDataRegs.GPADAT.bit.GPIO7 !=0){}//ABUSY
*add=0x1000; //指令 0x100h,,,CONVST=1;
// temp=*(add);
for(k=0;k<10;k++)
{
temp=*(add-2); //CONVST=0; 启动保持 和 转换 上一次结果
}
while(GpioDataRegs.GPADAT.bit.GPIO7 !=0){}
temp=*(add); //CONVST=1; 启动保持 和 转换
for(;;)
{
for(k=0;k<10;k++)
{
temp=*(add-2); //CONVST=0; 启动保持 和 转换 上一次结果
}
while(GpioDataRegs.GPADAT.bit.GPIO7 !=0){}
VoltageA[i]=(*add >>4);
for(k=0;k<10;k++) ;
VoltageB[i++]=(*add >>4);
if(i==5)
i=0;
}
}
void Init_epwm1_timer()
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;
// Setup Sync
//EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Pass through
// Allow each timer to be sync'ed
//EPwm1Regs.TBCTL.bit.HSPCLKdiv=3;
//EPwm1Regs.TBCTL.bit.CLKdiv=1; //epwm1clk=1/12*systemclk
EPwm1Regs.TBCTL.bit.HSPCLKdiv=3;
EPwm1Regs.TBCTL.bit.CLKdiv=0; //epwm1clk=1/6*systemclk
EPwm1Regs.TBPRD = 50000/10;
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Count up
EPwm1Regs.ETSEL.bit.INTSEL = 2; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate INT on 1st event
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;
}
// Interrupt routines uses in this example
interrupt void epwm1_timer_isr(void)
{
LED=~LED;
*add=0x0000;
// while(GpioCtrlRegs.GPADAT.bit.GPIO7 !=0) { }//ABUSY
// Check against sent data
/* temp=*add;
voltageA[count]=temp>>4;
temp=*add;
voltageB[count]=temp>>4;
Count=Count+1;
if (Count>=500) //end of an interrogation
{
Count=0;
}*/
//====================================================================
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void init_Gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; // GPIO7 ABUSY
GpioCtrlRegs.GPADIR.bit.GPIO7 = 0; // GPIO7 = input
GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 0; // GPIO20
GpioCtrlRegs.GPADIR.bit.GPIO20 = 1; // GPIO20 = output
EDIS;
}
void init_zone7(void)
{
// Make sure the XINTF clock is enabled
SysCtrlRegs.PCLKCR3.bit.XINTFENCLK = 1;
// Configure the GPIO for XINTF with a 16-bit data bus
// This function is in DSP2833x_Xintf.c
InitXintf16Gpio();
EALLOW;
// All Zones---------------------------------
// Timing for all zones based on XTIMCLK = SYSCLKOUT
XintfRegs.XINTCNF2.bit.XTIMCLK = 0;
// Buffer up to 3 writes
XintfRegs.XINTCNF2.bit.WRBUFF = 3;
// XCLKOUT is enabled
XintfRegs.XINTCNF2.bit.CLKOFF = 0;
// XCLKOUT = XTIMCLK
XintfRegs.XINTCNF2.bit.CLKMODE = 0;
// Disable XHOLD to prevent XINTF bus from going into high impedance state
// whenever TZ3 signal goes low. This occurs because TZ3 on GPIO14 is
// shared with HOLD of XINTF
XintfRegs.XINTCNF2.bit.HOLD = 1;
// Zone 7------------------------------------
// When using ready, ACTIVE must be 1 or greater
// Lead must always be 1 or greater
// Zone write timing
XintfRegs.XTIMING7.bit.XWRLEAD = 1;
XintfRegs.XTIMING7.bit.XWRACTIVE = 2;
XintfRegs.XTIMING7.bit.XWRTRAIL = 1;
// Zone read timing
XintfRegs.XTIMING7.bit.XRDLEAD = 1;
XintfRegs.XTIMING7.bit.XRDACTIVE = 3;
XintfRegs.XTIMING7.bit.XRDTRAIL = 0;
// don't double all Zone read/write lead/active/trail timing
XintfRegs.XTIMING7.bit.X2TIMING = 0;
// Zone will not sample XREADY signal
XintfRegs.XTIMING7.bit.USEREADY = 0;
XintfRegs.XTIMING7.bit.READYMODE = 0;
// 1,1 = x16 data bus
// 0,1 = x32 data bus
// other values are reserved
XintfRegs.XTIMING7.bit.XSIZE = 3;
EDIS;
//Force a pipeline flush to ensure that the write to
//the last register configured occurs before returning.
__asm(" RPT #7 || NOP");
}
//===========================================================================
// No more.
//===========================================================================
配置参考电压程序如下,测量得REFOUT电压正确改变:
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Configure the period for AD
Uint16 *add = (Uint16 *) 0x200002;
Uint16 temp;
//==============================================================================================
interrupt void epwm1_timer_isr(void);
void Init_epwm1_timer(void);
void init_zone7(void);
void init_Gpio(void);
//==============================================================================================
void main(void)
{
Uint16 k=0;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Init_epwm1_timer(); // For this example, only initialize the ePWM Timers
// Step 5. User specific code:
// This example is a basic pinout
init_Gpio();
init_zone7();
// IER |= M_INT3;
// Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
// PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
while(GpioDataRegs.GPADAT.bit.GPIO7 !=0){}
*add=0x1010; //指令 0x101h
*add=0x1FD0; //DAC1.240V
for(k=0;k<10;k++) ;
*add=0x1030; //指令 0x103h
*add=0x1FD0; //DAC1.240V
for(;;)
{
}
}
void Init_epwm1_timer()
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;
// Setup Sync
//EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Pass through
// Allow each timer to be sync'ed
//EPwm1Regs.TBCTL.bit.HSPCLKdiv=3;
//EPwm1Regs.TBCTL.bit.CLKdiv=1; //epwm1clk=1/12*systemclk
EPwm1Regs.TBCTL.bit.HSPCLKdiv=3;
EPwm1Regs.TBCTL.bit.CLKdiv=0; //epwm1clk=1/6*systemclk
EPwm1Regs.TBPRD = 50000/10;
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Count up
EPwm1Regs.ETSEL.bit.INTSEL = 2; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate INT on 1st event
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;
}
// Interrupt routines uses in this example
interrupt void epwm1_timer_isr(void)
{
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void init_Gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; // GPIO7 ABUSY
GpioCtrlRegs.GPADIR.bit.GPIO7 = 0; // GPIO7 = input
GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 0; // GPIO20
GpioCtrlRegs.GPADIR.bit.GPIO20 = 1; // GPIO20 = output
EDIS;
}
void init_zone7(void)
{
// Make sure the XINTF clock is enabled
SysCtrlRegs.PCLKCR3.bit.XINTFENCLK = 1;
// Configure the GPIO for XINTF with a 16-bit data bus
// This function is in DSP2833x_Xintf.c
InitXintf16Gpio();
EALLOW;
// All Zones---------------------------------
// Timing for all zones based on XTIMCLK = SYSCLKOUT
XintfRegs.XINTCNF2.bit.XTIMCLK = 0;
// Buffer up to 3 writes
XintfRegs.XINTCNF2.bit.WRBUFF = 3;
// XCLKOUT is enabled
XintfRegs.XINTCNF2.bit.CLKOFF = 0;
// XCLKOUT = XTIMCLK
XintfRegs.XINTCNF2.bit.CLKMODE = 0;
// Disable XHOLD to prevent XINTF bus from going into high impedance state
// whenever TZ3 signal goes low. This occurs because TZ3 on GPIO14 is
// shared with HOLD of XINTF
XintfRegs.XINTCNF2.bit.HOLD = 1;
// Zone 7------------------------------------
// When using ready, ACTIVE must be 1 or greater
// Lead must always be 1 or greater
// Zone write timing
XintfRegs.XTIMING7.bit.XWRLEAD = 1;
XintfRegs.XTIMING7.bit.XWRACTIVE = 2;
XintfRegs.XTIMING7.bit.XWRTRAIL = 1;
// Zone read timing
XintfRegs.XTIMING7.bit.XRDLEAD = 1;
XintfRegs.XTIMING7.bit.XRDACTIVE = 3;
XintfRegs.XTIMING7.bit.XRDTRAIL = 0;
// don't double all Zone read/write lead/active/trail timing
XintfRegs.XTIMING7.bit.X2TIMING = 0;
// Zone will not sample XREADY signal
XintfRegs.XTIMING7.bit.USEREADY = 0;
XintfRegs.XTIMING7.bit.READYMODE = 0;
// 1,1 = x16 data bus
// 0,1 = x32 data bus
// other values are reserved
XintfRegs.XTIMING7.bit.XSIZE = 3;
EDIS;
__asm(" RPT #7 || NOP");
}
好长一段程序,不能怀疑是否时序有问题,那就借助示波器等工具来查吧。
配置ADS7865内部DAC参考电压,是不是读写都用到了呢。是的话,读写都可以,时序就应该正确啊。电压值是从寄存器里读出来的吗。读别的寄存器看看是否正常。看看数据是否为原始数据。若原始数据不对。要么是读写操作有问题,要么是发送的指令到接收数据的过程不对。逐一排查一下。分析时序最好看示波器