?? example_281xadcsoc.c
字號:
//###########################################################################
//
// 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 Exterenal
// is setup to generate a periodic ADC SOC on SEQ1. Two channels
// are converted, ADCINA3 and ADCINA2.
//
// Watch Variables:
//
// Frequence[10] Last 10 ADCRESULT0 values
// Voltage[10] Last 10 ADCRESULT1 values
// ConversionCount Current result number 0-9
// LoopCount Idle loop counter
//
//
//###########################################################################
//
// Original Author: D.F.
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 11 Sep 2003 | L.H. | Changes since previous version (v.58 Alpha)
// | | | Cleanup only. Results are shifted >> 4
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Frequence;//5,10,15,20,25,30,35,40,45,50Hz:
Uint16 Voltage; //30,49,66,88,110,154,176,180,220v:
Uint16 DSP281x_ADCIO(void)
{
InitAdc(); // For this example, init the ADC
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;
// Configure ADC:start/stop mode
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1 = 1; // Enable EXTSOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Wait for ADC interrupt
while(1)
{
LoopCount++;
}
}
interrupt void adc_isr(void) // interrupt :Keyword
{
Frequence =(Uint16)((AdcRegs.ADCRESULT0 >>6)/81.6);//Input the Frequence
Voltage =(Uint16)(4.4*Frequence);//Acorrding with VVVF curve get the voltage
// If 40 conversions have been logged, start over
if(ConversionCount == 1)
{
ConversionCount = 0;
}
else ConversionCount++;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -