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

📄 user_interface.c

📁 用于motor控制的dispic实现
💻 C
📖 第 1 页 / 共 3 页
字号:
					{
						ramp_start_rate=(unsigned int)(COUNTER_RATE/ltemp);
						ramp_start_speed=user_parameters[6];
					}
					ltemp=((unsigned long)user_parameters[7]*(unsigned long)user_parameters[25])/20;
					// This check ensures that ramp_end_rate is calculated with no overflow
					if ((COUNTER_RATE/ltemp) > 65535)	
						ramp_end_rate=65535;
					else
						ramp_end_rate=(unsigned int)(COUNTER_RATE/ltemp);

					ramp_speed_delta=(int)(user_parameters[7]-user_parameters[6]);
					// Also calculate step rate at which zero X detection enabled when using
					// acquistion method 1
					ltemp=((unsigned long)user_parameters[44]*(unsigned long)user_parameters[25])/20;
					if ((COUNTER_RATE/ltemp) > 65535)
						acquire1_enable_rate=65535;
					else
						acquire1_enable_rate=(unsigned int)(COUNTER_RATE/ltemp);
					break;
		case 16:
		case 26:	
		case 27:	// Get value reported for ibus
					// At this stage assuming ibus=0 and have first valid sample
					// and so use this one for offset
					ibus_offset=ibus;
					ltemp=((unsigned long)user_parameters[16])*ADC_GAIN;
					ltemp*=((unsigned long)user_parameters[26]);
					current_trip=(ltemp/(user_parameters[27]*10))+ibus_offset;
					// Now calculate the current limits used when in CLOSED_CURRENT
					// speed control as 95% of the current trip levels
					pos_current_limit=(long)(current_trip-ibus_offset)*95/100;
					pos_current_limit*=16384L;
					neg_current_limit=-1*pos_current_limit;
					// Now recalculate starting parameters if using current control
					// for starting.
					if (user_parameters[40]==FALSE)
					{
						ltemp2=((unsigned long)(current_trip-ibus_offset));
						ltemp=((unsigned long)user_parameters[4])*ltemp2;
						hold1_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[5])*ltemp2;
						hold2_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[8])*ltemp2;
						ramp_start_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[9])*ltemp2;
						ramp_end_demand=(unsigned int)(ltemp/100);
						ramp_demand_delta=(signed int)(ramp_end_demand-ramp_start_demand);
					}
					ltemp2=((unsigned long)(current_trip-ibus_offset));
					ltemp=((unsigned long)user_parameters[41])*ltemp2;
					windmilling_demand=(ltemp/100);	
					break;
		case 15:
		case 22:
		case 28:
		case 29:	ltemp=((unsigned long)user_parameters[15])*ADC_GAIN;
					ltemp*=((unsigned long)user_parameters[28]);
					voltage_trip=ltemp/((unsigned long)user_parameters[29]*10);
					ltemp=((unsigned long)user_parameters[22])*ADC_GAIN;
					ltemp*=((unsigned long)user_parameters[28]);
					voltage_demand=ltemp/((unsigned long)user_parameters[29]*10);
					break;
		case 30: upper_tol=100+user_parameters[30];
					lower_tol=100-user_parameters[30];
					break;

		case 34: // Calculate acquision (method2) threshold values based
					// on user parameter and ADC value read during initialization.
					// This compensates for offset voltages due to ADC and power module.
					vph_red_threshold=vph_red+user_parameters[34];
					vph_yellow_threshold=vph_yellow+user_parameters[34];
					vph_blue_threshold=vph_blue+user_parameters[34];
					break;
		case 40:	if (user_parameters[40])
					{
						hold1_demand=(unsigned int)((unsigned long)user_parameters[4])*FULL_DUTY/100;
						hold2_demand=(unsigned int)((unsigned long)user_parameters[5])*FULL_DUTY/100;
						ramp_start_demand=(unsigned int)((unsigned long)user_parameters[8])*FULL_DUTY/100;
						ramp_end_demand=(unsigned int)((unsigned long)user_parameters[9])*FULL_DUTY/100;
					}
					else
					{
						ltemp2=((unsigned long)(current_trip-ibus_offset));
						ltemp=((unsigned long)user_parameters[4])*ltemp2;
						hold1_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[5])*ltemp2;
						hold2_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[8])*ltemp2;
						ramp_start_demand=(unsigned int)(ltemp/100);
						ltemp=((unsigned long)user_parameters[9])*ltemp2;
						ramp_end_demand=(unsigned int)(ltemp/100);
					}
					ramp_demand_delta=(int)(ramp_end_demand-ramp_start_demand);
					break;
		case 41: ltemp2=((unsigned long)(current_trip-ibus_offset));
					ltemp=((unsigned long)user_parameters[41])*ltemp2;
					windmilling_demand=(unsigned int)(ltemp/100);
					break;
		default:	break;
	}
	return;
}

// This function does a simple switch debounce by not
// updating the global variable valid_switch_states
// unless all 4 push buttons have been in the same
// state for 3 calls of the function
void debounce_switches(void)
{
	static unsigned char oldest_switch_states=0;
	static unsigned char previous_switch_states=0;
	unsigned char switch_states;

	// The four push buttons are on PORTG6-9 but have pull
	// up resistors making a logic 0 equal to a button press
	// So we complement and shift them down to be aligned to 
	//	the bottom which will also effectively mask off all other bits.

	switch_states=(unsigned char)((~PORTG)>>6);
	
	if (switch_states!=previous_switch_states)
	{
		oldest_switch_states=previous_switch_states;
		previous_switch_states=switch_states;
		return;
	}

	if (previous_switch_states != oldest_switch_states)
	{
		oldest_switch_states=previous_switch_states;
		previous_switch_states=switch_states;
	}
	else
	{
		valid_switch_states=switch_states;
		oldest_switch_states=previous_switch_states;
		previous_switch_states=switch_states;
	}
	return;
}

void Write_Screen(unsigned const char *line1,unsigned const char *line2)
{
    while(BusyXLCD());              	// Wait if LCD busy						
	SetDDRamAddr(0x00);						// sets address to origin
    while(BusyXLCD());             		// Wait if LCD busy
	putsXLCD(line1);				
	
	while(BusyXLCD());              	// Wait if LCD busy
	SetDDRamAddr(0x40);					// Move To Second Line
	while(BusyXLCD());              	// Wait if LCD busy
	putsXLCD(line2);					
    return;
}

void Edit_Screen(void)
{
	unsigned char lcd_char[5];

   while(BusyXLCD());              	// Wait if LCD busy
   SetDDRamAddr(0x00);					// Sets address to origin
   while(BusyXLCD());             	// Wait if LCD busy
	putsXLCD(parameter_data[param].line1_msg);
						
   while(BusyXLCD());              	// Wait if LCD busy
	SetDDRamAddr(0x40);					// Move To Second Line
	while(BusyXLCD());             	// Wait if LCD busy
	uint_to_string(new_param_value,&lcd_char[0]);
	putsXLCD(&lcd_char[0]);
	while(BusyXLCD());              	// Wait if LCD busy
	putsXLCD("  ");			
	while(BusyXLCD());              	// Wait if LCD busy
	putsXLCD(parameter_data[param].units_msg);

   return;
}

void Run_Screen(void)
{
	unsigned int temp;
	unsigned char lcd_char[7];
	unsigned long ltemp;
	
	while(BusyXLCD());              	// Wait if LCD busy
   SetDDRamAddr(0x00);					// Sets address to origin
	
	if (interface_flags.RUN_FRAME==0)
	{
		while(BusyXLCD());
		putsXLCD("RUN  DEMAND=");
		while(BusyXLCD());
		temp=((unsigned long)filtered_pot*100)/1023;
		uint_to_string(temp,&lcd_char[0]);
		putsXLCD(&lcd_char[2]);				// Note offset in address as
		while(BusyXLCD());					// demand only ever 100% max
		putsXLCD("%");

		ltemp=((unsigned long)filtered_vdc*10);
		ltemp*=((unsigned long)user_parameters[29]);
		temp=ltemp/((unsigned long)user_parameters[28]*ADC_GAIN);
		while(BusyXLCD());              	// Wait if LCD busy
		SetDDRamAddr(0x40);					// Move To Second Line
		while(BusyXLCD());
		uint_to_string(temp,&lcd_char[0]);
		// Add in decimal point as Vdc scaling gives 100's of mV
		lcd_char[6]='\0';						// Null terminate
		lcd_char[5]=lcd_char[4];			// Shift decimal fraction down
		lcd_char[4]='.';						// Add in decimal point
		putsXLCD(&lcd_char[1]);				// Note offset in address
		while(BusyXLCD());					// As VDC always less than 999V
		putsXLCD("V  ");
		uint_to_string(filtered_rpm,&lcd_char[0]);
		while(BusyXLCD());
		putsXLCD(&lcd_char[0]);
		while(BusyXLCD());
		putsXLCD("RPM");
	}
	else
	{
		while(BusyXLCD());
		putsXLCD("RUN ");
		while(BusyXLCD());
		temp=user_parameters[1];
		putsXLCD(&lcd_mode_msg[temp][0]);
		
		// Calculate phase advance in 1/10s of an electrical degree
		ltemp=((unsigned long)(phase_advance-TIME_CORRECTION)*1800);
		temp=ltemp/period_measurement;
		// Clamp to 30 degrees. phase_advance variable can be > 30
		// but commutation code limits it to 30.
		if (temp>300)	temp=300;
		while(BusyXLCD());              	// Wait if LCD busy
		SetDDRamAddr(0x40);					// Move To Second Line
		while(BusyXLCD());
		uint_to_string(temp,&lcd_char[0]);
		// Add in decimal point as phase advance calculated in
		// 1/10ths of a degree
		lcd_char[6]='\0';						// Null terminate
		lcd_char[5]=lcd_char[4];			// Shift decimal fraction down
		lcd_char[4]='.';						// Add in decimal point
		putsXLCD(&lcd_char[2]);				// Note offset in address
		while(BusyXLCD());					// As advance always less than 30
		putsXLCD("degs");
		uint_to_string(filtered_rpm,&lcd_char[0]);
		while(BusyXLCD());
		putsXLCD(&lcd_char[0]);
		while(BusyXLCD());
		putsXLCD("RPM");
	}
	return;
}
	




void uint_to_string(unsigned int value,unsigned char *display_str)
{

	unsigned char i , zero_flag; 

	display_str[0] = '0';
	while (value >= 10000)
   {
   	display_str[0] ++;
    	value -= 10000;
   }

	display_str[1] = '0';
	while (value >= 1000)
   {
   	display_str[1] ++;
   	value -= 1000;
   }

	display_str[2] = '0';
	while (value >= 100)
   {
   	display_str[2] ++;
   	value -= 100;
   }

	display_str[3] = '0';
	while (value >= 10)
   {
   	display_str[3] ++;
   	value -= 10;
   }

	display_str[4] = '0'+ value;

   /* Now blank off any leading zeros */

	zero_flag = TRUE;
	for (i=0;i<4;i++)
   {
    	if ((zero_flag) && (display_str[i] == '0'))	   
      	display_str[i]  = ' ';        
    	else
        	zero_flag = FALSE;
   }
	display_str[5]='\0';
	return;
}

⌨️ 快捷键说明

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