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

📄 user_interface.c

📁 关于无传感器BLDC使用DSPIC现实的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/**********************************************************************
 *                                                                     *
 *                        Software License Agreement                   *
 *                                                                     *
 *    The software supplied herewith by Microchip Technology           *
 *    Incorporated (the "Company") for its dsPIC controller            *
 *    is intended and supplied to you, the Company's customer,         *
 *    for use solely and exclusively on Microchip dsPIC                *
 *    products. The software is owned by the Company and/or its        *
 *    supplier, and is protected under applicable copyright laws. All  *
 *    rights are reserved. Any use in violation of the foregoing       *
 *    restrictions may subject the user to criminal sanctions under    *
 *    applicable laws, as well as to civil liability for the breach of *
 *    the terms and conditions of this license.                        *
 *                                                                     *
 *    THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION.  NO           *
 *    WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING,    *
 *    BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND    *
 *    FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE     *
 *    COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,  *
 *    INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  *
 *                                                                     *
  **********************************************************************/

 /**********************************************************************
 *                                                                     * 
 *    Author: Smart Power Soutions, LLP                                * 
 *                                                                     *
 *    Filename:       user_interface.c	                                *
 *    Date:           4/21/04                                         *
 *    File Version:   4.00                                             *
 *    Project:        53                                               *
 *    Drawing:        2                                                *
 *                                                                     *
 *    Tools used:    MPLAB C30 Compiler v 1.20.01                      *
 *                                                                     *
 *    Linker File:    p30f4012.gld                                   *
 *                                                                     *
 *                                                                     *
 ***********************************************************************
 *	Code Description
 *  
 *  This file contains all the code for implementing the user interface.
 *  The user interface functions are called from the slow event handler,
 *  which runs every 100 msec.
 *  Different screens are called depending on the operating state of the
 *  software.  The process_switches() function uses the debounced push
 *  buttons and determines the length of time the button has been 
 *  pressed for fast incrementing of the parameter. It also moves the 
 *  system between the various states according to the push buttons.
 *  The save_parameter() function reads an image of the Flash parameters
 *  into a RAM image, modifies the changed parameter, then writes the
 *  block back to Flash.
 *  The process_parameters() function does any scaling or units
 *  conversion that is required for the stored parameters.
 **********************************************************************/


#include "general.h"
#include "hardware.h"
#include "defs.h"
#include "extern_globals.h"


#ifdef DEVELOPMODE
/*********************************************************************/
// ASCII buffers for serial data to be transmitted
// This data is stored in Prog Mem and accessed as data memory 
// using the PSV feature of dsPIC
 struct parameter_data 
	{
    	char *line_msg;     //line 1 parameter screen message 
		char *quick_msg;	//abbriviation for message 
   	};
 struct fault_data
	{
		char *fault_msg;
	};

const struct fault_data fault_data [] =
{
	{"Press S2 to continue ..."},
	{"Failed to Start"},
	{"Over Current"},
	{"Over Voltage"},
	{"Hardware Trip"},
	{"Over Speed"},
	{"Sensorless Lost"},
	{"Motor Stalled"}
};

const unsigned char help_info[5][14]=
{
	{0,25,32,41,50,50,50,50,50,50,50,50,50,50},
	{26,27,28,29,33,34,35,36,37,38,39,42,50,50},
	{2,3,4,5,6,7,8,9,10,30,31,40,43,44},
	{1,11,12,17,18,19,20,21,22,23,24,50,50,50},
	{13,14,15,16,50,50,50,50,50,50,50,50,50,50},
};

 const struct parameter_data parameter_data [] =	
{
// Line msg, Quick msg 
{"DIRECTION       ","DD"},//0
{"CONTROL MODE    ","CM"},//1
{"Lock Pos.1 Time ","LP1T"},//2
{"Lock Pos.2  Time","LP2T"},//3
{"Lock Pos.1 Dem. ","LP1D"},//4
{"Lock Pos.2 Dem. ","LP2D"},//5
{"Ramp Start Speed","RSS"},//6
{"Ramp End Speed  ","RES"},//7
{"Ramp Start Dem. ","RSD"},//8
{"Ramp End Dem.   ","RED"},//9
{"Ramp Duration   ","RD"},//10
{"Phase Adv. Enable Spd ","PAES"},//11
{"Phase Adv. Slope","PAS"},//12
{"Stall Time Limit","STL"},//13
{"Over Speed Limit","OSL"},//14
{"Over Volts Limit","OVL"},//15
{"Over Current Lim","OCL"},//16
{"Current P Gain  ","CKP"},//17
{"Current I Gain  ","CKI"},//18
{"Current D Gain  ","CKD"},//19
{"Speed P Gain    ","SKP"},//20
{"Speed I Gain    ","SKI"},//21
{"Voltage Demand  ","VD"},//22
{"Volts P Gain    ","VKP"},//23
{"Volts I Gain    ","VKI"},//24
{"No. Motor Poles ","MP"},//25
{"Current Scale X ","CSX"},//26
{"Current Scale / ","CSD"},//27
{"Volts Scale X   ","VSX"},//28
{"Volts Scale /   ","VSD"},//29
{"Tolerance Check ","TC"},//30
{"Auto Re-acquire ","ARA"},//31
{"Blanking Count  ","BC"},//32
{"Zero X Level Thd","ZXL"},//33
{"Acquire Threshld","AT"},//34
{"Acquire Level Td","AL"},//35
{"Rotation Timeout","RT"},//36
{"Pot / for Duty  ","PDD"},//37
{"Pot / for Currnt","PDC"},//38
{"Pot X for Speed ","PXS"},//39
{"Starting Control","SC"},//40
{"Windmilling Dem.","WD"},//41
{"Braking Ramp T  ","BRT"},//42
{"Acquire Method  ","AM"},//43
{"ZeroX Enable Spd","ZXES"},//44
};

const unsigned char ParaHeader[] = 
			{"\r\nParameter Description\tParameter Abbreviation\tParameter Value\r\n"};

 const struct parameter_data HelpMsg_data [] =	
{	
	{"For Motor Parameters\t","Use '?M'"},
	{"For Starting Parameters\t", "Use '?S'"},
	{"For Control Parameters\t", "Use '?C'"},
	{"For Limit Parameters\t", "Use '?L'"},
	{"For Board Parameters\t", "Use '?B'"},
};

const unsigned char ErrorMsg[] = {"\r\nIncorrect Command! Use '??' For command set.\r\n"};
const unsigned char MotorParaHeader[] = {"Motor Parameters:\r\n"};
const unsigned char LimitParaHeader[] = {"Limit Parameters:\r\n"};
const unsigned char StartingParaHeader[] = {"Starting Parameters:\r\n"};
const unsigned char BoardParaHeader[] = {"Board Parameters:\r\n"};
const unsigned char ControlParaHeader[] = {"Control Parameters:\r\n"};
const unsigned char RunMessage[] = {"\r\n\r\n Speed = 2200 r.p.m.  DutyCycle = 72% Peak Current = 0245 mA \r\n"};
const unsigned char FaultMessage[] = {"\r\n\r\n Fault = Failed to Start \r\n"};

const unsigned char RunMsg1[] = {"Speed in rpm = "};
const unsigned char RunMsg2[] = {" % DutyCycle = "}; 
#endif

// User parameters are stored in program Flash as EEPROM is not currently functional.
// New values are to be stored using special routines written in assembler for erase
// and write. Read will be done via PSV thus allowing C code to access the values directly.
// The values must therefore be stored on a Flash memory row boundary as can only 
// erase 1 row (16 program locations) at a time. This is the purpose of the aligned attribute.
// Furthermore, can not use the normal const C declaration as otherwise have problems when 
// using compiler optimization. Therefore use the section attribute to instruct the linker
// to place the "variable" into the const section whilst compiler still treats it as a 
// variable which can change outside of it's control owing to volatile declaration
// The initialized values are the default values used when programming
// Note that even if all values in a block of 32 are not used, the array size must be declared
// in integar multiples of 32 as the erase can only be done on a single flash row of 32.
// If this is not done it is possible that linker may put other constants or even program code
// just after the array which are inadvertantly erased along with the parameters!
#ifndef DEVELOPMODE
volatile unsigned int user_parameters[64] __attribute__((aligned(64),far,section(".const,r")))=
#endif
#ifdef DEVELOPMODE
unsigned int user_parameters[45] = 
#endif
{	
	//BACKWARDS,
	FORWARDS,
	CLOSED_VOLTS,	// Speed Control Mode - See defs.h 
	50,				// First Lock Position Time in units of medium event (10ms) 
	50,				// Second Lock Position Time in units of medium event (10ms) 
	50,				// % Demand Used For Lock Position 1
	50,				// % Demand Used For Lock Position 2			
	100,			// Starting Speed for Ramp / RPM 
	2000,			// Finish Speed for Ramp / RPM	
	52,				// % Demand Used At Start of Ramp
	68,				// % Demand Used At End of Ramp	
	100,				// Duration of starting ramp in units of medium event (10ms)
	1500,			// Phase Advance Start Speed in RPM (1500 default) 
	25,				// Phase Advance Slope in 1/1000th elec. degree / RPM	
	100,			// Stall Time Limit in units of medium event (10ms) 
	3500,			// Over Speed Trip in RPM (3500 default)	
	500,			//	Over Voltage Trip in 1/10ths V
	100,			// Over Current Limit in 1/10ths A 
	900,			// Current Loop P Gain 
	100,			// Current Loop I Gain 
	0,				// Current Loop D Gain 
	2500,			// Speed Loop P Gain 
	40,				// Speed Loop I Gain 
	490,			// Voltage Demand for Brake Chopper in 1/10ths V 
	10000,			// Voltage Loop P Gain 
	5000,			// Voltage Loop I Gain 
	8,				// Number of Motor Poles 
	100,			// Current Scaling X - see below
	539,			// Current Scaling / - see below
	//239,
	100,			// Voltage Scaling X - see below
	//10,
	1305,			// Voltage Scaling / - see below
	//910,
	90,				// % Tolerance used for Lost Check - see below
	1,				// Auto-reaquire if lost ON/OFF
	1,				// Blanking Length used for zero X in no of ADC samples
	2,				// No. of samples required > or < VDC/2 before zero X checked for
	12,  			// ADC value used for rising edge detect for acquisition routine
	6,				// No of samples of VPH before rising edge detect done in acquisition
	5,				// Rotation Timeout in units of medium event (10ms)
	1,				// Divisor used to scale pot ADC reading to Duty Cycle
	8,				// Divisor used to scale pot ADC reading to I Dem in ADC
	3,				// X Used to Scale pot ADC reading to wdemand in rpm
	1,				// 1=Use Voltage Control for Starting, 0=Use Current Control
	20,				// % Demand Used For Windmilling Braking
	1,				// Duration of braking ramp in units of medium event (10ms)
	0,				// Use Method 1 (=0) or Method 2 (=1) for acquisition of position
	400};			// Speed at Which ZeroX detection enabled when using method1 acqusition

// Current and Voltage Scaling X and / Parameters
// These are used to scale ADC readings into Amps or Volts as follows: 
// If you get 12.87 A/V for ibus or 12.87 V/V for vdc then
// X = 100 and / = 1287 is one possible combination

// For LV Power Module Use The Following values: 
// VX=100 V/=1305 i.e scaling is 13.05 V/V		 
// If LK11&12 Open 	IX=100 I/=539 i.e scaling is 5.39A/V 
// If LK11&12 Closed	IX=10  I/=119 i.e.scaling is 11.9A/V 

// For HV Power Module Use The Following values: 
// VX=10  V/910 i.e. scaling is 91.0 V/V 
// If LK11&12 Open	IX=100 I/=108 i.e scaling is 1.08A/V 
// if LK11&12 Closed IX=100 I/=239 i.e scaling is 2.39A/V 

// Tolerance for Lost Check Parameter 
// Every 60 electrical degrees a new zero crossing event should
// be detected. In order to determine if the system is lost, 
// a check is carried out comparing the time elapsed since the 
// last zero crossing and the one before that. 
// If the tolerance parameter is set to 25% then up to 25%
// variation between the two times is considered to be acceptable.
// If the system fails the check, then the system is lost.
// Some natural variation in the times is to be expected even at
// a constant speed due to timer and ADC resolution as well as 
// motor asymmetry. Speed changes will also result in variation.
// It is suggested that the parameter is not set to less than 25%
// as otherwise the system may be determined to lost just due to
// normal variations.
/*********************************************************************/

#ifdef DEVELOPMODE
void GetMsgIndex(void);
void SendCRLF(void);
void SendErrorMsg(void);
void CheckHelp(void);
void SendHelpMsg(void);
void SendMsg(void);
void SendValue(unsigned int k);
void SaveValue(void);
void InitUart(void);
void SendHelpInfo(unsigned char Tab);
void SendMotorPara(void);
void SendLimitPara(void);
void SendControlPara(void);
void SendBoardPara(void);
void SendStartingPara(void);
void SendHeader(void);
void SendTab(void);
void SendRunMsg(void);
void SendFaultMsg(void);
void send_run(void);
void send_fault(void);
void serial_handler(void);
#endif

void process_switches(void);
void save_parameter(void);
void process_parameters(void);
void debounce_switches(void);
void uint_to_string(unsigned int, unsigned char *);

extern void erase_flash_row(unsigned int);
extern void program_flash(unsigned int, unsigned int);

struct interface_flags {
				unsigned EDIT_PARAM : 1;
				unsigned EDIT_MENU :	1;
				unsigned PARAM_CHANGING	: 1;
				unsigned S4_RISING :1;
				unsigned S5_RISING :1;
				unsigned S6_RISING :1;
				unsigned S7_RISING :1;
				unsigned RUN_FRAME :1;
				unsigned UNUSED : 8;
};

struct interface_flags interface_flags;




void process_switches(void)

⌨️ 快捷键说明

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