我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
zehao pan:
本人新手另外附上ADC.C文件中初始化的内容
void InitAdc(void){ extern void DSP28x_usDelay(Uint32 Count);
// *IMPORTANT* // The Device_cal function, which copies the ADC calibration values from TI reserved // OTP into the ADCREFSEL and ADCOFFTRIM registers, occurs automatically in the // Boot ROM. If the boot ROM code is bypassed during the debug process, the // following function MUST be called for the ADC to function according // to specification. The clocks to the ADC MUST be enabled before calling this // function. // See the device data manual and/or the ADC Reference // Manual for more information.
EALLOW; SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; (*Device_cal)(); EDIS;
// To powerup the ADC the ADCENCLK bit should be set first to enable // clocks, followed by powering up the bandgap, reference circuitry, and ADC core. // Before the first conversion is performed a 5ms delay must be observed // after power up to give all analog circuits time to power up and settle
// Please note that for the delay function below to operate correctly the // CPU_RATE define statement in the DSP2803x_Examples.h file must // contain the correct CPU clock period in nanoseconds. EALLOW; AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG EDIS;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels}
void InitAdcAio(){
EALLOW;
/* Configure ADC pins using AIO regs*/// This specifies which of the possible AIO pins will be Analog input pins.// NOTE: AIO1,3,5,7-9,11,13,15 are analog inputs in all AIOMUX1 configurations.// Comment out other unwanted lines.
GpioCtrlRegs.AIOMUX1.bit.AIO2 = 2; // Configure AIO2 for A2 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2; // Configure AIO4 for A4 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2; // Configure AIO6 for A6 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO10 = 2; // Configure AIO10 for B2 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO12 = 2; // Configure AIO12 for B4 (analog input) operation GpioCtrlRegs.AIOMUX1.bit.AIO14 = 2; // Configure AIO14 for B6 (analog input) operation
EDIS;}
我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
10#:
回复 zehao pan:
你的代码里:AdcRegs.ADCSOC0CTL.bit.CHSEL = 4;
配置的是使用ADC SOC0去对A4通道进行采样,因此上面的程序只会对A4通道进行处理。
同学,不能简单随便地拿一个例程就这样跑,需要去大概地看一下ADC是怎么工作的,寄存器是什么意思,如何配置再使用它呀。
我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
zehao pan:
回复 10#:
可能我帖子没表达清楚,例程中是采集片内温度传感器信息,我只想用4A通道单通道采集外部传感器信息,这样改有什么问题吗?我没想用其他通道啊
我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
10#:
回复 zehao pan:
那就没有问题啊,你使用SOC0对A4通道进行采样,只要A4通道外部是有接入被采样信号,那么采样结果就会被存放到AdcResult.ADCRESULT0寄存器里,你在中断程序里对它进行读取就可以。
我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
zehao pan:
回复 10#:
好吧,还有个问题我的通信程序里边
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数 { unsigned int i,j,k; SampleCountSCI++; for(i=0;i<9;i++) { SciaRegs.SCITXBUF=a.v[i]; //发送数据 for(j=0;j<600;j++) for(k=0;k<1000;k++); } SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应 EINT; // 开全局中断}
这一部分,只有当我加上
for(j=0;j<600;j++) for(k=0;k<1000;k++);
这样一个无效循环来演示才能正常显示字符,否则就是乱码,本来我用2812没有这种情况,28035就有了,我想问问这种情况正常不正常?
我用28035芯片的AD模块采集数据并传上位机,用Example_2803xAdcTempSensor.c例子,AD引脚只有选择ADCINA5通道并且内部温度传感器置1时才能识别传感器电压,选择其他通道时均不能识传感器电压,想问一下这是问什么?我把程序贴在下边
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 ConversionCount;
float TempSensorVoltage;
float adclo=0;float Dec;
char rec_data[9];
int SampleCount=0; //采样次数
int SampleCountSCI=0;static int AsciiBuff[9];#define array_size 9
typedef struct array array;
struct array
{
int v[array_size];
};
array a;
void HexToASCII(float data);
array f();
void scia_fifo_init(void);
void scia_echoback_init(void);
void main (void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitSciaGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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 DSP2803x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
EALLOW;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
InitAdc(); // For this example, init the ADC
scia_fifo_init();
scia_echoback_init();
// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
EALLOW;
AdcRegs.ADCCTL1.bit.TEMPCONV= 0;
EDIS;
// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
EDIS;
// Step 7. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
IER |= M_INT1;
IER |= M_INT9; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConversionCount = 0;
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// Wait for ADC interrupt
for(;;)
{
}
}
interrupt void adc_isr(void)
{
ConversionCount++;
TempSensorVoltage =((float)AdcResult.ADCRESULT0)*3.0/65520.0+adclo;;
// If 20 conversions have been logged, start over
/*if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;*/
HexToASCII(TempSensorVoltage);
a=f();
//SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; //清除TXFFINT标志位 AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
interrupt void SCITXINTA_ISR(void)//SCIA发送中断函数{
unsigned int i,j,k;
SampleCountSCI++;
for(i=0;i<9;i++)
{
SciaRegs.SCITXBUF=a.v[i]; //发送数据
for(j=0;j<300;j++)
for(k=0;k<1000;k++);
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
interrupt void SCIRXINTA_ISR(void) //SCIA接收中断函数
{
int i;
SampleCountSCI++;
for(i=0;i<9;i++)
{
rec_data[i]=SciaRegs.SCIRXBUF.all; //接收数据
}
Dec=(int)(rec_data[0]-0x30)*100.0+(int)(rec_data[1]-0x30)*10.0+(int)(rec_data[2]-0x30)*1.0
+(int)(rec_data[4]-0x30)/10.0+(int)(rec_data[5]-0x30)/100.0+(int)(rec_data[6]-0x30)/1000.0;
SciaRegs.SCIFFRX.bit.RXFIFORESET=0; //复位FIFO指针
SciaRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收FIFO
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; //清除RXFFINT标志位
PieCtrlRegs.PIEACK.all=0x0100; //使同组其他中断能够得到响应
EINT; // 开全局中断
}
//SCIA初始化
void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all=0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all=0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all=0x0003;
SciaRegs.SCICTL2.bit.TXINTENA=1;
SciaRegs.SCICTL2.bit.RXBKINTENA=1;
SciaRegs.SCIHBAUD=0x0000; // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
SciaRegs.SCILBAUD=0x00C2;
SciaRegs.SCICTL1.all=0x0023; // Relinquish SCI from Reset
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE020;
//SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x2061;
//SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void HexToASCII(float data){ AsciiBuff[0]=(Uint16)(data/100)%10+0x30; //Chr(48) 0
AsciiBuff[1]=(Uint16)(data/10)%10+0x30;
AsciiBuff[2]=(Uint16)((int)(data)%10)+0x30;
AsciiBuff[3]=46; //chr(46) .小数点
AsciiBuff[4]=((int)(data*10))%10+0x30;
AsciiBuff[5]=((int)(data*100))%10+0x30;
AsciiBuff[6]=((int)(data*1000))%10+0x30;
AsciiBuff[7]=0x20; //chr(9) 空格
AsciiBuff[8]=(Uint16)'\0'; //字符串的结尾有一个空符作为结束,不显示
if(AsciiBuff[0]==48&&AsciiBuff[1]==48)
{
AsciiBuff[0]=32;
AsciiBuff[1]=32;
}
if(AsciiBuff[0]==48)
{
AsciiBuff[0]=32;
}
}
array f()
{
array z;
int i;
for(i=0;i<9;i++)
z.v[i] = AsciiBuff[i];
return z;
}
zehao pan:
回复 10#:
非常感谢您的解答,非常完美