- This topic has 0 replies, 1 voice, and was last updated 12 years ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
|
Microcontroller › PIC › bldc motor
#define DrivePort PORTC
#define SensorMask B’00000111’
#define SensorPort PORTE
#define DirectionBit PORTA, 1
Commutate
movlw SensorMask ;retain only the sensor bits
andwf SensorPort ;get sensor data
xorwf LastSensor, w ;test if motion sensed
btfsc STATUS, Z ;zero if no change
return ;no change – return
xorwf LastSensor, f ;replace last sensor data with current
btfss DirectionBit ;test direction bit
goto FwdCom ;bit is zero – do forward commutation
;reverse commutation
movlw HIGH RevTable ;get MS byte to table
movwf PCLATH ;prepare for computed GOTO
movlw LOW RevTable ;get LS byte of table
goto Com2
FwdCom ;forward commutation
movlw HIGH FwdTable ;get MS byte of table
movwf PCLATH ;prepare for computed GOTO
movlw LOW FwdTable ;get LS byte of table
Com2
addwf LastSensor, w ;add sensor offset
btfsc STATUS, C ;page change in table?
incf PCLATH, f ;yes – adjust MS byte
call GetDrive ;get drive word from table
movwf DriveWord ;save as current drive word
return
GetDrive
movwf PCL
FwdTable
retlw B’00000000’ ;invalid
retlw B’00010010’ ;phase 6
retlw B’00001001’ ;phase 4
retlw B’00011000’ ;phase 5
retlw B’00100100’ ;phase 2
retlw B’00000110’ ;phase 1
retlw B’00100001’ ;phase 3
retlw B’00000000’ ;invalid
RevTable
retlw B’00000000’ ;invalid
retlw B’00100001’ ;phase /6
retlw B’00000110’ ;phase /4
retlw B’00100100’ ;phase /5
retlw B’00011000’ ;phase /2
retlw B’00001001’ ;phase /1
retlw B’00010010’ ;phase /3
retlw B’00000000’ ;invalid