tpu_tsm.c
来自「mpc564 时钟中断 时钟中断」· C语言 代码 · 共 370 行 · 第 1/2 页
C
370 行
/**************************************************************************/
/* FILE NAME: tpu_tsm.c COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.0 All Rights Reserved */
/* */
/* DESCRIPTION: This file shows how to use the standard set-up and header */
/* files for the MPC565. This program sets up the MPC565 TPU_A */
/* initializations for the Table Stepper Function. Then a new desired */
/* position is entered and the CPU is interrupted by a write of 0x11 to */
/* the HSR bits of the HSRR register. */
/* This program uses the fixed structure feature of the header files. */
/*========================================================================*/
/* COMPILER: Diab Data VERSION: 4.3g */
/* AUTHOR: Glenn Jackson */
/* */
/* HISTORY */
/* REV AUTHOR DATE DESCRIPTION OF CHANGE */
/* --- ----------- --------- --------------------- */
/* 1.0 G. Jackson 30/Jul/02 Initial version of function. */
/**************************************************************************/
#include "tpu_tsm.h"
#include "mpc500_util.h"
/*************************************************************/
/* Begin TPU Initialization */
/*************************************************************/
/*******************************************************************************
FUNCTION : tpu_tsm_init
PURPOSE : To initialize channels to run the TSM function.
INPUTS NOTES : This function has 13 parameters:
*tpu - This is a pointer to the TPU3 module to use. It is of
type TPU3_tag which is defined in m_tpu3.h
channel - This is the channel number of the primary TSM
channel. The next channels are used as the
parameter table.
priority - This is the priority to assign to TSM channels.
This parameter should be assigned a value of:
TPU_PRIORITY_HIGH, TPU_PRIORITY_MIDDLE or
TPU_PRIORITY_LOW.
start_position - This is the starting desired_position and current_position.
table_size - Initializes the number of bytes in the
acceleration table.
table_index - Initializes the table pointer to zero (start).
slew_period - initializes the slew_period and S.
start_period - initializes the start_period and A.
pin_sequence - initializes the pin_sequence.
number_channels - number of channels used for this TSM.
Two to four channels total, including the master
channel and the parameter table channels.
*table - pointer to the table beginning location.
table_size - initialize the number of bytes in the table.
RETURNS NOTES : none
WARNING : The channels must be stopped before it is reconfigured. The
function disables the channels but if they were currently
being serviced it would continue. The delay for assigning the
pram pointer may to enough but depends on system loading.
*******************************************************************************/
void tpu_tsm_init(struct TPU3_tag *tpu, UINT8 channel, UINT8 priority,
INT16 start_position, UINT16 table_size_index,
UINT16 slew_period, UINT16 start_period,
UINT16 pin_sequence, UINT8 number_channels,
UINT16 *table, UINT8 table_size)
{
/* Declare variables for channel designations */
int master_channel;
int param1_channel;
int param2_channel;
int param3_channel;
UINT8 pchannel;
UINT8 param;
UINT8 i;
/* Establish channels used for TSM function */
/* set channel values to other channels based upon the master */
/* if primary channel is 15 then secondary channel should be 0 */
master_channel = channel;
param1_channel = (channel + 1) & 0xF;
param2_channel = (channel + 2) & 0xF;
param3_channel = (channel + 3) & 0xF;
/* disable channels so they can be configured safely */
tpu_disable( tpu, master_channel);
tpu_disable( tpu, param1_channel);
if (number_channels > 2) { tpu_disable( tpu, param2_channel); }
if (number_channels > 3) { tpu_disable( tpu, param3_channel); }
/* select TSM function for number of active channels */
/* TSM is function 0xD */
tpu_func( tpu, master_channel, TPU_FUNCTION_TSM);
tpu_func( tpu, param1_channel, TPU_FUNCTION_TSM);
if (number_channels > 2) { tpu_func( tpu, param2_channel, TPU_FUNCTION_TSM); }
if (number_channels > 3) { tpu_func( tpu, param3_channel, TPU_FUNCTION_TSM); }
/* disable interupts on channels so they can be configured safely */
tpu_interrupt_disable( tpu, master_channel);
tpu_interrupt_disable( tpu, param1_channel);
if (number_channels > 2) { tpu_interrupt_disable( tpu, param2_channel); }
if (number_channels > 3) { tpu_interrupt_disable( tpu, param3_channel); }
/* Initialize Parameter RAM */
pchannel = param1_channel;
param = 0;
for (i=0; i<table_size; i++){
tpu->PARM.R[pchannel][param++] = *table++;
if (param == 8){
param = 0;
pchannel++;
if (pchannel == 16) pchannel = 0;
}
}
/* -initial DESIRED_POSITION and CURRENT_POSITION will be the same; */
/* -initialize TPU_TSM_TABLE, slew period, start period, pin_sequence */
tpu->PARM.R[master_channel][TPU_TSM_DESIRED_POSITION] = (INT16) (start_position);
tpu->PARM.R[master_channel][TPU_TSM_CURRENT_POSITION] = (INT16) (start_position);
tpu->PARM.R[master_channel][TPU_TSM_TABLE] = (INT16) (table_size_index);
tpu->PARM.R[master_channel][TPU_TSM_SLEW_PERIOD] = (INT16) (slew_period);
tpu->PARM.R[master_channel][TPU_TSM_START_PERIOD] = (INT16) (start_period);
tpu->PARM.R[master_channel][TPU_TSM_PIN_SEQUENCE] = (INT16) (pin_sequence);
/**************************************************/
/* Configure the Channels. */
/**************************************************/
/* Configure the first channel as the primary channel and the following */
/* channel as the secondary channel. */
tpu_hsq(tpu, master_channel, TPU_TSM_LOCAL_ACC_TBL | TPU_TSM_ROTATE_ONCE);
tpu_hsq(tpu, param1_channel, TPU_TSM_LOCAL_ACC_TBL | TPU_TSM_ROTATE_ONCE);
if(number_channels > 2) {
tpu_hsq(tpu, param2_channel, TPU_TSM_LOCAL_ACC_TBL | TPU_TSM_ROTATE_ONCE);
}
if(number_channels > 3) {
tpu_hsq(tpu, param3_channel, TPU_TSM_LOCAL_ACC_TBL | TPU_TSM_ROTATE_ONCE);
}
/* Initialize both channels */
tpu_hsr(tpu, master_channel, TPU_TSM_INIT_HI);
tpu_hsr(tpu, param1_channel, TPU_TSM_INIT_LO);
if(number_channels > 2) {
tpu_hsr(tpu, param2_channel, TPU_TSM_INIT_LO);
}
if(number_channels > 3) {
tpu_hsr(tpu, param3_channel, TPU_TSM_INIT_LO);
}
/* Enable channels by assigning a priority to them. */
/* All Channels MUST have the same priority. */
tpu_enable(tpu, master_channel, priority);
tpu_enable(tpu, param1_channel, priority);
tpu_enable(tpu, param2_channel, priority);
tpu_enable(tpu, param3_channel, priority);
} /* End tpu_tsm_init */
/****************************************************/
/* End of TPU Initialization */
/****************************************************/
/**************************************************/
/* Generate other tasks for the TSM function. */
/**************************************************/
/*******************************************************************************
FUNCTION : tpu_tsm_mov
PURPOSE : To activate the move and acceleration of the stepper motor.
INPUTS NOTES : This function has 3 parameters:
*tpu - This is a pointer to the TPU3 module to use. It is of
type TPU3_tag which is defined in m_tpu3.h
channel - This is the number of the master channel
position - The new desired position for the stepper motor.
GENERAL NOTES : The channel must be a master channel for the TSM function. There
can be more than one master channel in the same TPU. The
additional master channel(s) would be for another TSM function.
*******************************************************************************/
void tpu_tsm_mov(struct TPU3_tag *tpu, UINT8 channel, UINT16 position)
{
/* write a new desired position into the TSM master channel */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?