LED Machine Tach For Tired Eyes


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default LED Machine Tach For Tired Eyes

    Hello,
    I am trying to make a tachometer for my lathe and milling machines. I have joined M E Labs 7 segment example to some code I was experimenting with a year ago or so. The code does count and return a value, I have not attempted to make it return any useful numbers yet, as I am not at all satisfied with what it displays, 1: the portA.3 output is much brighter than the other 3, all switched with 2n3906 transistors, and the less bright displays are too dim. I decreased the initial pause directly after T1CON to increase the loop speed so as to make the display flash faster than my eyes can see,This makes the displays brighter too, I think however I will never be able to make enough pulses to use this as anything but an RF freq. counter with this setting. What I am contemplating is to add TTL latches to the ABCDEFG and DIG ports to freeze the LEDs on between cycles. Does anyone have better Ideas?
    Thank You
    Joe S.

    oh BTW PIC 16F876A and 2" tall LED 7 Segment displays

    Code:
    @ __config  _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF  & _BODEN_OFF
    define OSC 20
    CMCON  = 7
    ADCON0 = 0
    ADCON1 = 7
    
    
    TrisA = %00000000
    TrisB = %00000000
    TrisC = %00000001
    Segments Var	PORTB
    Digits	 Var	PORTA
    PORTC = %00000011
    PAUSE 500
    PORTC = %00000000
    
    CounterTotal var word
    RPM          VAR WORD 
    i	           Var Byte
    n	           Var Byte
    
    RPM = 0
    T1CON = %00000111 ' bits 0, 1, 2 set high, prescaler to 1:1
    
    
    
                                                                                            
    START:
    TMR1L = 0
    TMR1H = 0
    
    
    mainloop:
    
    counterTotal.lowbyte=TMR1L
    counterTotal.highbyte=TMR1H
    TMR1L = 0
    TMR1H = 0 
    
    T1CON.0=1
    pause 5   <font color = red>' the greater the delay the slower the display flashes</font color>
    rpm = (CounterTotal * 2) 'no attempt has been made here to get accurate numbers
    
    
    	GoSub display	' Display the value
    T1CON.0=0	
    	GoTo mainloop		' Do it forever
    
    
    ' Subroutine to send the number (0 - 9999) in Value to LEDs
    display:
    	For i = 0 To 3		' Loop through 4 digits
    		n = RPM Dig i	  ' Get digit to display
    		GoSub display1	' Display the digit
    				      ' Leave it on 2 millisecondS
    	Next i			      ' Do next digit
    	
    	Return
    
    
    ' Surboutine to display one digit on LED
    '  i = digit number
    '  n = number to display
    display1:
    	'Digits = $ff		' All digits off to prevent ghosting
    
    	' Convert binary number in n to segments for LED
    	Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18,$7f], Segments
      ' logic low complements
    	' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
    	Digits = ~Dcd i
      Pause 2<font color = red> Increase to make digits brighter and flicker worse</font color>
    	Return
    	
    	end
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Feed your individual digits into a few 74LS373 (or 74LS573) latches, kicks the latch pin, have the output from the 393's drive ULM2803's which connect directly to your 7 segment LEDs. Or might not even need the ULN2803, could probably drive the LEDs directly from the '373...

    Set everything up, set the output enables high, set the output latches high...

    Pull the output enable pin on the first '373 high, put the first number for output on PortA, toggle the first '373 latch pin, pull the first '373 output enable pin low, leave it
    Put the output enable pin on the second '373 high, put the second number for output on PortA, toggle the second '373 latch pin, pull the second '373 output enable pin low, leave it. Since you didn't trigger the latch enable pin on the 1st '373, it won't do squat but sit there and output for you...thereby stay sitting still.

    Wash, lather, rinse, repeat, all the way down the line...


    Or even easier, buy up one of those 'large-ish' backlit LCDs.
    Last edited by skimask; - 18th June 2008 at 04:01. Reason: EDIT: Wrong chip was listed...added info...

  3. #3
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    I did a similar counter several years back with some 4" tall digits I just over drive the LEDs, for example if you have 4 digits and each segment is 20mA, pump each segment to 80mA. I also found it necessary to put a resistor to each of the 7 outputs to the LED segments rather than just a common resistor - else I found that a 1 was much brighter than anything else - and of course the 8 was quite dim.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Joe,

    I think the problem is in the pauses.
    The first 3 digits are on for 2ms each, then the last digit is on for 7ms (2ms + 5ms in the main loop). So the dutycycles are around 15% for the 3 digits and over 50% for digit 4.

    Removing the 5ms pause in the Mainloop should make them all the same brightness with 25% duty.

    But you still need a Time Base if you want to read RPM, and you'll need to do some math to convert the result which will cause small variances in the brightness as the delays thru the loop change.

    This sounds like the perfect job for Instant Interrupts.

    I just happen to have some hardware available, that's hooked up the same way as the meLabs 7-segment demo.
    http://www.picbasic.co.uk/forum/show...?p=58076#58076

    Feel like trying it a different way?
    <br>
    DT

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Hi Joe,

    I think the problem is in the pauses.
    The first 3 digits are on for 2ms each, then the last digit is on for 7ms (2ms + 5ms in the main loop). So the dutycycles are around 15% for the 3 digits and over 50% for digit 4.

    Removing the 5ms pause in the Mainloop should make them all the same brightness with 25% duty.
    <br>
    That answered a question I didn't exactly know how to ask.
    Quote Originally Posted by Darrel Taylor View Post
    But you still need a Time Base if you want to read RPM, and you'll need to do some math to convert the result which will cause small variances in the brightness as the delays thru the loop change.
    <br>
    I thought the pause was the time base! In the example it was 500.
    Quote Originally Posted by Darrel Taylor View Post
    This sounds like the perfect job for Instant Interrupts.

    I just happen to have some hardware available, that's hooked up the same way as the meLabs 7-segment demo.
    http://www.picbasic.co.uk/forum/show...?p=58076#58076

    Feel like trying it a different way?
    <br>
    OH HECK YES . . . I was getting ready to output BCD into some 4511s so as to have a latch to get brightness without flicker . . . In fact to that end I ordered some common cathode LEDs last night, I already have common anode ones here.<h2><b>LEAD THE WAY MASTER</h2></b>Thank You Darrel.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello again,
    M E Labs has a lot of code samples, many of you have examples there, and here is a sample from mister_e that I believe will do what I need without all the overhead associated to using latches. I am posting it here as the download from ME Labs has some cut paste errors, specificly duplicate IF THEN loop which upset my compiler's little tummy I modified mister_e's code only enough to port it to a 16F628A, . . . Great piece of work Steve ! Thank You !
    Code:
    ' Pulse counter
    ' =============
    '
    ' File name : Count_Display.bas
    ' Company : Mister E
    ' Programmer : Steve Monfette
    ' Date : 27/12/2004
    ' Device : PIC16F84A-20/P
    '
    '
    ' This program display to 3 x 7 segments dislay the result of
    ' pulses count on PORTA.4 pin/sec.
    '
    ' Hardware connection :
    ' ---------------------
    '      1. 3 X 7 segments display on PORTB<7:0>
    '      2. 3 X PNP transistor on PORTA<3:0> to drive common anode
    '         of each 7 segments display
    '
    '
    ' Programming mode and PIC define
    ' -------------------------------
    '
    @ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF
    CMCON=7       ' ADDED FOR PIC16F628A   
    DEFINE OSC 20 ' use 20 MHZ oscillator
    
    
        ' I/O Definition
        ' --------------
        '
    TRISA = %11111000 ' PORTA  : <2:0> outputs to common Anode of 7 segment
                          '                1. PORTA.0 More significant
                          '                2. PORTA.2 Less significant
                          '        : PORTA.4 input for signal
                          '
    TRISB = 0         ' PORTB connected to 7 segments
                      '       B0 : segment a
                      '       B1 : segment b
                      '       B2 : segment c
                      '       B3 : segment d
                      '       B4 : segment e
                      '       B5 : segment f
                      '       B6 : segment g
                      '       B7 : segment decimal dot
                          
    
    ' Internal EEPROM definition
    ' --------------------------
    '
    data @0,192,249,164,176,153,146,130,248,128,144 ' table to convert
                                                    ' numbers to 7 segments
                                                    ' pattern output when
                                                    ' drive invert
                                                        
    
    
    ' Interrupt and register definition
    ' ---------------------------------
    
    OPTION_REG = %1111000   ' TMR0 clock source : RA4/T0CKI
                            ' increment on low to high transition
                            ' Prescaler assign to WDT
                            ' WDT rate 1:1
                            '
    INTCON = %10100000      ' Enable global interrupt
                            ' Disable EE write interrupt
                            ' Enable TMR0 overflow interrupt
    
            
        ' Variable definition
        ' -------------------
        '
    DisplayPort  var PORTB   ' Port for 7 Segments
    ClockInput   var PORTA.4 ' Input pin for signal
    _7Seg1       con 14      ' enable more significant 7 segment display
    _7Seg2       con 13      ' enable mid significant 7 segment display
    _7Seg3       con 11      ' enable less significant 7 segment display
    Digit_1          var byte    ' Hundreds digit
    Digit_2          var byte    ' Tenth digit
    Digit_3          var byte    ' Unit digit
    ToBeDisplay  var word    ' Result of count to be send to 7 segment display
    Display      var byte    ' Temp variable
    DisplayLoop  var byte    '
    Delay        var word    ' Variable for Delay loop
    OverFlowVar  var word        '
    Thousands    var bit         ' Flag for count >= 1000 & < 10 000
    TenThousands var bit         ' Flag for count >= 10 000
    
        ' Variable and software initialisation
        ' ------------------------------------
        '
    tobedisplay = 0 ' set initial value of count
    TMR0 = 0        ' reset prescaller
    On interrupt GoTo SetVarToBeDisplay
        
    MainLoop:
    
        ' MainLoop
        ' ---------
        '
        ' 1. display the result of the count on RA4 pin
        ' 2. refresh display
        ' 3. reset Timer0
        ' 4. reload prescaler.
        '
        ' Duration of the procedure : 1 sec
        '           fine tuned by DelayBetweenEachDisplay Sub
        '
        ' Looping 1 sec and get results of the pulse count in
        ' TMR0 + OverFlowVar
        '
    DisplayRefresh:
            '
        ' Testing amount of count
        ' -----------------------
        '
        ' Get the result of count and place decimal point flag
        ' on the according 7 segments
        '
        If tobedisplay>= 1000 Then
        tobedisplay = tobedisplay / 10
        Else
            tenthousands = 0
               thousands = 1
    EndIf
         
        '
        ' convert digit to 7 segment output pattern
        ' -----------------------------------------
    display=ToBeDisplay dig 2 ' Read hundreds digit
    read display, digit_1     ' Convert hundreds
         if thousands==1 then digit_1=digit_1 & $7F ' enable decimal dot
                                                       ' by clearing PORTB.7
    
        display=ToBeDisplay dig 1 ' Read tenths digit
        read display, digit_2     ' Convert tens
            if tenthousands==1 then digit_2=digit_2 & $7F ' enable decimal dot                          '
                                                      ' by clearing PORTB.7
                                                      
            display=ToBeDisplay dig 0 ' Read units digit
            read display, digit_3     ' Convert units
        '
        '
        ' Send digit to 7 segments
        ' ------------------------
        For displayloop = 0 To 111 ' loop for about 1 sec
    
            ' display hundreds
            ' ----------------
            PORTA=_7seg1        ' enable hundreds 7 segment
            displayport = digit_1 ' display
            GoSub DelayBetweenEachDigit
            
            ' display tenth
            ' -------------
            PORTA=_7seg2        ' enable tenth 7 segment
            displayport = digit_2 ' display
            GoSub DelayBetweenEachDigit
            
            ' display units
            ' -------------
            PORTA=_7seg3        ' enable unit 7 segment
            displayport = digit_3 ' display
            GoSub DelayBetweenEachDigit
            
        Next
        tobedisplay = OverFlowVar + TMR0
        OverFlowVar = 0 ' Reset OverFlowVar
        TMR0 = 0        ' reset prescaller
        GoTo DisplayRefresh
    
    
    DelayBetweenEachDigit:
    
        ' DelayBetweenEachDigit
        ' ---------------------
        ' Produce delay of about 3 mSec
        '
        ' Fine tuned with MPLAB StopWatch to get MainLoop = 1 sec
        '
            For delay = 1 To 307
                @ nop
            Next
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
        Return
    
    
        disable
    SetVarToBeDisplay:
        '
        ' SetVarToBeDisplay
        ' -----------------
        ' interrupt routine of TMR0 overflow
        '
        ' Reset prescaller
        ' Reset overflow flag
        '
        OverFlowVar = OverFlowVar + 256
        INTCON.2 = 0 ' clear overflow flag
        TMR0 = 0     ' reload TMR0
        Resume
        enable
    
    END
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's a "Straw", I'm a "Camel", and my back is broken.

    2 days of work, and as I'm posting it I see ... "Nevermind, I'll use mister-e's program".
    Arrrrghhh.

    Enjoy.
    DT

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    That's a "Straw", I'm a "Camel", and my back is broken.

    2 days of work, and as I'm posting it I see ... "Nevermind, I'll use mister-e's program".
    Arrrrghhh.

    Enjoy.
    No NO NO NO Don't be that way Darrel, I really want to see what you have come up with! You and Mister_e, Melanie, and a few others all write really sweet code, and I am humbled, that you have made this effort. I thought you were standing by to see what I could come up with (I know, there I go thinkin' again). I just really thought this example needed to be "showcased"as a lot of NOOBS may have tried unsucessfuly to use it, due to aforementioned . . . misprint? For sure I have no intent to offend Professor Rex Nexus Taylor of the Crownhill University. I'm like an old hound dog with a bone, keep on shakin' it and shakin' it till I get the marrow out of it, now for steak . . . as for you being a Camel, yea like Secretariate was huh?
    Last edited by Archangel; - 21st June 2008 at 11:45. Reason: recap
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. LED Tach Sources?
    By Netjammer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th October 2004, 03:47

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