PIC16F84A Tachometer LED routine


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Question

    Hi Christian,

    I'd like to be sure of one thing : what do you use as a rotation detector ???

    ... as in your calculations, the pulsin signal is supposed to be equal to the rotation period, something hurts me ... but what ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Oct 2008
    Location
    Denmark
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi Christian,

    I'd like to be sure of one thing : what do you use as a rotation detector ???

    ... as in your calculations, the pulsin signal is supposed to be equal to the rotation period, something hurts me ... but what ???

    Alain
    As it is, I am only using a simulator. I do not have a programmer.

    Actually, it's supposed to measure the RPM of a computer-fan. 50% duty-cycle. :-)
    / Lerche

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    ThaSanta, Here is a snipit of code I wrote about 4 years ago to do exactly what you are requesting..

    ASM
    PutMulResult macro Const32
    MOVE?CB low Const32, R2
    MOVE?CB low (Const32 >> 8), R2 + 1
    MOVE?CB low (Const32 >> 16), R0
    MOVE?CB low (Const32 >> 24), R0 + 1
    endm
    ENDASM

    PULSIN B_IN,1,POINTER1 'MEASURE HIGH PULSE
    IF POINTER1 > 0 THEN
    @ PutMulResult 15000000 ' Load PBP internal vars Max= 2,147,483,648
    POINTER2 = DIV32 POINTER1 ' Divide 15000000/(PERIOD/2)
    SCRATCH = R2 ' Get remainder of Div32
    ' Change remainder to Decimals
    SCRATCH = SCRATCH * 10000 ' Multiply remainder * 10,000
    SCRATCH = DIV32 POINTER1 ' Divide remainder by original divisor
    ELSE
    POINTER2 = 0
    SCRATCH = 0
    ENDIF
    LCDOUT $FE,LINE(1)
    PAUSEUS 100
    LCDOUT DEC5 POINTER2,".",DEC4 SCRATCH

    I hope it works for you... It did for me...

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Oct 2008
    Location
    Denmark
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Hey again guys. Long time, no code.

    Finally, I got the idea.

    - This rountine uses an external freq-to-voltage chip, and reads it using ADCIN, multiplies it, and show the result a lot of times per second.

    Here goes.

    Code:
    '****************************************************************
    '*  Name    : RPM.BAS                                           *
    '*  Author  : Christian Lerche                                  *
    '*  Notice  : Copyright (c) 2009 DSB El-teknik                  *
    '*          : All Rights Reserved                               *
    '*  Date    : 28-05-2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC16F913, Boden Off, WDT off, PWR off            *
    '*          :                                                   *
    '****************************************************************
    '
    ' Includes
    '
    
    '
    ' Defines-----------------------------------------------------------------------
    '
        Define  osc 10                          ' Define oscillator XT 10 MHz
        DEFINE  ADC_BITS 10                     ' Define A/D Converter 10 bit
        DEFINE  ADC_CLOCK 3                     ' Define ADC clock source 
        DEFINE  ADC_SAMPLEUS 50                 ' Wait 50 µS before convert to digi
    '
    ' INPUT / OUTPUT----------------------------------------------------------------
    '
        TRISA = 0                               ' PORTA is output
        TRISA.5 = 1                             ' PORTA.5 is input
        TRISB = 1                               ' PORTB is input
        TRISC = 0                               ' PORTC is Output
        TRISB.0 = 1                             ' B0 / Int is count input
        ADCON0 = %10010001                      ' ADC On, right justified
        ADCON1 = 0                              ' ADC Freq = 625KHz
        ASM                                     ; Insert ASM
        BANKSEL LCDCON                          ; LCD Configuration
        CLRF    LCDCON                          ; Turn off LCD Driver
        ENDASM                                  ; End of ASM
    '
    ' Variables and constants-------------------------------------------------------
    '
        W1  VAR WORD                            ' W1 is 16 bit variable
        W2  var word                            ' W2 is 16 bit variable 
        W3  var word                            ' W3 is 16 bit variable
        B0  var byte                            ' B0 is 8 bit variable 
    '
    ' Main program------------------------------------------------------------------
    '
    Main:
        ADCIN 4, W2                             ' Read Freq-to-voltage device
        W3 = W2 * 977                           ' Freaky constant makes it work.
        W1 = DIV32 100                          ' Put the result in W1
        GOSUB display4                          ' Show RPM
        GOTO Main                                ' Do forever
        END                                     ' For the compilers sake       
    '
    ' Subroutines-------------------------------------------------------------------
    ' 
    display4:
        B0 = W1 / 1000	                        ' Find number of thousands
    	W1 = W1 // 1000	                        ' Remove thousands from W1
        Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
        PORTC = B0      	                    ' Send segments to LED
    	PORTA = $01     	                    ' Turn on fourth digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00	                            ' Turn off digit to prevent ghosting 
    	B0 = W1 / 100	                        ' Find number of hundreds
    	W1 = W1 // 100	                        ' Remove hundreds from W1
    	Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0	                            ' Send segments to LED
    	PORTA = $02	                            ' Turn on third digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00     	                    ' Turn off digit to prevent ghosting 
    	B0 = W1 / 10	                        ' Find number of tens
    	W1 = W1 // 10	                        ' Remove tens from W1
    	Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0      	                    ' Send segments to LED
    	PORTA = $04  	                        ' Turn on second digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00	                            ' Turn off digit to prevent ghosting 
    	B0 = W1		                            ' Get number of ones
        Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0	                            ' Send segments to LED
    	PORTA = $08     	                    ' Turn on first digit
    	Pause 1		                            ' Leave it on 1 ms
        PORTA = $00	                            ' Turn off digit to prevent ghosting     
        RETURN                                  ' Return to caller!
    I'm sorry that there is some comments that shouldn't be in the code. But I've made a lot of changes through time!!
    Last edited by ThaSanta; - 19th June 2009 at 02:02. Reason: Adding info
    / Lerche

  5. #5
    Join Date
    Oct 2008
    Location
    Denmark
    Posts
    10


    Did you find this post helpful? Yes | No

    Post Tachometer finally done

    Hey All.

    I've finally finished my tachometer, with full 4 7 segments displays. It updates very fast, with the calculation, and showing the new RPM's.
    - Later I will post the full code, and probably the hardware to convert. It's really cheap, and the only thing you have to change in it, it the potentiometer value, so that 166,6 * the number of cilenders your car have. That's the frequency of the top 5volts. For some of the guys, that doesn't have a squarewave signal generator, to adjust it with, you can grab the schematic of LM2907, and start calculating the resistor the fits the purpose.

    My routine is simply the routine from the melabs, site. 4*7 Segments, multiplexed, and a calculator, plus ADC converter, the it updates, more than you'll ever get to see.
    It's not finished, cuz i need to remove the first zeroes, before the RPM, cuz it is confusing.

    Anyways, schematic and code will be applied this week.


    May the code be with you all!
    Last edited by ThaSanta; - 5th July 2009 at 01:32. Reason: Spelling errors
    / Lerche

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Great! I'm looking forward to see them!

  7. #7
    Join Date
    Oct 2008
    Location
    Denmark
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Source for the project

    Code:
    '****************************************************************
    '*  Name    : RPM.BAS                                           *
    '*  Author  : Christian Lerche                                  *
    '*  Notice  : Copyright (c) 2009 DSB El-teknik                  *
    '*          : All Rights Reserved                               *
    '*  Date    : 28-05-2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC16F913, Boden Off, WDT off, PWR off            *
    '*          :                                                   *
    '****************************************************************
    '
    ' Includes
    '
    
    '
    ' Defines-----------------------------------------------------------------------
    '
        Define  osc 10                          ' Define oscillator XT 10 MHz
        DEFINE  ADC_BITS 10                     ' Define A/D Converter 10 bit
        DEFINE  ADC_CLOCK 3                     ' Define ADC clock source 
        DEFINE  ADC_SAMPLEUS 50                 ' Wait 50 µS before convert to digi
    '
    ' INPUT / OUTPUT----------------------------------------------------------------
    '
        TRISA = 0                               ' PORTA is output
        TRISA.5 = 1                             ' PORTA.5 is input
        TRISB = 1                               ' PORTB is input
        TRISC = 0                               ' PORTC is Output
        TRISB.0 = 1                             ' B0 / Int is count input
        ADCON0 = %10010001                      ' ADC On, right justified
        ADCON1 = 0                              ' ADC Freq = 625KHz
        ASM                                     ; Insert ASM
        BANKSEL LCDCON                          ; LCD Configuration
        CLRF    LCDCON                          ; Turn off LCD Driver
        ENDASM                                  ; End of ASM
    '
    ' Variables and constants-------------------------------------------------------
    '
        W1  VAR WORD                            ' W1 is 16 bit variable
        W2  var word                            ' W2 is 16 bit variable 
        W3  var word                            ' W3 is 16 bit variable
        B0  var byte                            ' B0 is 8 bit variable 
    '
    ' Main program------------------------------------------------------------------
    '
    Main:
        ADCIN 4, W2                             ' Read Freq-to-voltage device
        W3 = W2 * 9774                          ' 9999 / 1023 = 9.774
        W1 = DIV32 1000                         ' Put the result in W1
        GOSUB GETNUM                            ' Show RPM
        Goto Main                               ' Do this forever
        END                                     ' For the compilers sake       
    '
    ' Subroutines-------------------------------------------------------------------
    ' 
    GETNUM:
        IF W1 >= 1000   THEN display4
        IF W1 >= 100    THEN display3
        IF W1 >= 10     THEN display2
        IF W1 >= 0      THEN display1
    display4:
        B0 = W1 / 1000	                        ' Find number of thousands
    	W1 = W1 // 1000	                        ' Remove thousands from W1
        Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
        PORTC = B0      	                    ' Send segments to LED
    	PORTA = $01     	                    ' Turn on fourth digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00	                            ' Turn off digit to prevent ghosting 
    display3:
    	B0 = W1 / 100	                        ' Find number of hundreds
    	W1 = W1 // 100	                        ' Remove hundreds from W1
    	Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0	                            ' Send segments to LED
    	PORTA = $02	                            ' Turn on third digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00     	                    ' Turn off digit to prevent ghosting 
    display2
    	B0 = W1 / 10	                        ' Find number of tens
    	W1 = W1 // 10	                        ' Remove tens from W1
    	Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0      	                    ' Send segments to LED
    	PORTA = $04  	                        ' Turn on second digit
    	Pause 1		                            ' Leave it on 1 ms
    	PORTA = $00	                            ' Turn off digit to prevent ghosting 
    display1
    	B0 = W1		                            ' Get number of ones
        Lookup B0,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67],B0
    	PORTC = B0	                            ' Send segments to LED
    	PORTA = $08     	                    ' Turn on first digit
    	Pause 1		                            ' Leave it on 1 ms
        PORTA = $00	                            ' Turn off digit to prevent ghosting     
        RETURN                                  ' Return to caller!
    Here's the code for the project. I've made it, so it doesn't show the zeroes before the actual RPM.

    I hope some of you can use it. Later I'll post the schematic for F/V converter

    ** EDIT **


    Here's the schematic for the F/V Converter. For the 8V source, i use a small regulator, so that the car can run between 12 and 13.8 V at the battery. Depending on the source to the converter, the potentiometer is turned, until satisfied. Mine will run of the 12V to the ignition coil, so that i have 4 pulses for one revolution of the engine.
    Depending on your choice of pulses, you may use a Frequency generator, at square-wave, and if your car pulses 4 times per revolution, then adjust it, until you get 5V out, at 4*166.66.
    If the car pulses once per revolution, set your frequency generator to 166.66 (mine was digital), and adjust the potentiometer until 5V is reached.

    You've now succesfully made a digital tachometer, that updates faster than the code could ever do, by it self.

    Good luck, and have fun all of you!
    Last edited by ThaSanta; - 24th July 2009 at 03:28. Reason: Adding F/V Schematic
    / Lerche

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts