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

📄 bldcmmain.s

📁 三相无刷电机的PWM控制
💻 S
字号:
	.module bldcmmain.c
	.area text(rom, con, rel)
	.dbfile F:\avrprojs\bldcm\bldcmmain.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 10
; 									 //********************************************************///////////////
; ///**purpose:  use PWM to control BLDCM**********/////
; ///***data: 2008.8.20***********///
; ///***author: XieZu Su********//////
; #include <iom48v.h>
; #include <macros.h>		
; #define speed0 0x20
; 
; void port_init(void)
; {
	.dbline 11
;  PORTB = 0x00;	 //PB1~PB3输出,对应3个下桥臂的通断
	clr R2
	out 0x5,R2
	.dbline 12
;  DDRB  = 0x0E;	
	ldi R24,14
	out 0x4,R24
	.dbline 13
;  PORTC = 0x07; //PC0,PC1,PC2霍尔位置传感器输入,上拉
	ldi R24,7
	out 0x8,R24
	.dbline 14
;  DDRC  = 0x00;
	out 0x7,R2
	.dbline 15
;  PORTD = 0x00;
	out 0xb,R2
	.dbline 16
;  DDRD  = 0x68;	//PD6 PD5 PD3分别对应上桥臂的通断信号PWM
	ldi R24,104
	out 0xa,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 22
; }
; 
; 
; 
; void timer0_init(void)
; {
	.dbline 31
;      //TCCR0B = 0x00; //stop
;     // TCNT0 = 0x01; //set count
; 	 
;     // TCCR0A = 0xA3; 	 //		 快速PWM
;     // TCCR0B = 0x01; //start timer		 选择分频系数			 
; 		// OCR0A = 0x30;
; 	// OCR0B = 0x30;				
; 		
;  TCCR0B = 0x00; //stop
	clr R2
	out 0x25,R2
	.dbline 32
;  TCNT0 = 0x01; //set count
	ldi R24,1
	out 0x26,R24
	.dbline 35
;  //TCCR0A = 0xa3;   //CTC mode 
;  //TCCR0B = 0x01; //start timer		
;  OCR0A = speed0;
	ldi R24,32
	out 0x27,R24
	.dbline 36
;  OCR0B = speed0;
	out 0x28,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer2_init _timer2_init fV
	.even
_timer2_init::
	.dbline -1
	.dbline 40
; }
; 
; void timer2_init(void)
; {
	.dbline 42
; 
;     TCCR2B = 0x00; //stop
	clr R2
	sts 177,R2
	.dbline 43
;     ASSR  = 0x00; //set async mode
	sts 182,R2
	.dbline 44
;     TCNT2 = 0x01; //setup
	ldi R24,1
	sts 178,R24
	.dbline 45
;     OCR2A = speed0;
	ldi R24,32
	sts 179,R24
	.dbline 46
;     OCR2B = speed0;
	sts 180,R24
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Start_PWMAB _Start_PWMAB fV
	.even
_Start_PWMAB::
	.dbline -1
	.dbline 50
; }
; 
; void Start_PWMAB(void)
; {
	.dbline 51
;  	  TCCR0B = 0x00;
	clr R2
	out 0x25,R2
	.dbline 52
; 	  TCCR0A = 0xA3;		//
	ldi R24,163
	out 0x24,R24
	.dbline 53
;       TCCR0B = 0x01; //start Timer
	ldi R24,1
	out 0x25,R24
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Start_PWMA_Close_PWMB _Start_PWMA_Close_PWMB fV
	.even
_Start_PWMA_Close_PWMB::
	.dbline -1
	.dbline 57
; }
; 
; void Start_PWMA_Close_PWMB(void)
; {
	.dbline 58
;  	  TCCR0B = 0x00;
	clr R2
	out 0x25,R2
	.dbline 59
; 	  TCCR0A = 0x83;		//
	ldi R24,131
	out 0x24,R24
	.dbline 60
;       TCCR0B = 0x01; //start Timer
	ldi R24,1
	out 0x25,R24
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Start_PWMB_Close_PWMA _Start_PWMB_Close_PWMA fV
	.even
_Start_PWMB_Close_PWMA::
	.dbline -1
	.dbline 64
; }
; 
; void Start_PWMB_Close_PWMA(void)
; {
	.dbline 65
;  	  TCCR0B = 0x00;
	clr R2
	out 0x25,R2
	.dbline 66
; 	  TCCR0A = 0x23;		//
	ldi R24,35
	out 0x24,R24
	.dbline 67
;       TCCR0B = 0x01; //start Timer
	ldi R24,1
	out 0x25,R24
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Shut_PWMAB _Shut_PWMAB fV
	.even
_Shut_PWMAB::
	.dbline -1
	.dbline 71
; }
; 
; void Shut_PWMAB(void)
; {
	.dbline 72
; 	 TCCR0B = 0x00;
	clr R2
	out 0x25,R2
	.dbline 73
; 	 TCCR0A = 0x02;
	ldi R24,2
	out 0x24,R24
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Start_PWMC _Start_PWMC fV
	.even
_Start_PWMC::
	.dbline -1
	.dbline 77
; }
; 
; void Start_PWMC(void)
; {
	.dbline 78
; 		 TCCR2B = 0x00; //stop
	clr R2
	sts 177,R2
	.dbline 79
; 		 TCCR2A = 0x23; 
	ldi R24,35
	sts 176,R24
	.dbline 80
;      TCCR2B = 0x01; //start
	ldi R24,1
	sts 177,R24
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Shut_PWMC _Shut_PWMC fV
	.even
_Shut_PWMC::
	.dbline -1
	.dbline 84
; }	
; 
; void Shut_PWMC(void)
; {
	.dbline 85
; 		 TCCR2B = 0x00; //stop
	clr R2
	sts 177,R2
	.dbline 86
; 		 TCCR2A = 0x03; 
	ldi R24,3
	sts 176,R24
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_one_five _phase_one_five fV
	.even
_phase_one_five::
	.dbline -1
	.dbline 90
; }
; 
; void phase_one_five(void)
; {
	.dbline 91
;  	 PORTB = PORTB&0xF5;  //关下桥臂4,6
	in R24,0x5
	andi R24,245
	out 0x5,R24
	.dbline 92
; 	 Shut_PWMC();   //关上桥臂 3
	rcall _Shut_PWMC
	.dbline 93
; 	 Start_PWMA_Close_PWMB();  //关上桥臂2,开上桥臂1
	rcall _Start_PWMA_Close_PWMB
	.dbline 94
; 	 PORTB = PORTB|0x04;    //开下桥臂5
	sbi 0x5,2
	.dbline -2
L10:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_one_six _phase_one_six fV
	.even
_phase_one_six::
	.dbline -1
	.dbline 98
; }
; 
; void phase_one_six(void)
; {
	.dbline 99
;  	 PORTB = PORTB&0xF9;  //关下桥臂4,5
	in R24,0x5
	andi R24,249
	out 0x5,R24
	.dbline 100
; 	 Shut_PWMC();   //关上桥臂 3
	rcall _Shut_PWMC
	.dbline 101
; 	 Start_PWMA_Close_PWMB();  //关上桥臂2,开上桥臂1
	rcall _Start_PWMA_Close_PWMB
	.dbline 102
; 	 PORTB = PORTB|0x08;       //开下桥臂6
	sbi 0x5,3
	.dbline -2
L11:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_two_six _phase_two_six fV
	.even
_phase_two_six::
	.dbline -1
	.dbline 106
; }
; 
; void phase_two_six(void)
; {
	.dbline 107
;  	 PORTB = PORTB&0xF9;  //关下桥臂4,5
	in R24,0x5
	andi R24,249
	out 0x5,R24
	.dbline 108
; 	 Shut_PWMC();   //关上桥臂 3
	rcall _Shut_PWMC
	.dbline 109
; 	 Start_PWMB_Close_PWMA();  //关上桥臂1,开上桥臂2
	rcall _Start_PWMB_Close_PWMA
	.dbline 110
; 	 PORTB = PORTB|0x08;      //开下桥臂6
	sbi 0x5,3
	.dbline -2
L12:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_two_four _phase_two_four fV
	.even
_phase_two_four::
	.dbline -1
	.dbline 114
; }
; 
; void phase_two_four(void)
; {
	.dbline 115
;  	 PORTB = PORTB&0xF3;  //关下桥臂4,6
	in R24,0x5
	andi R24,243
	out 0x5,R24
	.dbline 116
; 	 Shut_PWMC();   //关上桥臂 3
	rcall _Shut_PWMC
	.dbline 117
; 	 Start_PWMB_Close_PWMA();  //关上桥臂1,开上桥臂2
	rcall _Start_PWMB_Close_PWMA
	.dbline 118
; 	 PORTB = PORTB|0x02;      //开下桥臂4
	sbi 0x5,1
	.dbline -2
L13:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_three_four _phase_three_four fV
	.even
_phase_three_four::
	.dbline -1
	.dbline 122
; }
; 
; void phase_three_four(void)
; {
	.dbline 123
;  	 PORTB = PORTB&0xF3;  //关下桥臂6,5
	in R24,0x5
	andi R24,243
	out 0x5,R24
	.dbline 124
; 	 Shut_PWMAB();   //关上桥臂 1,2
	rcall _Shut_PWMAB
	.dbline 125
; 	 Start_PWMC();  //开上桥臂PWMC
	rcall _Start_PWMC
	.dbline 126
; 	 PORTB = PORTB|0x02;      //开下桥臂4
	sbi 0x5,1
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e phase_three_five _phase_three_five fV
	.even
_phase_three_five::
	.dbline -1
	.dbline 130
; }
; 
; void phase_three_five(void)
; {
	.dbline 131
;  	 PORTB = PORTB&0xF5;  //关下桥臂6,4
	in R24,0x5
	andi R24,245
	out 0x5,R24
	.dbline 132
; 	 Shut_PWMAB();   //关上桥臂 1,2
	rcall _Shut_PWMAB
	.dbline 133
; 	 Start_PWMC();  //开上桥臂PWMC
	rcall _Start_PWMC
	.dbline 134
; 	 PORTB = PORTB|0x04;      //开下桥臂5
	sbi 0x5,2
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 140
; }
; 
; 
; 
; void uart0_init(void)
; {
	.dbline 141
;  UCSR0B = 0x00; //disable while setting baud rate
	clr R2
	sts 193,R2
	.dbline 142
;  UCSR0A = 0x00;
	sts 192,R2
	.dbline 143
;  UCSR0C = 0x06; //8位数据传送
	ldi R24,6
	sts 194,R24
	.dbline 144
;  UBRR0L = 0x33; //set baud rate lo
	ldi R24,51
	sts 196,R24
	.dbline 145
;  UBRR0H = 0x00; //set baud rate hi
	sts 197,R2
	.dbline 146
;  UCSR0B = 0x18; //
	ldi R24,24
	sts 193,R24
	.dbline -2
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 150
; }
; 
; void init_devices(void)
; {
	.dbline 152
;       //stop errant interrupts until set up
;      CLI(); //disable all interrupts
	cli
	.dbline 153
;      port_init();
	rcall _port_init
	.dbline 154
;      timer0_init();
	rcall _timer0_init
	.dbline 155
;      timer2_init();
	rcall _timer2_init
	.dbline 156
; 	 uart0_init();
	rcall _uart0_init
	.dbline 158
; 
;      MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 159
;      EICRA = 0x00; //extended ext ints
	sts 105,R2
	.dbline 160
;  	 EIMSK = 0x00;
	out 0x1d,R2
	.dbline 162
;  
;  	 TIMSK0 = 0x00; //timer 0 interrupt sources
	sts 110,R2
	.dbline 163
;  	 TIMSK1 = 0x00; //timer 1 interrupt sources
	sts 111,R2
	.dbline 164
;  	 TIMSK2 = 0x00; //timer 2 interrupt sources
	sts 112,R2
	.dbline 166
;  
;  	 PCMSK0 = 0x00; //pin change mask 0 
	sts 107,R2
	.dbline 167
;  	 PCMSK1 = 0x00; //pin change mask 1 
	sts 108,R2
	.dbline 168
;  	 PCMSK2 = 0x00; //pin change mask 2
	sts 109,R2
	.dbline 169
;  	 PCICR = 0x00; //pin change enable 
	sts 104,R2
	.dbline 170
;  	 PRR = 0x00; //power controller
	sts 100,R2
	.dbline 171
;  	 SEI(); //re-enable interrupts
	sei
	.dbline -2
L17:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e USART_Transmit _USART_Transmit fV
;           data -> R16
	.even
_USART_Transmit::
	.dbline -1
	.dbline 177
;  	 //all peripherals are now initialized
; }
; 
; 
; void USART_Transmit(unsigned char data)
; {
L19:
	.dbline 180
L20:
	.dbline 179
;      //等待发送器缓冲为空
;  	 while(!(UCSR0A&(1<<UDRE0)))
	lds R2,192
	sbrs R2,5
	rjmp L19
	.dbline 183
; 	 ;
; 	 
; 	 //发送数据
; 	 UDR0 = data;
	sts 198,R16
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbsym r data 16 c
	.dbend
	.dbfunc e USART_Receive _USART_Receive fc
	.even
_USART_Receive::
	.dbline -1
	.dbline 188
; }
; 
; 
; unsigned char USART_Receive(void)
; {
L23:
	.dbline 191
L24:
	.dbline 190
;     //等待接收数据
;  	while(!(UCSR0A&(1<<RXC0)))
	lds R2,192
	sbrs R2,7
	rjmp L23
	.dbline 192
; 	;
; 	return UDR0;
	lds R16,198
	.dbline -2
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_speed _set_speed fV
;          speed -> R16
	.even
_set_speed::
	.dbline -1
	.dbline 196
; }
; 
; void set_speed(unsigned char speed)
; {
	.dbline 197
;  	 OCR0A = speed;
	out 0x27,R16
	.dbline 198
; 	 OCR0B = speed;
	out 0x28,R16
	.dbline 199
; 	 OCR2B = speed;
	sts 180,R16
	.dbline -2
L26:
	.dbline 0 ; func end
	ret
	.dbsym r speed 16 c
	.dbend
	.dbfunc e main _main fV
;      Speed_Val -> R20,R21
;        Pos_Val -> R22,R23
	.even
_main::
	.dbline -1
	.dbline 203
; }
; 
; void main(void)
; {
	.dbline 205
;      unsigned int Pos_Val,Speed_Val;
; 	  init_devices();
	rcall _init_devices
	rjmp L29
L28:
	.dbline 216
; 	  //Start_PWMA_Close_PWMB();
; 	// Start_PWMC();
; 	// Start_PWMAB();
; 	  
; 	 /* while(1)
; 	  {
; 	   				Speed_Val = USART_Receive();
; 							set_speed(Speed_Val);
; 	  }*/
; 	  while(1)
; 	  {
	.dbline 218
; 
; 			if((UCSR0A&0x80)!=0)
	lds R2,192
	sbrs R2,7
	rjmp L31
	.dbline 219
; 			{
	.dbline 220
; 						 	Speed_Val = UDR0;
	lds R20,198
	clr R21
	.dbline 221
; 						 	OCR0A = Speed_Val;
	out 0x27,R20
	.dbline 222
; 							OCR0B = Speed_Val;
	out 0x28,R20
	.dbline 223
; 							OCR2B = Speed_Val;
	sts 180,R20
	.dbline 224
; 			}
L31:
	.dbline 225
; 			Pos_Val = PINC&0x07;
	in R22,0x6
	clr R23
	andi R22,7
	andi R23,0
	.dbline 254
; /* //   500w轮毂电机			
; 			switch(Pos_Val)
; 			{
; 			    case 3:
; 					 phase_three_five();
; 				break;
; 				case 2:
; 					 phase_one_five();
; 				break;
; 				case 6:
; 					 phase_one_six();
; 				break;
; 				case 4:
; 					 phase_two_six();
; 				break;
; 				case 5:
; 					 phase_two_four();
; 				break;
; 				case 1:
; 					 phase_three_four();
; 				break;		
; 				default:
; 				break;
; 				
; 			}
; */			
; 
; //   2.2kw电机			
; 			switch(Pos_Val)
	cpi R22,1
	ldi R30,0
	cpc R23,R30
	breq L35
	cpi R22,2
	ldi R30,0
	cpc R23,R30
	breq L37
	cpi R22,3
	ldi R30,0
	cpc R23,R30
	breq L36
	cpi R22,4
	ldi R30,0
	cpc R23,R30
	breq L39
	cpi R22,5
	ldi R30,0
	cpc R23,R30
	breq L40
	cpi R22,6
	ldi R30,0
	cpc R23,R30
	breq L38
	rjmp L34
X0:
	.dbline 255
; 			{
L35:
	.dbline 257
; 			    case 1:  
; 					 phase_three_five();   //C+   B-
	rcall _phase_three_five
	.dbline 258
; 				break;
	rjmp L34
L36:
	.dbline 260
; 				case 3:
; 					 phase_one_five();     //A+   B-
	rcall _phase_one_five
	.dbline 261
; 				break;
	rjmp L34
L37:
	.dbline 263
; 				case 2:
; 					 phase_one_six();      //A+   C-
	rcall _phase_one_six
	.dbline 264
; 				break;
	rjmp L34
L38:
	.dbline 266
; 				case 6:
; 					 phase_two_six();      //B+   C-
	rcall _phase_two_six
	.dbline 267
; 				break;
	rjmp L34
L39:
	.dbline 269
; 				case 4:
; 					 phase_two_four();      //B+   A-
	rcall _phase_two_four
	.dbline 270
; 				break;
	rjmp L34
L40:
	.dbline 272
; 				case 5:
; 					 phase_three_four();    //C+   B-
	rcall _phase_three_four
	.dbline 273
; 				break;		
	.dbline 275
; 				default:
; 				break;
L34:
	.dbline 280
L29:
	.dbline 215
	rjmp L28
X1:
	.dbline -2
L27:
	.dbline 0 ; func end
	ret
	.dbsym r Speed_Val 20 i
	.dbsym r Pos_Val 22 i
	.dbend

⌨️ 快捷键说明

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