0606-015 From: Juan Carlos Manuel
Polanco Aguilar jucamapa@gmail.com
July 03, 2006
Proyecto con 8085Necesito una ayuda con un proyecto de control de
velocidad de un motor DC usando PWM (Pulse Width Modulation) o Modulacion de
Ancho de pulso. Por favor si tuvieran el codigo ensamblador explicado de
este proyecto o si es que me pudieran ayudar a entenderlo pues no lo tengo
muy claro SE LOS AGRADECERIA INFINITAMENTE. Gracias. Saludos
; ---------------------------------------------------------------
; This program regulates the speed of a DC motor by...
; [1] Averaging 16 samples of back EMF during motor off time.
; [2] Generating an error term (DIP switch - average EMF).
; [3] Using the error term to adjust the pulse width.
; [4] Using the resulting pulse width to pulse width modulate
; (PWM) the motor.
;
; WARNING: Use a 9V supply with a current limit of 1000 mA or
; more with this lab. The standard 500mA supply will
; be damaged if it is used with this lab.
;
MOS: EQU 1000H ; MOS SERVICES ADDRESS.
PWM_PORT: EQU 11H ; DIGITAL OUTPUT PORT.
DIP_SW: EQU 12H ; DIP SWITCH PORT.
SERV09: EQU 09H ; MOS SERVICE.ADCIN => L.
SERV13: EQU 13H ; MOS SERVICE.DE => 7-SEG DISPLAY.
PW_MIN: EQU 03H ; MINIMUM PW. T=160uS X PW_MIN
PW_MAX: EQU 32H ; MAXIMUM PW. T=160uS X PW_MAX
MAX_SLICE: EQU 3FH ; MAXIMUM NUMBER OF TIME SLICES.
; SETS PWM PERIOD.
; T=160uS X MAX_SLICE.
SMARK: EQU 34H ; TIME SLICE WHERE BACK EMF
; SAMPLE WILL BE TAKEN.
VEC7HLF: EQU 0FFE9H ; 7.5 INTERRUPT VECTOR.
SCALELO: EQU 35H ; MODE/SCALER FOR TIMER,
SCALEHI: EQU 11000000B ; CONTINUOUS PULSES EVERY 160uS.
TIMERLO: EQU 14H ; TIMER PORT.
TIMERHI: EQU 15H ; TIMER PORT.
TIMCMD: EQU 0CDH ; TIMER CONTROL COMMAND.
CMDREG: EQU 10H ; TIMER CONTROL PORT.
INTMASK: EQU 1AH ; INTERRUPT MASK.
ORG 0FF01H
DI
LXI H,SLICER ; POINT 7.5 INTERRUPT
SHLD VEC7HLF ; VECTOR TO SLICER.
MVI A,SCALELO ; SET UP TIMER FOR
OUT TIMERLO ; CONTINUOUS PULSES
MVI A,SCALEHI ; AT DESIRED INTERRUPT
OUT TIMERHI ; RATE.
MVI A,TIMCMD
OUT CMDREG
MVI A,INTMASK
SIM
EI
PWM_MOTOR:
LXI H,0000H ; REG H = TOTAL
MVI B,10H ; REG B = SAMPLE COUNT.
CHKZERO:
LDA T_SLICE ; TIME SLICE = 0 ?
CPI 00H
JNZ CHKZERO ; NO.GO CHECK SMARK.
MVI D,00H ; DISPLAY SPEED.
MOV E,C ; C = SPEED.
PUSH B
MVI C,SERV13
CALL MOS
POP B
LDA PULSE_WIDTH
MOV D,A ; DISPLAY PW.
MVI E,0FFH ; E = MASK.
ORA E ; CLEAR CARRY.
ROT_MASK:
RAL ; ROTATE 0 TO MASK.
MOV E,A ; SAVE MASK.
MOV A,D ; GET PW.
SUI 08H ; PW = PW - 8.
MOV D,A ; SAVE RESULT TO D.
MOV A,E ; GET MASK.
JNC ROT_MASK ; PW STILL POS. ?
DI ; DISABLE INTERRUPT.
LDA IMAGE ; GET IMAGE.
RAR ; SAVE BIT 0.
MOV A,E ; GET MASK.
RAL ; 7 BITS MASK + BIT 0.
STA IMAGE ; TO IMAGE.
EI ; ENABLE INTERRUPT.
CHK_SMARK:
LDA T_SLICE
CPI SMARK ; TIME SLICE = SMARK ?
JNZ CHK_SMARK ; NO.WAIT TILL IT IS.
XCHG ; DE = TOTAL.
PUSH B ; SAMPLE BACK EMF.
MVI C,SERV09
CALL MOS
POP B
MVI H,00H ; HL = SAMPLE.
DAD D ; HL = TOTAL + SAMPLE.
DCR B ; DEC. SAMPLE COUNT.
JNZ CHKZERO ; IF NOT 0, CHK 0 T_SLICE.
DIV_MORE: DAD H ; HL*16/256=HL/16, SO...
DAD H ; ...4 DAD H's MAKES HL*16...
DAD H ; ..AFTER THIS H=HL/256 (THINK ABOUT IT)
DAD H ; SPEED=TOTAL / MAX SAMP (16).
MOV C,H ; STORE SPEED.
IN DIP_SW ; GET DESIRED SPEED.
ANI 00111111B ; DES.SPEED 6 BITS MAX.
SUB H ; SWITCH-SPEED=ERROR.
LXI H,PULSE_WIDTH
JM DECPW_CHK ; ERROR = -. DEC PW ?
CPI 2 ; ERROR < 2 ?
JC PW_RANGE ; YES. NO PW CHANGE.
INR M ; NO. INC PW.
JMP PW_RANGE ; RANGE CHECK PW.
DECPW_CHK:
CPI 0FFH ; ERROR = -1.
JZ PW_RANGE ; YES. RANGE CHECK PW.
DCR M ; NO. DEC PW.
PW_RANGE:
MVI A,PW_MIN ; PW < MIN ?
CMP M
JC MAX_CHK ; NO. CHECK MAX.
MOV M,A ; YES. PW = MIN.
MAX_CHK:
MVI A,PW_MAX ; PW > MAX ?
CMP M
JNC PWM_MOTOR ; NO. PW OK.
MOV M,A ; YES. PW = MAX.
JMP PWM_MOTOR ; START AGAIN.
; ---------------------------------------------------------------
; .......................SLICER..................................
; SLICER IS AN INTERRUPT HANDLER FOR THE 7.5 INTERRUPT.
; SLICER CONTROLS A TIME MARKER (T_SLICE) BY ADJUSTING IT FROM
; 0 TO MAX_SLICE IN EQUAL TIME INCREMENTS ON EACH 7.5 INTERRRUPT.
; SLICER ALSO CONTROLS THE WIDTH OF THE PULSE USED TO DRIVE THE
; MOTOR BY COMPARING THE VALUE OF PULSE_WIDTH TO THAT OF T_SLICE
; TO DETERMINE IF THE PULSE SHOULD BE HIGH OR LOW.
; PULSE HIGH => T_SLICE < PULSE_WIDTH.
; PULSE LOW => T_SLICE >=PULSE_WIDTH.
; ---------------------------------------------------------------
SLICER:
PUSH PSW ; SAVE REGISTERS.
PUSH H
LXI H,T_SLICE ; H POINTS TO T_SLICE.
INR M ; INCREMENT T_SLICE
MVI A,MAX_SLICE
CMP M ; T_SLICE = MAX_SLICE ?
JNZ PWM ; NO. T_SLICE OK.
MVI M,00H ; YES. T_SLICE = 0.
PWM:
MOV A,M ; A = T_SLICE.
LXI H,PULSE_WIDTH ; M = PULSE WIDTH.
CMP M ; T_SLICE < PULSE WIDTH ?
LXI H,IMAGE ; M = IMAGE.
MOV A,M ; GET IMAGE.
RAR ; CY => BIT 7.
RLC ; BIT 7 => BIT 0.
MOV M,A ; STORE IMAGE.
OUT PWM_PORT ; OUTPUT IMAGE.
POP H ; RECOVER REGISTERS.
POP PSW
EI
RET ; RETURN
T_SLICE: DB 00H
PULSE_WIDTH: DB PW_MIN
IMAGE: DS 01H
END
; ----------------------------------------------------------
VOLVER
|