Tms320F28335中软件触发信号采样(ADC)
//該程序用于信號ADC,其中,采用定時器0中斷讀取采樣結果 ?//
//該程序ADC觸發(fā)源為軟件觸發(fā)(S/w),然后,通過AdcRegs.ADCST.bit.INT_SEQ1標志位為1判斷轉換結果
//采用連續(xù)采樣方式,連續(xù)采集A0和A1口數(shù)據(jù),A0口數(shù)據(jù)放在Result0,2-15中,A1口數(shù)據(jù)放到Result1中
#include "DSP2833x_Device.h" ? ? ? ? ? ? ? // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" ? ? ? ? ? ? // DSP2833x Examples Include File
interrupt void cpu_timer0_isr(void);
#define startCpuTimer0() CpuTimer0Regs.TCR.bit.TSS=0
//int ncount;
// ADC start parameters
#if (CPU_FRQ_150MHZ) ? ? // Default - 150 MHz SYSCLKOUT
? #define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) ? = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
? #define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) ? = 25.0 MHz
#endif
#define ADC_CKPS ? 0x0 ? // ADC module clock = HSPCLK/1 ? ? ?= 25.5MHz/(1) ? = 25.0 MHz
#define ADC_SHCLK ?0x1 ? // S/H width in ADC module periods ? ? ? ? ? ? ? ? ?= 2 ADC cycle
#define BUF_SIZE ? 1024 ?// Sample buffer size
// Global variable for this example
Uint16 SampleTable[BUF_SIZE];
Uint16 SampleTable1[BUF_SIZE];
Uint16 Data=0;
void main(void)
{
? ? Uint16 i;
? ? // Step 1. Initialize System Control:
? ? // PLL, WatchDog, enable Peripheral Clocks
? ? // This example function is found in the DSP2833x_SysCtrl.c file.
? ? ? ?InitSysCtrl();
? ? // Specific clock setting for this example:
? ? ? ?EALLOW;
? ? ? ?SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
? ? ? ?EDIS;
? ? ? ?EALLOW;
? ? // Step 2. Initalize GPIO:
? ? ? ? GpioCtrlRegs.GPBMUX2.all=0x00000000; ? ?//功能選擇寄存器 普通IO使用,GPIO48屬于GPBMUX2
? ? ? ? GpioCtrlRegs.GPBDIR.all=0xFFFFFFFF; ? ? //設置為輸出模式
? ? ? ?EDIS;
? ? // 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 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();
? ?// Step 4. Initialize all the Device Peripherals:
? ?// This function is found in DSP2833x_InitPeripherals.c
? ?// InitPeripherals(); // Not required for this example
? ? ? ? ?InitAdc(); ? ? ? ? // For this example, init the ADC
? ?// Specific ADC setup for this example:
? ? ? ? ? ? AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; ?//01 采樣時間窗大小,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.ADCTRL1.bit.CPS = 0;
? ? ? ? ? ? AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; //0
? ? ? ? ? ? AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; ? ? ? ?// 1 ?Cascaded mode
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
? ? ? ? ? ? AdcRegs.ADCTRL1.bit.CONT_RUN = 1; ? ? ? // Setup continuous run
? ? ? ? ? ? AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; ? ? ? // Enable Sequencer override feature
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ1.all = 0x10; ? ? ? ? // 將Results0、Results2—15全部指向A0,Results1存儲A1
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ2.all = 0x0;
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ3.all = 0x0;
? ? ? ? ? ? AdcRegs.ADCCHSELSEQ4.all = 0x0;
? ? ? ? ? ? AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x1; ?// convert and store in 8 results registers
? ? ? ? ? ? AdcRegs.ADCTRL2.all = 0x2000; ?// s/w啟動方式,啟動AD轉換
? // Interrupts that are used in this example are re-mapped to
? // ISR functions found within this file.
? ? ? ? ?EALLOW; ?// This is needed to write to EALLOW protected registers
? ? ? ? ?PieVectTable.TINT0 = &cpu_timer0_isr;
? ? ? ?//PieVectTable.XINT13 = &cpu_timer1_isr;
? ? ? ?//PieVectTable.TINT2 = &cpu_timer2_isr;
? ? ? ? ?EDIS; ? ?// This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// ? ? ? ? found in DSP2833x_CpuTimers.c
? ? ? ? ?InitCpuTimers(); ? // For this example, only initialize the Cpu Timers
? ? ? ? ?#if (CPU_FRQ_150MHZ)
// Configure CPU-Timer 0, 1, and 2 to interrupt every 100 usecond:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
? ? ? ? ? ConfigCpuTimer(&CpuTimer0, 150, 500);
//ConfigCpuTimer(&CpuTimer1, 150, 1000000);
//ConfigCpuTimer(&CpuTimer2, 150, 1000000);
? ? ? ? ?#endif
? ? ? ? ?#if (CPU_FRQ_100MHZ)
// Configure CPU-Timer 0, 1, and 2 to interrupt every 100 usecond:
// 100MHz CPU Freq, 1 second Period (in uSeconds)
? ? ? ? ? ? ? ConfigCpuTimer(&CpuTimer0, 100, 500)
? ? ? ? ? ? //ConfigCpuTimer(&CpuTimer1, 100, 1000000);
? ? ? ? ? ? //ConfigCpuTimer(&CpuTimer2, 100, 1000000);
? ? ? ? ?#endif
// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
// below settings must also be updated.
? ? // Step 5. User specific code, enable interrupts: 下面代碼已經(jīng)在ConfigCpuTimer中定義過了
? ? ? // ?啟動定時器
? ? ? ? startCpuTimer0();
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
? ? ? ? IER |= M_INT1;
? ? ? ? ? ? ? ?//IER |= M_INT13;
? ? ? ? ? ? ? ?//IER |= M_INT14;
?// Enable TINT0 in the PIE: Group 1 interrupt 7
? ? ? ? PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
? ? ? ? EINT; ? // Enable Global interrupt INTM
? ? ? ? ERTM; ? // Enable Global realtime interrupt DBGM
? ? ? ? for (i=0; i<BUF_SIZE; i++)
? ? ? ? {
? ? ? ? ? SampleTable[i] = 0;
? ? ? ? ? SampleTable1[i] = 0;
? ? ? ? }
? ? while(1)
? ? {
? ? }
}
interrupt void cpu_timer0_isr(void)
{ ?Uint16 i;
? ?CpuTimer0.InterruptCount++; ?//中斷計數(shù)器,用于計算中斷的響應次數(shù)? if(CpuTimer0.InterruptCount==2000) ?//每個1sLED閃爍一次,用于程序調(diào)試,可刪除
? ? ? ?{
? ? ? ?GpioDataRegs.GPBTOGGLE.bit.GPIO48 = 1;
? ? ? ?CpuTimer0.InterruptCount=0;
? ? ? ?}
?for (i=0; i<BUF_SIZE-1; i++) //更新數(shù)據(jù)緩存區(qū)
? ? ? ?{
? ? ? ? ?SampleTable[i] = SampleTable[i+1];
? ? ? ? ?SampleTable1[i] = SampleTable1[i+1];
? ? ? ? ?}
? ?while (AdcRegs.ADCST.bit.INT_SEQ1== 0){} ?//等待直到轉換結束
? ? ?SampleTable[BUF_SIZE-1]= AdcRegs.ADCRESULT0>>4;
? ? ?SampleTable1[BUF_SIZE-1]= AdcRegs.ADCRESULT1>>4;
? ? ?AdcRegs.ADCST.bit.INT_SEQ1_CLR=1; //清除轉換結束標志位
? ? ?PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
? ? ?CpuTimer0Regs.TCR.bit.TIF=1;//清除中斷標志位
? ? ?CpuTimer0Regs.TCR.bit.TRB=1;//重新裝載初值
}
?
總結
以上是生活随笔為你收集整理的Tms320F28335中软件触发信号采样(ADC)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简明python教程五----数据结构(
- 下一篇: 专业精神-希波克拉底的誓言(转载)