Restarting project and getting closer :) Need a little help with an Interrupt
A little while ago, I was working on a digital tach for my car, but had a big problem with the displays flickering. The flickering is fixed, but now the RPM is completely wrong [noparse]:([/noparse] I think it has to do with the interrupt messing with the PULSIN commands. A few members gave me advice to use the COUNT command, but i could never get it precise. I was also given a few other alternatives for the PULSIN command, but i could not get them to work correctly.
Here is what i have so far :
I am only using 3 LED displays because that is all the would fit on my test board so I just want to read the first 3 digits. When I hook it up to my car and let it idle, the display jumps from 2000+ rpm to 500 rpm even though it is idling at 800 rpm. I was trying to find if there was a way to call an interrupt from inside the code only when needed and figured that may fix my problem, but I have not been able to find anything like that. I am wanting to only use the internal clock because I want to keep the circuitry as simple as possible.
Any help is greatly appreciated [noparse]:)[/noparse]
Here is what i have so far :
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "M-SEG" RPM_signal PIN RC.0 INPUT TRIS_disp VAR TRIS_B rpm VAR WORD pWidth0 VAR WORD pWidth1 VAR WORD dividendMSW VAR WORD dividendLSW VAR WORD overflow VAR BIT doneBit VAR BIT display VAR RB digit VAR WORD digit1 VAR WORD currentrpm VAR WORD INTERRUPT 120 digit = currentrpm LOW RA.1 digit1 = digit / 100 ' Get First digit digit = __REMAINDER READ SegMap + digit, display pause 5 HIGH RA.1 LOW RA.2 digit1 = digit1 / 10 ' Get second digit digit = __REMAINDER READ SegMap + digit, display pause 5 HIGH RA.2 LOW RA.3 digit1 = digit1 / 10 ' Get Third digit digit = __REMAINDER READ SegMap + digit, display pause 5 HIGH RA.3 RETURNINT PROGRAM Start Start: TRIS_disp = %00000000 Main: PULSIN RPM_signal, 0, pWidth0 PULSIN RPM_signal, 1, pWidth1 pWidth0 = pWidth0 + pWidth1 pWidth0 = pWidth0 * 2 dividendMSW = $005B dividendLSW = $8D80 rpm = 1 overflow = 0 DO doneBit = rpm.15 rpm = rpm << 1 IF overflow = 1 THEN rpm.0 = 1 dividendMSW = dividendMSW - pWidth0 ELSE IF dividendMSW >= pWidth0 THEN rpm.0 = 1 dividendMSW = dividendMSW - pWidth0 ENDIF ENDIF overflow = dividendMSW.15 dividendMSW = dividendMSW << 1 dividendMSW.0 = dividendLSW.15 dividendLSW = dividendLSW << 1 LOOP UNTIL doneBit = 1 rpm = rpm << 1 rpm.0 = overflow IF dividendMSW >= pWidth0 THEN rpm.0 = 1 ENDIF ' Set variable currentrpm to prevent the interrupt from getting var rpm while in the middle of calculations currentrpm = rpm + 150 GOTO Main SegMap: ' segments maps DATA %00111111 ' 0 DATA %00000110 ' 1 DATA %01011011 ' 2 DATA %01001111 ' 3 DATA %01100110 ' 4 DATA %01101101 ' 5 DATA %01111101 ' 6 DATA %00000111 ' 7 DATA %01111111 ' 8 DATA %01100111 ' 9
I am only using 3 LED displays because that is all the would fit on my test board so I just want to read the first 3 digits. When I hook it up to my car and let it idle, the display jumps from 2000+ rpm to 500 rpm even though it is idling at 800 rpm. I was trying to find if there was a way to call an interrupt from inside the code only when needed and figured that may fix my problem, but I have not been able to find anything like that. I am wanting to only use the internal clock because I want to keep the circuitry as simple as possible.
Any help is greatly appreciated [noparse]:)[/noparse]
Comments