CSE466 Assignment 2 Solution
In my version, I went ahead and added the code to check for the case that the fan is moving too slow. There are at least three ways that this code can fail in real operation. Identify at least two of these failure modes and make any changes or additions necessary to catch them. Note: I am not looking for bugs in my code, If I made an obvious programming error, please fix it, but it won't count against the two items!
The some possible problems with the original solution:
maxH equ 2BH; maximum period at 30Hz is 11K
maxL equ 67H;
RSEG STACK ; relocatable segment
CSEG AT 2BH ; location for EX2 interrupt
PUSH ACC;
PUSH PSW;
PUSH R3;
JMP MYT2;
RSEG PROG
MYT2:
MOV
C,TF2 ; move the
overflow flag to the carry bit
JNC NOOVR ; No
overflow found, so no problem
MOV periodH #FF ; ensures that main routine will detect
fan speed error
MOV periodL #FF ;
MOV TL2, #00; reset
everything
MOV TH2,#00;
MOV thenL, #00;
MOV thenH, #00;
JMP exit
NOOVR:
CLR C;
MOV A,RCAP2L ; get low byte
MOV R3,A ;
save for later
SUBB thenL ; subtract
"then" low byte
MOV thenL,R3 ; save now as then
MOV periodL,A ; store difference in low
byte
MOV A,RCAP2H; get high byte
MOV R3,A ; save for later
SUBB A, thenH ; subtract high byte
MOV thenH,R3 ; save now as then
MOV periodH,A ; store high byte difference
MOV T2CON, #0D; clear the interrupt flags
EXIT:
POP R3;
POP PSW;
POP ACC;
RTI
RSEG PROG ; relocatable segment