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

📄 step.c

📁 网上下载的一个rtx例子
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
     char a[2];
     int b;
    }cntld;

	if (chip == 1 || chip == 2) {  /* Be sure chip selection is valid            */

		/* Check if the frequeny is in range */
		frequency = (float)fabs(frequency);
		if (frequency > VELMAX) return(-2);
		if (frequency < VELMIN) return(-2);

		/* Compute the time constant to get frequency, based on clock frequency   */
		cntld.b = (int) (1.25e6/frequency + .5);

		/* Pause counter while loading new time constant, in case of retrigger    */
		tmp = pause_ctr(chip,2);

		/* Load new velocity time constant - no effect until counter triggered    */
		Int32_Write_Register(chip,CNT_2_TIME_CNST_MSB,cntld.a[1]);
		Int32_Write_Register(chip,CNT_2_TIME_CNST_LSB,cntld.a[0]);

		tmp = continue_ctr(chip,2);
		return(0);
	} else return(-1);                        

}

/*****************************************************************************/
/*   ENABLE_CTRS                                                             */
/*      Allow counter activity.                                              */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/

int enable_ctrs(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_Register(chip,MASTER_CONF_CNTR);
		// remove dblock 2/16/99 for compat. with servos
//		tmp = tmp | PORT_C_CNT_3_EN_BIT | CNT_1_EN_BIT | CNT_2_EN_BIT;
		tmp = tmp | CNT_1_EN_BIT | CNT_2_EN_BIT;
		Int32_Write_Register(chip,MASTER_CONF_CNTR,tmp);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   DISABLE_CTRS                                                            */
/*      Inhibit counter activity.                                            */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/

int disable_ctrs(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_Register(chip,MASTER_CONF_CNTR);
		// remove dblock 2/16/99
//		tmp = tmp & ~(PORT_C_CNT_3_EN_BIT | CNT_1_EN_BIT | CNT_2_EN_BIT);
		tmp = tmp & ~(CNT_1_EN_BIT | CNT_2_EN_BIT);
		Int32_Write_Register(chip,MASTER_CONF_CNTR,tmp);
		return(0);
	}

	return(-1);
}

/*****************************************************************************/
/*   CONTINUE_CTR                                                            */
/*      Continue counting (set the gate bit).                                */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*      counter - the counter to continue                                    */
/*                                                                           */
/*****************************************************************************/

int continue_ctr(int chip, int counter) {

	int tmp;         

	if ((chip == 1 || chip == 2) && (counter == 1 || counter == 2)) {
		tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1); 
		Int32_Write_Register(chip,CNT_1_COM_STA+counter-1,tmp | GATE_CNT);
		return(0);
	} else return(-1);
}


/*****************************************************************************/
/*   PAUSE_CTR                                                               */
/*      Pause counting (clear the gate bit).                                 */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*      counter - the counter to pause                                       */
/*                                                                           */
/*****************************************************************************/

int pause_ctr(int chip, int counter) {

	int tmp;         

	if ((chip == 1 || chip == 2) && (counter == 1 || counter == 2)) {
		tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1); 
		Int32_Write_Register(chip,CNT_1_COM_STA+counter-1,tmp & ~GATE_CNT);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   TRIGGER_CTR                                                             */
/*      Trigger counting (load time constant and start counting).            */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*      counter - the counter to trigger                                     */
/*                                                                           */
/*****************************************************************************/

int trigger_ctr(int chip, int counter) {

	int tmp;         

	if ((chip == 1 || chip == 2) && (counter == 1 || counter == 2)) {
		tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1); 
		Int32_Write_Register(chip,CNT_1_COM_STA+counter-1,tmp | TRIG_CNT);

		/* Since we rely on CIP flag to indicate whether things are running, we   */
		/* need to wait here for it to be set--not instantaneous.  It appears to  */
		/* happen synchronously with an input pulse, but this is not documented.  */
		tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1) & CNT_IN_PROG; 
		while (!tmp) tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1) & CNT_IN_PROG;
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   COUNT_IN_PROG                                                           */
/*      Indicates whether a count is running on the specified counter.       */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*      counter - the counter to poll                                        */
/*                                                                           */
/*****************************************************************************/
int count_in_prog(int chip, int counter) {

	if ((chip == 1 || chip == 2) && (counter == 1 || counter == 2))
		return(Int32_Read_Register(chip,CNT_1_COM_STA+counter-1) & CNT_IN_PROG);
	else
		return(-1);
}

/*****************************************************************************/
/*   CLEAR_IP                                                                */
/*      Clear the interrupt flag for a counter. (Set when counter finishes.) */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*      counter - the counter to clear                                       */
/*                                                                           */
/*****************************************************************************/
int clear_IP(int chip, int counter) {

	int tmp;         

	if ((chip == 1 || chip == 2) && (counter == 1 || counter == 2)) {
		tmp = Int32_Read_Register(chip,CNT_1_COM_STA+counter-1);
		Int32_Write_Register(chip,CNT_1_COM_STA+counter-1, (tmp && COM_STA_MASK) | CLEAR_IP);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   SET_RUN                                                                 */
/*      Set driver to "RUN."                                                 */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/

int set_RUN(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp | RUN);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   SET_HOLD                                                                */
/*      Set driver to "HOLD" (i.e. clear the RUN line).                      */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/

int set_HOLD(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp & ~RUN);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   SET_CW                                                                  */
/*      set clockwise direction.                                             */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/

int set_CW(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp | CW);
		return(0);
	} else return(-1); 
}

/*****************************************************************************/
/*   SET_CCW                                                                 */
/*      set counter-clockwise direction.                                     */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/
int set_CCW(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp & ~CW);
		return(0);
	} else return(-1); 
}

/*****************************************************************************/
/*   SET_HALF                                                                */
/*      Set driver for half step motion.                                     */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/
int set_HALF(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp | HALF);
		return(0);
	} else return(-1);
}

/*****************************************************************************/
/*   SET_FULL                                                                */
/*      Set driver for full step motion.                                     */
/*                                                                           */
/*   parameters                                                              */
/*      chip - the timer chip on the board to use                            */
/*                                                                           */
/*****************************************************************************/
int set_FULL(int chip) {
	int tmp;

	if (chip == 1 || chip == 2) {
		tmp = Int32_Read_PortA(chip);
		Int32_Write_PortA(chip,tmp & ~HALF);
		return(0);
	} else return(-1);
}


 

⌨️ 快捷键说明

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