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

📄 tpu_fqd_example2.c

📁 mpc564 时钟中断 时钟中断
💻 C
字号:
/**************************************************************************/
/* FILE NAME: tpu_fqd_example2.c              COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.0                                   All Rights Reserved     */
/*                                                                        */
/* DESCRIPTION: This sample program show a simple example of a program    */
/* that updates of the global "position" varible from an external         */
/* quadrature input singal. The signal is connected to TPU A on channels  */
/* 4 and 5.                                                               */
/* The program switches between fast and normal. If the count during a    */
/* certain period is more than a maximum count and the function is in     */
/* normal mode then it shifts to fast mode. If the count during a certain */
/* period is less than a minumun count and the function is in fast mode   */
/* then it shifts to normal mode.                                         */
/* The program is targeted for the MPC555 but should work on any MPC500   */
/* device with a TPU. For other devices the setup routines will also need */
/* to be changed.                                                         */
/*========================================================================*/
/* HISTORY           ORIGINAL AUTHOR: Jeff Loeliger                       */
/* REV      AUTHOR      DATE       DESCRIPTION OF CHANGE                  */
/* ---   -----------  ---------    ---------------------                  */
/* 1.0   J. Loeliger  03/Aug/02    Initial version of function.           */
/**************************************************************************/

#include "mpc555.h"     /* Define all of the MPC555 registers, this needs to */
                        /* changed if other MPC500 devices are used.         */
#include "mpc500.c"     /* Configuration routines for MPC555 EVB, will need */
                        /* to be changed if other hardware is used.         */
#include "mpc500_util.h"    /* Utility routines for using MPC500 devices */
#include "tpu_fqd.h"    /* TPU FQD functions */

#define FQD_INIT_COUNT 0x1000
#define FQD_MIN_DELTA_COUNT 0x0100
#define FQD_MAX_DELTA_COUNT 0x7000

#define ENCODER1 tpua,4 /* ENCODER1 is connected to TPU A channels 0 & 1 */

INT16 position;     /* global position value for quadrature input signal */

void main ()
{
    INT32 delta;
    INT32 new_position;
    INT32 delay;
    UINT8  mode;

    struct TPU3_tag *tpua = &TPU_A;   /* pointer for TPU routines */
    
    setup_mpc500(40);       /*Setup device and programm PLL to 40MHz*/	

    /* Initialize quadrature input function */
    tpu_fqd_init(ENCODER1 , FQD_INIT_COUNT, TPU_PRIORITY_HIGH);
    
    position = tpu_fqd_position(ENCODER1);
    
    while (1) {
         new_position = tpu_fqd_position(ENCODER1);
         delta = new_position - position;
         position = new_position;
         
         mode = tpu_fqd_current_mode(ENCODER1);
         
         if ((delta>FQD_MAX_DELTA_COUNT) && (mode==TPU_FQD_NORMAL_MODE))
                  tpu_fqd_mode(ENCODER1 , TPU_FQD_FAST_MODE);

         if ((delta<FQD_MIN_DELTA_COUNT) && (mode==TPU_FQD_FAST_MODE))
                  tpu_fqd_mode(ENCODER1 , TPU_FQD_NORMAL_MODE);
                  
         /* delay to simulate other tasks or calculations */                  
         for(delay=0; delay<10000 ; delay++);
    }
}

/*********************************************************************
 *
 * Copyright:
 *	MOTOROLA, 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 Motorola, Inc. This 
 *  software is provided on an "AS IS" basis and without warranty.
 *
 *  To the maximum extent permitted by applicable law, MOTOROLA 
 *  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 MOTOROLA 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.   
 * 
 *  Motorola assumes no responsibility for the maintenance and support
 *  of this software
 ********************************************************************/

⌨️ 快捷键说明

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