;----------------------------------------------------------------------------- ; Copyright (C) 2004 by Takao. ; All rights reserved. ; ; FILE NAME : BL_ESC_03.ASM ; DATE : 22 AUG '04 ; TARGET MCU : C8051F330 ; DESCRIPTION : Simple MOS FET driver program for BL motor start run as a stepping motor ; ; NOTES : Improve the start stepping sequence by sweep frame timing control at starting ; $include (c8051f330.inc) ; Include register definition file. ;----------------------------------------------------------------------------- ; EQUATES ;----------------------------------------------------------------------------- TEST_PIN equ P1.7 ; Scope Trigger pin OUT_U equ P1.4 ; Motor 'U' lead drive port OUT_V equ P1.5 ; Motor 'V' lead drive port OUT_W equ P1.6 ; Motor 'W' lead drive port IO_MODE_M equ TMR2L ; Using Timer2 registers instead of RAM(F300 does not have user RAM) IO_SETTING equ TMR2H ; Using Timer2 registers instead of RAM(F300 does not have user RAM) ;TEMP1 equ R1 ;TEMP2 equ R2 ;TEMP3 equ R3 ;TEMP4 equ R4 TEMP5 equ R5 ;TEMP6 equ R6 ;TEMP7 equ R7 S_ON_DUTY equ 30 ; "on duty" at Stepping starting S_OFF_DUTY equ 170 ; "off duty" at Stepping starting S_S_FRAME equ 90 ;slow stepping start frame timing data S_R_FRAME equ 30 ;slow stepping running frame timing data ; STACK SEGMENT IDATA ; declare STACK segment RSEG STACK DS 80h ; reserve 128 bytes for stack ;----------------------------------------------------------------------------- ; RESET and INTERRUPT VECTORS ;----------------------------------------------------------------------------- ;Reset Vector cseg AT 0 ljmp Main ; Locate a jump to the start of ; code at the reset vector. ;----------------------------------------------------------------------------- ; CODE SEGMENT ;----------------------------------------------------------------------------- BL_ESC segment CODE rseg BL_ESC ; Switch to this code segment. using 0 ; Specify register bank for the ; following program code. Main: ; Disable the WDT. anl PCA0MD, #NOT(040h); clear Watchdog Enable bit orl OSCICN, #00000011b ; make 24.5MHz run orl P0MDIN, #10000000b ; make the out put pin's input mode digital or analog orl P1MDIN, #01110000b ; make the out put pin's input mode digital or analog orl P0MDOUT, #00000000b ; make the out put pin's mode. "0"= Open Drain, "1"= Push-Pull. orl P1MDOUT, #00000000b ; make the out put pin's mode. "0"= Open Drain, "1"= Push-Pull. orl P0SKIP, #00111111b ; skipped by the cross bar orl P1SKIP, #01110111b ; skipped by the cross bar ; Enable the Port I/O Crossbar ; orl XBR0, #00000000b ; mov XBR1, #01100000b ; no weak pull-ups, cross bar enabled on out put pins. ; All out puts are "L", just after RESET. SET_START_FRAME: mov a, #S_S_FRAME ; slow starting frame timing data to avoid Ansync. stepping. STEPPING_START: acall STATE1 acall STEP_DRIVE_CNT acall STATE2 acall STEP_DRIVE_CNT acall STATE3 acall STEP_DRIVE_CNT acall STATE4 acall STEP_DRIVE_CNT acall STATE5 acall STEP_DRIVE_CNT acall STATE6 acall STEP_DRIVE_CNT dec a cjne a, #S_R_FRAME-1, STEPPING_START ; Sweep starting *********** ;inc a mov a, #S_R_FRAME jmp STEPPING_START ;spin forever ; Stepping start with duty control as current limitter. STEP_DRIVE_CNT: mov TEMP5, a STEP_FRAME_CNT: acall START_PWR_CNTROL djnz TEMP5, STEP_FRAME_CNT ret START_PWR_CNTROL: ON_TIM: mov TH1, #S_ON_DUTY sLoop10: nop nop nop nop djnz TH1, sLoop10 ALL_3ST: mov IO_MODE_M, P1MDOUT ; GPIO mode setting data storage mov IO_SETTING, P1 ; IO data storage mov P1MDOUT, #0 ; make the outputs are open drain as 3-Sate open to reduce the SW noise mov P1, #10000000b ; All "0" for stepping start with magnetic brake ************************ OFF_TIM: mov TH1, #S_OFF_DUTY tLoop10: nop nop nop nop nop nop nop djnz TH1, tLoop10 RE_ON: mov P1, IO_SETTING ; IO data storage mov P1MDOUT, IO_MODE_M ; GPIO mode setting data storage ret ;----------------------------- ;Motor drive each states STATE1: mov P1MDOUT, #00110001b ; make the out UV pin output push-pull, W pin is 3ST mov P1, #11010001b ; U=1, V=0, W=3ST + TEST PIN=1 mov P1, #11010000b ; U=1, V=0, W=3ST + TEST PIN=0 ret STATE2: mov P1MDOUT, #00010000b ; make the out U pin output push-pull, V,W pin 3ST mov P1, #10110000b ; U=1, V=3ST, W=0 mov P1MDOUT, #01010000b ; make the out UW pin output push-pull, V pin is 3ST ret STATE3: mov P1MDOUT, #01100000b ; make the out W pin output push-pull, U,V pin is 3ST mov P1, #10110000b ; U=3ST, V=1, W=0 ret STATE4: mov P1MDOUT, #00100000b ; make the out V pin output push-pull, U,W pin 3ST mov P1, #11100000b ; U=0, V=1, W=3ST mov P1MDOUT, #00110000b ; make the out UV pin output push-pull, W pin is 3ST ret STATE5: mov P1MDOUT, #01010000b ; make the out UW pin output push-pull, V pin is 3ST mov P1, #11100000b ; U=0, V=3ST, W=1 ret STATE6: mov P1MDOUT, #01000000b ; make the out W pin output push-pull, U,V pin is 3ST mov P1, #11010000b ; U=3ST, V=0, W=1 mov P1MDOUT, #01100000b ; make the out VW pin output push-pull, U pin is 3ST ret ; End of file. END