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

📄 hallpattern.ini

📁 xc800_bldc.zip,资源多多共享!不亦乐乎!
💻 INI
字号:
func unsigned char sensorless (float step, unsigned char hallstate){
unsigned char direction;
//direction 0 is forward
switch( MCMOUTL )
	{
	case 0x21:		AIN5=0;
					AIN6=5;
					if(hallstate==2){
						direction=0;
						AIN4-=5.0/step;					
					}
					else {
						direction=1;
						AIN4+=5.0/step;					
					}
					break;
	case 0x06:		AIN5=5;
					AIN4=0;

					if(hallstate==1){
						direction=0;
						AIN6-=5.0/step;
					}
					else {
						direction=1;
						AIN6+=5.0/step;
					}
					break;
	case 0x24:		AIN4=0;
					AIN6=5;
					if(hallstate==3){
						direction=0;
						AIN5+=5.0/step;
					}
					else {
						direction=1;
						AIN5-=5.0/step;
					}
					break;
	case 0x18:		AIN4=5;
					AIN6=0;
					if(hallstate==4){
						direction=0;
						AIN5-=5.0/step;
					}
					else {
						direction=1;
						AIN5+=5.0/step;
					}
					break;
	case 0x09:		AIN5=0;
					AIN4=5;
					if(hallstate==6){
						direction=0;
						AIN6+=5.0/step;
					}
					else {
						direction=1;
						AIN6-=5.0/step;
					}
					break;
	case 0x12:		AIN5=5;
					AIN6=0;
					if(hallstate==5){
						direction=0;
						AIN4+=5.0/step;
					}
					else {
						direction=1;
						AIN4-=5.0/step;
					}
					break;
	}
	return direction;
}

signal void hall (void) {
unsigned int temp;
float v;
unsigned samplestep;
unsigned int x;
unsigned char direction,hallstate;
samplestep=10;


	AIN4=0;
	AIN5=0;
	AIN6=0;
	P2_DATA=5;
	PORT2=5;
	PORT3|=0x40;
	swatch(0.15);

	while (1) {
		hallstate=PORT2&7;
		for(x=0;x<samplestep;x++){
			swatch (0.001);
			direction = sensorless(samplestep,hallstate);
		}
		switch(PORT2&7) {
			case 1: 	if(direction==0)PORT2=5;
						else PORT2=3;
						break;
			case 2: 	if(direction==0)PORT2=3;
						else PORT2=6;
						break;
			case 3: 	if(direction==0)PORT2=1;
						else PORT2=2;
						break;
			case 4: 	if(direction==0)PORT2=6;
						else PORT2=5;
						break;
			case 5: 	if(direction==0)PORT2=4;
						else PORT2=1;
						break;
			case 6: 	if(direction==0)PORT2=2;
						else PORT2=4;
						break;
		}

	}
}

signal void trap (void) {
PORT3&=~0x40;
swatch(0.01);
PORT3|=0x40;
}


define button "start hall","hall();g"
define button "trap", "trap()"

PORT2=5

⌨️ 快捷键说明

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