I suggested timer1 overflow with a true interrupt (Darrel Taylor interrupt) your code didn't use any interrupt.I already tried tmr1 interrupt on overflow, as you are suggesting,
You can try to use this simple snippet which uses the timer1 as a counter, without interrupt and works pretty well.
Naturally you need to complete the code replacing the parts with ?????? and Xx with reference to your hardware setup.Code:False con 0 True con 1 Z0 Var Byte Cnts var word Tape_Len Var Word Logic_1 var portXx ' any available free input Motor = False Brake = False TMR1H = 0 TMR1L = 0 Main_Loop: If ????? goto Load_Tape If ????? goto Set_Tape_L goto Main_loop Set_tape_L: Tape_Len = XXXXX ' encoder pulses derived from the tape lenght desired return Start_Motor: Brake = False Motor = True Return Stop_Motor: Motor = false Brake = True Pause 200 Brake = False T1CON.0 = False Return Load_Tape: Cnts = 0 TMR1H = 0 TMR1L = 0 T1CON.0 = true Resume_Halt: Lcdout $FE, 1, " Press Yy to stop " Lcdout $FE, $C0, "--------------------" Lcdout $FE, $94, "Now Loading Tape ..." Lcdout $FE, $D4, "Loaded: ",dec Cnts Gosub Start_Motor For Z0 = 0 To 100 ' 100 millisecs delay pause 1 if Logic_1 = True then Hw_Halt ' check if emergency stop is activated Next Z0 Winding: ' loading start here Cnts.highbyte = TMR1H Cnts.lowbyte = TMR1L If Cnts => Tape_Len then gosub Stop_Motor ' if count = lenght desired stop motor goto Main_Loop End If if Logic_1 = True then Hw_Halt ' If emergency stop key pressed stop motor Lcdout $FE, $D4, "Loaded: ",dec Cnts ' display updated count goto Winding Hw_Halt: gosub Stop_Motor Emergency_menu: 1) if ????? then goto Resume_Halt 2) if ????? then goto Main_Loop goto Hw_Halt End
Cheers
Al.




Bookmarks