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

📄 etpu_qd.c

📁 FREESCALE MCF52XX eTPU控制三相电机的程序
💻 C
📖 第 1 页 / 共 3 页
字号:
*PURPOSE      : This function changes the QD mode to slow.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: Error code that can be returned is: FS_ETPU_ERROR_VALUE.
*******************************************************************************/
int32_t fs_etpu_qd_set_slow_mode(uint8_t channel_primary)
{
   /* Parameters bounds check */
   #ifdef FS_ETPU_MC_PARAM_CHECK
   if(((channel_primary>31)&&(channel_primary<64))||(channel_primary>95))
   {
      return(FS_ETPU_ERROR_VALUE);
   }
   #endif

   fs_etpu_set_chan_local_8(channel_primary, FS_ETPU_QD_MODE_CURRENT_OFFSET,
                            FS_ETPU_QD_MODE_SLOW);

   return(0);
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_pc
*PURPOSE      : This function returns the Position Counter value.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: Position Counter value.
*******************************************************************************/
int24_t fs_etpu_qd_get_pc( uint8_t channel_primary)
{
   return(fs_etpu_get_chan_local_24s(channel_primary, FS_ETPU_QD_PC_OFFSET));
}

/******************************************************************************
*FUNCTION     : fs_etpu_qd_get_pc_sc
*PURPOSE      : This function returns the Position Counter for SC value.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: Position Counter for SC value.
*******************************************************************************/
int24_t fs_etpu_qd_get_pc_sc( uint8_t channel_primary)
{
   return(fs_etpu_get_chan_local_24s(channel_primary, FS_ETPU_QD_PC_SC_OFFSET));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_rc
*PURPOSE      : This function returns the Revolution Counter value.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: Revolution Counter value.
*******************************************************************************/
int24_t fs_etpu_qd_get_rc( uint8_t channel_primary)
{
   return(fs_etpu_get_chan_local_24s(channel_primary, FS_ETPU_QD_RC_OFFSET));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_direction
*PURPOSE      : This function returns the motion system direction.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: The returned value can be one of:
*               0 - FS_ETPU_QD_DIRECTION_INC
*               1 - FS_ETPU_QD_DIRECTION_DEC
*******************************************************************************/
int8_t fs_etpu_qd_get_direction(uint8_t channel_primary)
{
   if ((int8_t)(fs_etpu_get_chan_local_8(channel_primary,
       FS_ETPU_QD_DIRECTION_OFFSET)) > 0)
      return(FS_ETPU_QD_DIRECTION_INC);
   else
      return(FS_ETPU_QD_DIRECTION_DEC);
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_mode
*PURPOSE      : This function returns the current mode of QD operation.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: The returned value can be one of:
*               1 - FS_ETPU_QD_MODE_SLOW
*               2 - FS_ETPU_QD_MODE_NORMAL
*               4 - FS_ETPU_QD_MODE_FAST
*******************************************************************************/
uint8_t fs_etpu_qd_get_mode(uint8_t channel_primary)
{
   return((uint8_t)(fs_etpu_get_chan_local_8(channel_primary,
                                        FS_ETPU_QD_MODE_CURRENT_OFFSET) & 0x7));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_tcr
*PURPOSE      : This function returns the TCR time of the last detected
*               transition.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: TCR time of the last transition.
*******************************************************************************/
uint24_t fs_etpu_qd_get_tcr( uint8_t channel_primary)
{
   return(fs_etpu_get_chan_local_24(channel_primary, FS_ETPU_QD_LAST_EDGE_OFFSET));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_period
*PURPOSE      : This function returns the QD period.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: QD period.
*******************************************************************************/
uint24_t fs_etpu_qd_get_period( uint8_t channel_primary)
{
   return(fs_etpu_get_chan_local_24(channel_primary, FS_ETPU_QD_PERIOD_OFFSET));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_pinA
*PURPOSE      : This function returns the current state of Primary (Phase A)
*               input signal.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: State of Phase A input channel.
*******************************************************************************/
uint8_t fs_etpu_qd_get_pinA( uint8_t channel_primary)
{
   return((uint8_t)(fs_etpu_get_chan_local_8(channel_primary,
                   FS_ETPU_QD_PINS_OFFSET) & 0x1));
}

/*******************************************************************************
*FUNCTION     : fs_etpu_qd_get_pinB
*PURPOSE      : This function returns the current state of Secondary (Phase B)
*               input signal.
*INPUTS NOTES : This function has 1 parameter:
*  channel_primary - This is the Primary channel number (Phase A).
*                    0-31 for ETPU_A and 64-95 for ETPU_B.
*
*RETURNS NOTES: State of Phase B input channel.
*******************************************************************************/
uint8_t fs_etpu_qd_get_pinB( uint8_t channel_primary)
{
   return((uint8_t)((fs_etpu_get_chan_local_8(channel_primary,
                    FS_ETPU_QD_PINS_OFFSET) &  0x2) >> 1));
}


/*******************************************************************************
*=============== TPU3 API Compatibility Functions ==============================
*******************************************************************************/

/*******************************************************************************
*FUNCTION      : tpu_fqd_init
*PURPOSE       : This routine is used to initialize a pair of eTPU channels
*                to run the QD function.
*INPUTS NOTES  : This function has 4 parameters:
*               *tpu     - This is a pointer to the TPU3 module. Not used.
*               channel  - This is the channel number of the primary QD channel.
*                          The next channel is used as the secondary.
*                          0-30 for ETPU_A and 64-94 for ETPU_B.
*               priority - This is the priority to assign to the QD function.
*                          This parameter should be assigned a value of:
*                          FS_ETPU_PRIORITY_HIGH, FS_ETPU_PRIORITY_MIDDLE,
*                          FS_ETPU_PRIORITY_LOW or FS_ETPU_PRIORITY_DISABLE.
*               init_position - This is the starting position of the counter.
*RETURNS NOTES : none
*******************************************************************************/
void tpu_fqd_init(struct TPU3_tag *tpu,
                  UINT8 channel,
                  UINT8 priority,
                  INT16 init_position)
{
   fs_etpu_qd_init( channel,
                    0,
                    0,
                    FS_ETPU_QD_PRIM_SEC,
                    priority,
                    0,
                    FS_ETPU_TCR1,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

     fs_etpu_qd_set_pc( channel,
                        init_position);
}

/*******************************************************************************
*FUNCTION      : tpu_fqd_current_mode
*PURPOSE       : This function returns the current mode of the QD channels.
*INPUTS NOTES  : This function has 2 parameters:
*                 *tpu    - This is a pointer to the TPU3 module. Not used.
*                 channel - This is the Primary or Secondary channel number.
*                           0-31 for ETPU_A and 64-95 for ETPU_B.
*RETURNS NOTES : The current mode which will be FS_ETPU_QD_MODE_NORMAL or
*                FS_ETPU_QD_MODE_FAST.
*******************************************************************************/
UINT8 tpu_fqd_current_mode(struct TPU3_tag *tpu,
                           UINT8 channel)
{
   return ((UINT8)fs_etpu_qd_get_mode(channel));
}

/*******************************************************************************
*FUNCTION      : tpu_fqd_position
*PURPOSE       : This function returns the current Position Counter value
*                of QD channels.
*INPUTS NOTES  : This function has 2 parameters:
*                 *tpu    - This is a pointer to the TPU3 module. Not used.
*                 channel - This is the Primary or Secondary channel number.
*                           0-31 for ETPU_A and 64-95 for ETPU_B.
*RETURNS NOTES : The current Position Counter value.
*******************************************************************************/
INT16 tpu_fqd_position(struct TPU3_tag *tpu,
                       UINT8 channel)
{
   return((INT16)fs_etpu_qd_get_pc(channel));
}

/*******************************************************************************
*FUNCTION      : tpu_fqd_data
*PURPOSE       : This function returns the data parameters associated with
*                the QD channels.
*INPUTS NOTES  : This function has 6 parameters:
*            *tpu           - This is a pointer to the TPU3 module. Not used.
*            channel        - This is the Primary or Secondary channel number.
*                             0-31 for ETPU_A and 64-95 for ETPU_B.
*            *tcr1          - The current Value of the TCR1 timebase.
*            *edge          - The last edge time.
*            *primary_pin   - The current state of the Primary channel, this
*                             will be TPU_FQD_PIN_HIGH or TPU_FQD_PIN_LOW.
*            *secondary_pin - The current state of the Secondary channel, this
*                             will be TPU_FQD_PIN_HIGH or TPU_FQD_PIN_LOW.
*RETURNS NOTES : none
*******************************************************************************/
void tpu_fqd_data(struct TPU3_tag *tpu,
                  UINT8 channel,
                  INT16 *tcr1,
                  INT16 *edge,
                  INT16 *primary_pin,
                  INT16 *secondary_pin)
{
   *tcr1=(INT16)(eTPU->TB1R_A.R);
   *edge=(INT16)(fs_etpu_qd_get_tcr(channel));
   *primary_pin  =(INT16)(fs_etpu_qd_get_pinA(channel));
   *secondary_pin=(INT16)(fs_etpu_qd_get_pinB(channel));
}

/*********************************************************************
 *
 * Copyright:
 *  Freescale Semiconductor, INC. All Rights Reserved.
 *  You are hereby granted a copyright license to use, modify, and
 *  distribute the SOFTWARE so long as this entire notice is
 *  retained without alteration in any modified and/or redistributed
 *  versions, and that such modified versions are clearly identified
 *  as such. No licenses are granted by implication, estoppel or
 *  otherwise under any patents or trademarks of Freescale
 *  Semiconductor, Inc. This software is provided on an "AS IS"
 *  basis and without warranty.
 *
 *  To the maximum extent permitted by applicable law, Freescale
 *  Semiconductor DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
 *  INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
 *  PARTICULAR PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH
 *  REGARD TO THE SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
 *  AND ANY ACCOMPANYING WRITTEN MATERIALS.
 *
 *  To the maximum extent permitted by applicable law, IN NO EVENT
 *  SHALL Freescale Semiconductor BE LIABLE FOR ANY DAMAGES WHATSOEVER
 *  (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
 *  BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER
 *  PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
 *
 *  Freescale Semiconductor assumes no responsibility for the
 *  maintenance and support of this software
 ********************************************************************/

⌨️ 快捷键说明

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