⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.c

📁 keil下开发的永磁同步电机矢量控制程序
💻 C
字号:
//****************************************************************************
// @Module        Analog / Digital Converter (ADC)
// @Filename      ADC.C
// @Project       svm.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC167CI-16F40
//
// @Compiler      Keil
//
// @Codegenerator 2.1
//
// @Description   This file contains functions that use the ADC module.
//
//----------------------------------------------------------------------------
// @Date          19.12.2003 11:31:22
//
//****************************************************************************

// USER CODE BEGIN (ADC_General,1)

// USER CODE END



//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"

// USER CODE BEGIN (ADC_General,2)

// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************

// USER CODE BEGIN (ADC_General,3)

// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************

// USER CODE BEGIN (ADC_General,4)

// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************

// USER CODE BEGIN (ADC_General,5)

// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************

// USER CODE BEGIN (ADC_General,6)

// USER CODE END


//****************************************************************************
// @Global Variables
//****************************************************************************

// USER CODE BEGIN (ADC_General,7)
unsigned int idata adcresult;
// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************

// USER CODE BEGIN (ADC_General,8)

// USER CODE END


//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************

// USER CODE BEGIN (ADC_General,9)

// USER CODE END


//****************************************************************************
// @Function      void ADC_vInit(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the initialization function of the ADC function 
//                library. It is assumed that the SFRs used by this library 
//                are in its reset state. 
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          19.12.2003
//
//****************************************************************************

// USER CODE BEGIN (Init,1)

// USER CODE END

void ADC_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  ///  - enhanced mode is selected
  ///  - auto scan single conversion mode is selected
  ///  - 10-bit resolution
  ///  - once converts a sequence beginning with channel 4
  ///  - ADC start bit is reset
  ///  - wait for ADDAT read mode is enabled
  ///  - converter basic clock tbc is fcpu / 2
  ///  - sample time tsc is tbc * 8
  ///  - conversion time tc = 2,950 祍
  ///  - channel injection is enabled
  ///  - inject channel 0
  ///  - trigger input CCU6 selected
  ///  - resolution for injection mode is 10-bit
  ///  - converter basic clock tbc for injection mode is fcpu / 2
  ///  - sample time tsc for injection mode is tbc * 8
  ///  - conversion time in injection mode tc = 2,950 祍

  ADC_CTR0       =  0xA644;      // load ADC control register 0

  ADC_CTR2       =  0x0040;      // load ADC control register 2

  ADC_DAT2       =  0x0000;      // load A/D converter 2 result register

  ADC_CTR2IN     =  0x0040;      // load ADC injection control register 2



  ///  -----------------------------------------------------------------------
  ///  Configuration of the used ADC Interrupts:
  ///  -----------------------------------------------------------------------
  ///  Conv service request node configuration:
  ///  - Conv interrupt priority level (ILVL) = 14
  ///  - Conv interrupt group level (GLVL) = 0
  ///  - Conv group priority extension (GPX) = 0

  ADC_CIC        =  0x0078;     

  ///  Use PEC channel 0 for ADC Conv INT:
  ///  - decrement counter
  ///  - increment destination pointer
  ///  - transfer a word
  ///  - service End of PEC interrrupt by a EOP interrupt node is disabled

  PECC0          =  0x0202;      // load PECC0 control register

  SRCP0  =  _sof_(&ADC_DAT);  //set source pointer

  //// - DO NOT FORGET TO SET THE DESTINATION-POINTER FOR PECC CHANNEL 0 
  ////   BECAUSE IT IS SELECTED FOR USER DEFINED

  ///  Error service request node configuration:
  ///  - Error interrupt priority level (ILVL) = 11
  ///  - Error interrupt group level (GLVL) = 1
  ///  - Error group priority extension (GPX) = 0

  ADC_EIC        =  0x006D;     

  ///  Use PEC channel 5 for ADC Error INT:
  ///  - decrement counter
  ///  - increment destination pointer
  ///  - transfer a word
  ///  - service End of PEC interrrupt by a EOP interrupt node is disabled

  PECC5          =  0x2202;      // load PECC5 control register

  SRCP5  =  _sof_(&ADC_DAT2);  //set source pointer

  //// - DO NOT FORGET TO SET THE DESTINATION-POINTER FOR PECC CHANNEL 5 
  ////   BECAUSE IT IS SELECTED FOR USER DEFINED


  ///  -----------------------------------------------------------------------
  ///  Configuration of the used ADC Port Pins:
  ///  -----------------------------------------------------------------------


  P5DIDIS        =  0x0000;      // load Port 5 digital input disable register



  // USER CODE BEGIN (Init,3)
	DSTP0=_sof_(&adc_result[0]);
	DSTP5=_sof_(&adc_dclink_res[0]);
  // USER CODE END

} //  End of function ADC_vInit


//****************************************************************************
// @Function      void ADC_viConv(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the interrupt service routine for the ADC. It is 
//                called at the end of each conversion. The user obtains the 
//                conversion result by calling the function ADC_uwReadConv().
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          19.12.2003
//
//****************************************************************************

// USER CODE BEGIN (Conv,1)

// USER CODE END

void ADC_viConv(void) interrupt ADC_C_INT
{
  // USER CODE BEGIN (Conv,2)


//	adcresult=ADC_uwReadConv();

  // USER CODE END

} //  End of function ADC_viConv


//****************************************************************************
// @Function      void ADC_viError(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the interrupt service routine for the overwrite 
//                error of the ADC (in standard mode) - the last measurement 
//                result was overwritten - , or the ISR for the end of an 
//                injected conversion - the result of the injected conversion 
//                has been written to ADC_DAT2. An overrun is not possible in 
//                channel injection mode; in this case the A/D measurement is 
//                stopped. To get the injected conversion result the user can 
//                call the function ADC_uwReadInject().
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          19.12.2003
//
//****************************************************************************

// USER CODE BEGIN (Error,1)

// USER CODE END

void ADC_viError(void) interrupt ADC_E_INT
{
  // USER CODE BEGIN (Error,2)

  // USER CODE END

} //  End of function ADC_viError




// USER CODE BEGIN (ADC_General,10)

// USER CODE END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -