Quote Originally Posted by ThaSanta View Post
I'm writing a routine to a tachometer. I just doesn't work! I've searched the forum, but i haven't found anything that looks like this.


Code:
'****************************************************************
'*  Name    : Tacho.BAS                                         *
'*  Author  : Christian Lerche                                  *
'*  Notice  : Copyright (c) 2008 Lerche                         *
'*          : All Rights Reserved                               *
'*  Date    : 07-10-2008                                        *
'*  Version : 1.0                                               *
'*  Notes   : PIC16F84A @ 10 Mhz XT                             *
'*          : XT osc, BODEN off, WD off                         *
'****************************************************************
'Include------------------------------------------------------------------------

'Definitions--------------------------------------------------------------------                                     
Define osc 10                          ' Define Osc as 10 Mhz
DEFINE PULSIN_MAX 25000                ' Lowest RPM 600

'Inputs/outputs-----------------------------------------------------------------
TRISB = $80                            ' All PortB Output
TRISA = $f0                            ' All PortA Output
INPUT PORTA.4                          ' PortA.4 Input

'Variables----------------------------------------------------------------------
B0 VAR BYTE                            ' Define B0 as byte
W1 var WORD                            ' Define W1 as word
     
'Main program-------------------------------------------------------------------                                       
loop:      
        IF PORTA.4 THEN                ' Wait until start of low pulse
                GOTO MAIN1
            ELSE
                GOTO loop
        ENDIF 
MAIN1:
        PULSIN PORTA.4,0,W1            ' Measure pulse-width in 4µS resolution
        GOTO MAIN
MAIN:
        W1 = W1 * 4                    ' Convert µS to mS
        W1 = (60000 / W1)              ' Revs in 60 mS
        W1 = W1 * 1000                 ' Revs in 60 sec
            GOSUB display              ' Go to display sobroutine       
        GoTo LOOP                      ' Do forever
        
'Display subroutine------------------------------------------------------------- 
display: B0 = W1 / 1000	               ' Find number of thousands
	W1 = W1 // 1000	                   ' Remove thousands from W1
	   Gosub bin2seg	               ' Convert number to segments
	PortB = B0	                       ' Send segments to LED
	PortA = $17	                       ' Turn on fourth digit
	Pause 1    		                   ' Leave it on 1 ms
	PortA = $1F	                       ' Turn off digit to prevent ghosting 
	B0 = W1 / 100	                   ' Find number of hundreds
	W1 = W1 // 100	                   ' Remove hundreds from W1
	   Gosub bin2seg	               ' Convert number to segments
	PortB = B0	                       ' Send segments to LED
	PortA = $1B	                       ' Turn on third digit
	Pause 1    	                       ' Leave it on 1 ms
	PortA = $1F	                       ' Turn off digit to prevent ghosting 
	B0 = W1 / 10	                   ' Find number of tens
	W1 = W1 // 10	                   ' Remove tens from W1
	   Gosub bin2seg	               ' Convert number to segments
	PortB = B0	                       ' Send segments to LED
	PortA = $1D	                       ' Turn on second digit
	Pause 1    	                       ' Leave it on 1 ms
	PortA = $1F	                       ' Turn off digit to prevent ghosting 
	B0 = W1		                       ' Get number of ones
	   Gosub bin2seg	               ' Convert number to segments
	PortB = B0	                       ' Send segments to LED
	PortA = $1E	                       ' Turn on first digit
	Pause 1    	                       ' Leave it on 1 ms
	PortA = $1F	                       ' Turn off digit to prevent ghosting
    Return		                       ' Return to main
                                       ' Routine copied from ledart.

'Lookup table-------------------------------------------------------------------
bin2seg:
    Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18],B0
	Return
Anyone got a clue, what is does wrong?

Thanks in advance!

/ ThaSanta

Please check this line:

loop:
IF PORTA.4 THEN ' Wait until start of low pulse


Should it be:

IF PORTA.4 = 0 THEN ' Wait until start of low pulse

Andy