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

📄 ccu6.c

📁 xc164的捕获比较单元6的使用例程
💻 C
字号:
//****************************************************************************
// @Module        Capture / Compare Unit 6 (CCU6)
// @Filename      CCU6.C
// @Project       CCU6.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC164CM-8F40
//
// @Compiler      Keil
//
// @Codegenerator 0.2
//
// @Description   This file contains functions that use the CCU6 module.
//
//----------------------------------------------------------------------------
// @Date          2006-8-3 13:41:47
//
//****************************************************************************

// USER CODE BEGIN (CCU6_General,1)

// USER CODE END



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

#include "MAIN.H"

// USER CODE BEGIN (CCU6_General,2)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,3)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,4)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,5)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,6)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,7)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,8)

// USER CODE END


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

// USER CODE BEGIN (CCU6_General,9)

// USER CODE END


//****************************************************************************
// @Function      void CCU6_vInit(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the initialization function of the CCU6 function 
//                library. It is assumed that the SFRs used by this library 
//                are in reset state. 
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2006-8-3
//
//****************************************************************************

// USER CODE BEGIN (Init,1)

// USER CODE END

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

  // USER CODE END

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Timer 12:
  ///  -----------------------------------------------------------------------
  ///  - prescaler factor is 1
  ///  - timer 12 run bit is set
  ///  - single shot mode is disabled
  ///  - timer 12 works in center aligned mode
  ///  - interrupt on period match is enabled
  ///  - interrupt on one match is enabled

  CCU6_T12PR     =  0x07CF;      // load CCU6 T12 period register

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Timer 13:
  ///  -----------------------------------------------------------------------
  ///  - prescaler factor is 1
  ///  - timer 13 run bit is set
  ///  - single shot mode is disabled
  ///  - interrupt on period match is disabled
  ///  - interrupt on compare match is disabled

  CCU6_T13PR     =  0x0F9F;      // load CCU6 T13 period register

  CCU6_TCTR0     =  0x0080;      // load CCU6 timer control register 0
  CCU6_TCTR2     =  0x0020;      // load CCU6 timer control register 2

  ///  -----------------------------------------------------------------------
  ///  Configuration of Multi Channel Mode:
  ///  -----------------------------------------------------------------------
  ///  - multi channel mode is disabled


  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Channel 0:
  ///  -----------------------------------------------------------------------
  ///  - compare mode 3 is selected
  ///  - T12 modulation for output CC60 is enabled
  ///  - T13 modulation for output CC60 is disabled
  ///  - the trap functionality of the pin CC60 is enabled
  ///  - the compare output CC60 drives passive level while CC60ST is '0'
  ///  - the passive level of the output CC60 is '0'
  ///  - T12 modulation for output COUT60 is enabled
  ///  - T13 modulation for output COUT60 is disabled
  ///  - the trap functionality of the pin COUT60 is enabled
  ///  - the compare output COUT60 drives passive level while CC60ST is '1'
  ///  - the passive level of the output COUT60 is '0'
  ///  - dead time generation is enabled

  ///  - generation interrupt on flag ICC60R is disabled
  ///  - generation interrupt on flag ICC60F is disabled

  CCU6_CC60SR    =  0x03E8;      // load CCU6 capture/compare shadow register 
                                 // for channel 0

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Channel 1:
  ///  -----------------------------------------------------------------------
  ///  - compare mode 3 is selected
  ///  - T12 modulation for output CC61 is enabled
  ///  - T13 modulation for output CC61 is disabled
  ///  - the trap functionality of the pin CC61 is enabled
  ///  - the compare output CC61 drives passive level while CC61ST is '0'
  ///  - the passive level of the output CC61 is '0'
  ///  - T12 modulation for output COUT61 is enabled
  ///  - T13 modulation for output COUT61 is disabled
  ///  - the trap functionality of the pin COUT61 is enabled
  ///  - the compare output COUT61 drives passive level while CC61ST is '1'
  ///  - the passive level of the output COUT61 is '0'
  ///  - dead time generation is enabled

  ///  - generation interrupt on flag ICC61R is disabled
  ///  - generation interrupt on flag ICC61F is disabled

  CCU6_CC61SR    =  0x03E8;      // load CCU6 capture/compare shadow register 
                                 // for channel 1

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Channel 2:
  ///  -----------------------------------------------------------------------
  ///  - compare mode 3 is selected
  ///  - T12 modulation for output CC62 is enabled
  ///  - T13 modulation for output CC62 is disabled
  ///  - the trap functionality of the pin CC62 is enabled
  ///  - the compare output CC62 drives passive level while CC62ST is '0'
  ///  - the passive level of the output CC62 is '0'
  ///  - T12 modulation for output COUT62 is enabled
  ///  - T13 modulation for output COUT62 is disabled
  ///  - the trap functionality of the pin COUT62 is enabled
  ///  - the compare output COUT62 drives passive level while CC62ST is '1'
  ///  - the passive level of the output COUT62 is '0'
  ///  - dead time generation is enabled

  ///  - generation interrupt on flag ICC62R is disabled
  ///  - generation interrupt on flag ICC62F is disabled

  CCU6_CC62SR    =  0x03E8;      // load CCU6 capture/compare shadow register 
                                 // for channel 2

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 Channel 3:
  ///  -----------------------------------------------------------------------
  ///  - alternate output function COUT63 for the PWM signal generated by T13 
  ///    is enabled
  ///  - the trap functionality of the pin COUT63 is disabled
  ///  - the compare output COUT63 drives passive level while CC63ST is '0'
  ///  - the passive level of the output COUT63 is '0'
  ///  - T13 output is not inverted


  CCU6_CC63SR    =  0x07D0;      // load CCU6 capture/compare shadow register 
                                 // for channel 3


  CCU6_T12DTC    =  0x0701;      // load CCU6 dead time control register for 
                                 // timer T12

  CCU6_T12MSEL   =  0x0333;      // load CCU6 T12 campture/compare mode 
                                 // select register

  CCU6_CMPSTAT   =  0x2A00;      // load CCU6 compare status register

  CCU6_PSLR      =  0x0000;      // load CCU6 passive state level register

  CCU6_MODCTR    =  0x803F;      // load CCU6 modulation control register

  CCU6_MCMOUTS   =  0x0000;      // load CCU6 multi channel mode output 
                                 // control register

  CCU6_MCMCTR    =  0x0000;      // load CCU6 multi channel mode control 
                                 // register

  ///  - enable shadow transfer to T12 and T13
  CCU6_TCTR4     =  0x4040;      // load CCU6 timer control register 4

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 trap control:
  ///  -----------------------------------------------------------------------
  ///  - a trap can be generated by SW or by rising edge on #CTRAP
  ///  - the trap state is left when a zero-match of T12 (while counting up) 
  ///    is detected (synchronization to T12)
  ///  - bit TRPF is automatically cleared by HW (according to TRPPEN, TRPM0 
  ///    and TRPM1)
  ///  - trap interrupt is enabled


  CCU6_TRPCTR    =  0xBF00;      // load CCU6 trap control register

  ///  -----------------------------------------------------------------------
  ///  Configuration of CCU6 interrupt control:
  ///  -----------------------------------------------------------------------
  ///  - for channel 0 interrupts is node I2 selected
  ///  - for channel 1 interrupts is node I2 selected
  ///  - for channel 2 interrupts is node I2 selected
  ///  - for correct hall event interrupt is node I2 selected
  ///  - for error interrupts is node I2 selected
  ///  - for T12 interrupts is node I2 selected
  ///  - for T13 interrupts is node I2 selected


  CCU6_INP       =  0x2AAA;      // load CCU6 capture/compare interrupt node 
                                 // pointer register

  CCU6_IEN       =  0x04C0;      // load CCU6 capture/compare interrupt 
                                 // enable register


  ///  -----------------------------------------------------------------------
  ///  Configuration of the used CCU6 Channel Port Pins:
  ///  -----------------------------------------------------------------------
  ///  - P1L.0 is used for CAPCOM6 output (CC60)
  ///  - P1L.2 is used for CAPCOM6 output (CC61)
  ///  - P1L.4 is used for CAPCOM6 output (CC62)
  ///  - P1L.1 is used for CAPCOM6 output (COUT60)
  ///  - P1L.3 is used for CAPCOM6 output (COUT61)
  ///  - P1L.5 is used for CAPCOM6 output (COUT62)
  ///  - P1L.6 is used for CAPCOM6 output (COUT63)
  ///  - P1L.7 is used for CAPCOM6 input (#CTRAP)

  ALTSEL0P1L    |=  0x007F;      // select alternate output function
  P1L   = (P1L   & ~(uword)0x007F) | 0x007F;    //set data register
  DP1L  = (DP1L  & ~(uword)0x007F) | 0x007F;    //set direction register

  ///  -----------------------------------------------------------------------
  ///  Configuration of the used CCU6 Channels Interrupts:
  ///  -----------------------------------------------------------------------
  ///  NodeI2 service request node configuration:
  ///  - NodeI2 interrupt priority level (ILVL) = 12
  ///  - NodeI2 interrupt group level (GLVL) = 1
  ///  - NodeI2 group priority extension (GPX) = 0

  CCU6_T12IC     =  0x0071;     




  CCU6_TCTR4     =  0x0202;      // load CCU6 timer control register 4

  // USER CODE BEGIN (Init,3)

  // USER CODE END

} //  End of function CCU6_vInit


//****************************************************************************
// @Function      void CCU6_viNodeI2(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the interrupt service routine for the CCU6 node I2. 
//                If the content of the corresponding compare timer 
//                (configurable) equals the content of the capture/compare 
//                register or if a capture event occurs at the associated 
//                port pin, the interrupt request flag is set and an 
//                interrupt is triggered (only if enabled).
//                Please note that you have to add application specific code 
//                to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2006-8-3
//
//****************************************************************************

// USER CODE BEGIN (NodeI2,1)

// USER CODE END

void CCU6_viNodeI2(void) interrupt CCU6_NodeI2_INT
{
  // USER CODE BEGIN (NodeI2,2)

  // USER CODE END

  if(CCU6_IS & 0x0040)  // if CCU6_IS_T12OM
  {
    // timer T12 one match detection

    // USER CODE BEGIN (NodeI2,20)

    // USER CODE END

    CCU6_ISR = 0x0040;  // clear flag CCU6_IS_T12OM
  }

  if(CCU6_IS & 0x0080)  // if CCU6_IS_T12PM
  {
    // timer T12 period match detection

    // USER CODE BEGIN (NodeI2,19)

    // USER CODE END

    CCU6_ISR = 0x0080;  // clear flag CCU6_IS_T12PM
  }

  if(CCU6_IS & 0x0400)  // if CCU6_IS_TRPF
  {
    // trap detection

    // USER CODE BEGIN (NodeI2,17)

    // USER CODE END

    CCU6_ISR = 0x0400;  // clear flag CCU6_IS_TRPF
  }


} //  End of function CCU6_viNodeI2




// USER CODE BEGIN (CCU6_General,10)

// USER CODE END

⌨️ 快捷键说明

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