ADC 顺序采样模式测试教程

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

ADC 顺序采样模式的代码记录:

一、ADC采样是什么

二、代码

//###########################################################################
//
// FILE:   Example_2833xAdcSeqModeTest.c
//
// TITLE:  ADC顺序采样模式测试
//
// ASSUMPTIONS:
//
//     此程序需要 DSP2833x头文件.
//
//    编译此例程前,在DSP2833x_Examples.h文件中确保CPU时钟速
//    度被合适地定义
//
//    连接信号到转换通道A0
// 功能描述:
//
//    通道A0一直被转换并被加载到缓存器中(SampleTable)
//
//    运行一会程序然后观察内容的变化
//
//       观察变量:
//          SampleTable - 加载的转换值.
//


#include "DSP2833x_Device.h"     // DSP2833x Header file Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

// ADC start parameters
// 设置CPU时钟频率
#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
// 手把手第169页
#define ADC_CKPS   0x1   // ADC module clock = HSPCLK/2*ADC_CKPS   = 25.0MHz/(1*2) = 12.5MHz
#define ADC_SHCLK  0xf   // S/H width in ADC module periods                        = 16 ADC clocks
#define AVG        1000  // Average sample limit
#define ZOFFSET    0x00  // Average Zero offset
#define BUF_SIZE   2048  // Sample buffer size

// Global variable for this example
Uint16 SampleTable[BUF_SIZE];

main()
{
   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/2*ADC_MODCLK
   EDIS;

// 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 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;  //采样窗口大小配置
   AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; // 对高速时钟进行分频
   AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;        // 1是选择级联模式
   AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;   // 采样通道1
   AdcRegs.ADCTRL1.bit.CONT_RUN = 1;       // 连续转换模式


// Step 5. User specific code, enable interrupts:


// Clear SampleTable
   for (i=0; i<BUF_SIZE; i++)
   {
     SampleTable[i] = 0;
   }

   // Start SEQ
   AdcRegs.ADCTRL2.all = 0x2000; // SOC_SEQ1 = 1,立即复位序列发生器状态为CONV00

   // Take ADC data and log the in SampleTable array
   for(;;)
   {
     for (i=0; i<AVG; i++)
     {
        while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt,等待,直到转换完成,然后读取结果
        AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;   //清除标志位
        SampleTable[i] =((AdcRegs.ADCRESULT0>>4));
     }
   }
}

//===========================================================================
// No more.
//===========================================================================


总结

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值