// TI File $Revision: /main/3 $
// Checkin $Date: July 2, 2007 11:33:46 $
//###########################################################################
//
// FILE: Example_281xAdc.c
//
// TITLE: DSP281x ADC Example Program.
//
// ASSUMPTIONS:
//
// This program requires the DSP281x V1.00 header files.
// As supplied, this project is configured for "boot to H0" operation.
//
// Make sure the CPU clock speed is properly defined in
// DSP281x_Examples.h before compiling this example.
//
// Connect signals to be converted to A2 and A3.
//
//
// DESCRIPTION:
//
// This example sets up the PLL in x10/2 mode, divides SYSCLKOUT
// by six to reach a 25Mhz HSPCLK (assuming a 30Mhz XCLKIN). The
// clock divider in the ADC is not used so that the ADC will see
// the 25Mhz on the HSPCLK. Interrupts are enabled and the EVA
// is setup to generate a periodic ADC SOC on SEQ1. Two channels
// are converted, ADCINA3 and ADCINA2.
//
// Watch Variables:
//
// Voltage1[10] Last 10 ADCRESULT0 values
// Voltage2[10] Last 10 ADCRESULT1 values
// ConversionCount Current result number 0-9
// LoopCount Idle loop counter
//
//
//###########################################################################
// $TI Release: DSP281x Header Files V1.11 $
// $Release Date: September 26, 2007 $
//###########################################################################
#include "DSP2833x_Device.h" // DSP281x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP281x Examples Include File
//#include "device.h" // DSP2812EVM Device Include File
#include "math.h"
#define DAC1_OUT *( volatile unsigned int * )( 0x00240004 )
#define DAC2_OUT *( volatile unsigned int * )( 0x00240005 )
#define DAC3_OUT *( volatile unsigned int * )( 0x00240006 )
#define DAC4_OUT *( volatile unsigned int * )( 0x00240007 )
#define DAC_LDC *( volatile unsigned int * )( 0x00260000 )
void dac_ldc_ctl(unsigned int ldcdata);
void dac_transparent(unsigned int DA_num ,unsigned int trans_dat);
float sindat;
main()
{
float i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
InitXintf();
// For this example, set HSPCLK to SYSCLKOUT / 6 (25Mhz assuming 150Mhz SYSCLKOUT)
EALLOW;
SysCtrlRegs.HISPCP.all = 0x3; // HSPCLK = SYSCLKOUT/6
EDIS;
// Step 2. Initialize GPIO:
// This example function is found in the DSP281x_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 DSP281x_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 DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
// Wait for ADC interrupt
while(1)
{
for(i=0;i<256.0;i++) {
sindat = sin((i/255.0)*6.28)+1.000;
sindat = sindat * 2047.000 ;
dac_transparent(1 ,(unsigned int )sindat);
sindat = cos((i/255.0)*6.2830)+1.000;
sindat = sindat * 2047.000 ;
dac_transparent(2 ,(unsigned int )sindat);
if(i<128){
dac_transparent(3 ,0);
}else {
dac_transparent(3 ,4095);}
sindat = i*16 ;
dac_transparent(4 ,(unsigned int )sindat);
}
}
}
void dac_ldc_ctl(unsigned int ldcdata)
{
DAC_LDC = ldcdata;
}
void dac_transparent(unsigned int DA_num ,unsigned int trans_dat)
{
unsigned int dactrans_flag = 0;
switch (DA_num)
{
case 1 : DAC1_OUT = trans_dat ;
dactrans_flag = 1;
break;
case 2 : DAC2_OUT = trans_dat ;
dactrans_flag = 1;
break;
case 3 : DAC3_OUT = trans_dat ;
dactrans_flag = 1;
break;
case 4 : DAC4_OUT = trans_dat ;
dactrans_flag = 1;
break;
default : break;
}
if (dactrans_flag == 1){
dac_ldc_ctl(0x00);
DELAY_US(0xf);
dac_ldc_ctl(0xff);
dactrans_flag = 0;
}
}
评论0