This is my code for length measurements for fatigue testing machine with PEAK-HOLD.
I use 1000 PPR encoder with CH A and CH B for up/down, code working well when machine working in compression.
but problem is when machine work in tension side, encoder count 65535 below 00
i want this sequence
<<---------- 00 --------->>
Tension Compression
6-5-4-3-2-1-0-1-2-3-4-5-6
chip 16f88
Code:DEFINE OSC 20 INCLUDE "MODEDEFS.BAS" INCLUDE "MYLCD.BAS" ANSEL = 0 'SELECT ANALOG INPUTS 0 = NONE AND ALL DIGITAL ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT CMCON = 7 'COMPARATORS OFF TRISA = %00000 TRISB = %00000011 ' INT0 = ENCODER CH. A ' PORTB.1 = ENCODER CH. B W0 VAR WORD B1 var word W0 = 0 B1 = 0 PAUSE 500 '------------------------------------------------------------------------- INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _ToggleLED1, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM OPTION_REG.6 = 0 ; 1 = Interrupt on rising edge of INT pin ; 0 = Interrupt on falling edge of INT pin @ INT_ENABLE INT_INT ; enable external (INT) interrupts '------------------------------------------------------------------------- LOOP: if W0 > B1 then B1 = W0 ' (Peak-Hold), Hold the last value of W0 in B1 LCDOUT $FE,1 LCDOUT "Length = ", dec5 w0, " mm" lcdout $FE, $C0 lcdout "Peak- Value ",dec5 B1, " mm" pause 500 GOTO LOOP ToggleLED1: if PORTB.1 = 0 then W0 = W0+1 else w0 = w0-1 IF (W0 < 0) THEN W0 = 65535 + 1 endif ENDIF @ INT_RETURN




Bookmarks