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

📄 mc_interface.c

📁 无刷电机驱动原理
💻 C
字号:
/**
* @file mc_lib.c
*
* Copyright (c) 2005 Atmel.
*
* @brief This module provides High level function for the motor control
*
* @version 1.0 (CVS revision : $Revision: 1.3 $)
* @date $Date: 2006/07/12 12:58:27 $
* @author $Author: raubree $
*****************************************************************************/
#include "config.h"
#include "config_motor.h"

#include "mc_interface.h"
#include "mc_control.h"
#include "mc_drv.h"

void mc_ramp_up_init(void);

Bool mci_direction = CW;      //!<User Input parameter to set motor direction
Bool mci_run_stop  = STOP;    //!<User Input parameter to launch or stop the motor
U8 mci_cmd_speed   = 0;       //!<User Input parameter to set motor speed

U8 mci_measured_speed      = 0; //!<Motor Input parameter to get the motor speed
U32 mci_measured_current   = 0; //!<Motor Input parameter to get the motor current
U8 mci_potentiometer_value = 0; //!<Motor Input to set the motor speed


/**
* @brief get the motor state
* @param
* @pre initialization  HW and SW
* @post We know if the motor is running or not
*/
Bool mci_motor_is_running(void)
{
  return mci_run_stop;
}


/**
* @brief use to init programm
* @param
* @post configuration of hardware and sotware
* @pre none
*/
void mc_motor_init()
{
  mc_init_HW();
  mc_init_SW();

  mci_stop();
  mci_store_measured_speed(0);
}

/*
* @brief speed modification
* @pre initialization of motor
* @post new value of speed
*/
void mci_set_motor_speed(U8 speed)
{
  mci_cmd_speed = speed;
}

/*
* @brief speed visualization
* @pre initialization of motor
* @post get speed value
*/
U8 mci_get_motor_speed(void)
{
  return mci_cmd_speed;
}

/*
* @brief direction modification
* @pre initialization of motor
* @post new value of direction
*/
void mci_set_motor_direction(U8 direction)
{
//  if ((mci_direction == CW) || (mci_direction == CCW)) mci_direction = direction;
   mci_direction = direction;
}

/*
* @brief set the direction in CW
* @pre initialization of motor
* @post new value of direction
*/
void mci_forward(void)
{
  mci_direction = CW;
}

/*
* @brief set the direction in CCW
* @pre initialization of motor
* @post new value of direction
*/
void mci_backward(void)
{
  mci_direction = CCW;
}

/*
* @brief direction visualization
* @pre initialization of motor
* @post get direction value
*/
/* U8 mci_get_motor_direction(void)
{
  return mci_direction;
} */

/**
 * @brief set Measured of speed (for initialization)
 * @pre none
 * @post mc_measured_speed initialized
*/
void mci_store_measured_speed(U8 measured_speed)
{
  mci_measured_speed = measured_speed;
}

/**
 * @brief Measured of speed
 * @return return value of speed (8 bits)
 * @pre none
 * @post none
*/
U8 mci_get_measured_speed(void)
{
  return mci_measured_speed;
}

/**
* @brief Get the current measured in the motor
* @pre Launch ADC scheduler
* @post Get ADC Channel 12 result (Current value on 8bits).
*/
U16 mci_get_measured_current(void)
{
/*  U16 value_to_return;
  value_to_return = mci_measured_current>>6;
  if (value_to_return > 994)
  {
    value_to_return = value_to_return - 994;
  }
  else
  {
    value_to_return = 994 - value_to_return;
  }
  return value_to_return;*/
  return mci_measured_current;
}

/**
* @brief Set the variable 'mc_measured_current' for initialization.
* @pre none
* @post 'mc_measured_current' set with the current value
*/
void mci_store_measured_current(U16 current)
{
  mci_measured_current = ((63*mci_measured_current)+(64*current))>>6;
}

/**
* @brief Get the potentiometer value
* @pre Launch ADC scheduler
* @post Get ADC Channel 6 result (Potentiometer value on 8bits).
*/
U8 mci_get_potentiometer_value(void)
{
  return mci_potentiometer_value;
}

/**
* @brief Set the 'mc_potentiometer_value' variable with the potentiometer value
* @pre Launch ADC scheduler
* @post 'mc_potentiometer_value' set with the potentiometer value
*/
void mci_store_potentiometer_value(U8 potentiometer)
{
  mci_potentiometer_value = potentiometer;
}

/**
* @brief mci_run starts the motor with predefined parameter
* @param
* @pre initialization  HW and SW
* @post New value in Hall variable
*/
void mci_run(void)
{
   mc_motor_init();  // launch initialization of the motor
   mci_run_stop = RUN;
   mci_set_motor_speed(DUTY_RAMP_UP); /* set a speed for the ramp-up */
   mc_set_Open_Loop();      /* set the regulation type */
   mc_regulation_loop();    /* execute the regulation one time */
   mc_ramp_up_init();
   PSC_Run();
}

void mci_stop(void)
{
   PSC_Stop();
   mci_run_stop  = STOP;
}


void mci_set_speed(U16 speed)
{
   mci_set_motor_speed((U8)speed);
}

⌨️ 快捷键说明

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