F28335 AD 如果采用软件触发AD转换的话,如何控制采样频率呢?
是否有例程可以参考呢?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我改了个工程,试了下断点,可以重复的进timer的中断和ADC的中断,但是采样出来的结果特别奇怪,您能帮忙看看程序吗?
main()
{
// Uint16 i;
Uint16 array_index;
InitSysCtrl();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
DINT;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
// EALLOW;
// PieVectTable.TINT0 = &TINT0_ISR;
// PieVectTable.ADCINT = &adc_isr;
// EDIS;
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 150, 100);
StartCpuTimer0();
InitAdc();
// IER |= M_INT1;
IER |= M_INT1; // Enable CPU Interrupt 1
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
EINT;
ERTM;
// For this example, init the ADC
// EALLOW;
// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 级联
AdcRegs.ADCTRL3.bit.SMODE_SEL = 1; //同步采样
AdcRegs.ADCTRL1.bit.CONT_RUN = 0; // 启停模式
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0; // 设置1对转换通道
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; //设置ADC A0/B0为第一个变换
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; //使能SEQ1中断
// wait for adc interrupt
for(;;)
{
LoopCount++;
}
}
interrupt void ADCINT_ISR(void) // ADC
{ // SampleCount++;
adc[0]= AdcRegs.ADCRESULT0 >>4;
adc[1]= AdcRegs.ADCRESULT1 >>4;
if (count<500)
{ abc1[count]= adc[0];
abc2[count]= adc[1];
count ++;
}
else
{ count=0;
}
EALLOW;
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;
// PieCtrlRegs.PIEACK.bit.ACK1=1; //响应PIE同组中断
AdcRegs.ADCST.bit.INT_SEQ1_CLR=1; //清除AD中断的标志位
// EINT; //使能全局中断
// Insert ISR Code here
// To receive more interrupts from this PIE group, acknowledge this interrupt
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
// asm (" ESTOP0");
// for(;;);
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
return;
}
// INT1.7
interrupt void TINT0_ISR(void) // CPU-Timer 0
{ CpuTimer0.InterruptCount++;
// Acknowledge this interrupt to receive more interrupts from group 1
//0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
return;
// Insert ISR Code here
// To receive more interrupts from this PIE group, acknowledge this interrupt
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
// asm (" ESTOP0");
// for(;;);
}
主函数以及两个中断函数
能帮忙看看为什么这转化后不正常吗
void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
// *IMPORTANT*
// The ADC_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; // 使能ADC时钟
ADC_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 DSP2833x_Examples.h file must
// contain the correct CPU clock period in nanoseconds.
AdcRegs.ADCTRL3.all = 0x00E0; // Power up bandgap/reference/ADC circuits
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
EALLOW;
DSP28x_usDelay(50);
AdcRegs.ADCTRL1.bit.RESET = 0; //0:无效,1:复位整个ADC模块
AdcRegs.ADCTRL1.bit.CPS = 0; //转换时间预标定器 0:f=CLK/1 1:f=CLK/2
AdcRegs.ADCTRL1.bit.ACQ_PS=4; //window ACQ_PS*Tclk(采样时间选择)
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //0:非连续运行,1:连续运行
AdcRegs.ADCTRL3.bit.ADCCLKPS = 1; //ADC内核时钟分频器:ADCLK = HSPCLK--75M/[2xnx(CPS+1)]
AdcRegs.ADCTRL1.bit.SEQ_CASC=1; //0:双排序器模式,1:级联排序器模式
AdcRegs.ADCTRL3.bit.SMODE_SEL=0; //0:顺序采样,1:同步采样
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0; //最大转换通道数 = MAXCONVn +1
/**********************输入通道选择排序*************************************/
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0; //ADC_A0--Udc
// AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 1; //ADC_A1--Idc
// AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 2; //ADC_A2--Ic
// AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 3; //ADC_A3--Ib
// AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 4; //ADC_A4--Ia
// AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 5; //ADC_A5--Uc
// AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 6; //ADC_A6--Ub
// AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 7; //ADC_A7--Ua
// AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 8; //
// AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 9; //
// AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 10; //
// AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 11; //
/**********************输入通道选择排序*************************************/
EDIS;
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; //复位排序器:0=无效;1=复位排序器到CONV00状态
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; //SEQ1的启动转换触发
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; //级联排序器使能ePWM_SOCA
}
然后是主函数,
while(1)
{
while(AdcRegs.ADCST.bit.INT_SEQ1==0);
AdcRegs.ADCST.bit.INT_SEQ1_CLR=1;
a=AdcRegs.ADCRESULT0>>4;
b=a*1.0/4096*3;
Oled_Print_5_6x8(2,2,b);
}
}