Tachometer with DT Interrupts?


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default Tachometer with DT Interrupts?

    Hello Guys,

    Well, for a few weeks, maybe a few months, I've been trying not to open this thread, as a website admin from another forum I know what is like to have the same question asked over and over again, but I couldn't find a simple piece of code for a tachometer using DT Interrupts (if it's possible to do that).

    I don't need the config fuses for the PIC (16F88) or the entire code for the project I'm doing (a wireless tach for R/C brushless cars), I only need to know how to read how many pulses there are on a pin in a second and read that from a word variable (because I think a byte is not enough) using DT Interrupts.

    So, could someone give me a hand with this request? (don't like the words help/problem)

    Thanks!

    Daniel.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Daniel

    I generally use TMR1 and it's interrupt, reading Timer1 ( as free running timer ) ...

    just read it @ each interrupt ... difference from previous read ... gives the period.

    @ 20 Mhz max resolution is 200ns which is quite enough ...

    Alain
    Last edited by Acetronics2; - 17th November 2009 at 08:07.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Hi Daniel, you can also use the timer1 as an asynchronous counter, and connect your encoder directly to portB.6 (pin 12) and with two words variable one for the count one for the delay you will govern the counting process. You can also set (using DT interrupt) an overflow routine which will tell you when the setted delay time is too much.

    All the time you will call the subroutine Get_Count the word Counter will contain the count from time0 and time0+delay. Setting delay appropriatly the counter could give you the speed without any additional maths.

    Al.



    Code:
    Counter var word
    Delay   var word
    
    
    Get_Count:
    TCON1 = 6
    TMR1L = 0
    TMR1H = 0
    TCON1 = 7
    Pauseus Dalay
    TCON1 = 6
    Counter.Byte0 = TMR1L
    Counter.byte1 = TMR1H
    Return
    All progress began with an idea

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I posted this at least once before, but here it is again;


    Code:
            INCLUDE "DT_INTS-18.bas"         ; Base Interrupt System
    
      
    ASM
    INT_LIST  macro    
                  INT_Handler    TMR0_INT,   ReadTachs,   ASM,  yes 
    
              endm
        INT_CREATE              
    ENDASM
                             
    Goto OverInt
    
    ;-----------------------------------------------------------------
       
    Asm                            
    ReadTachs
             movff    PreloadH,TMR0H  ; Preload depends on clk speed
             movff    PreloadL,TMR0L
          
            
          
             infsnz  MasterClock                     ; 16 bit timer used for housekeeping
             incf    MasterClock + 1
            
             btfsc   TPE,0                             ; Tells tach routine to stop
             bra     DoneForNow
            
    ;CheckTach        
             infsnz  TachClock          ; Tells tach counters how long to count
             incf    TachClock + 1
         
             movlw   0x03 - 1          ; Real value is 1000 = 0x3E8, but must have one less
             cpfsgt  TachClock + 1      ; to compare with greater than
             bra     TachRoutine
             movlw   0xE8 - 1          ; Likewise, subtract one here, too.
             cpfsgt  TachClock
             bra     TachRoutine
             bsf     TPE,0
             
             clrf    TachClock
             clrf    TachClock + 1
             bra     DoneForNow
                    
    TachRoutine
                  
             movf     PORTB,0,0
             movwf   Temp,0            ; Save VAR so can't change between compare and save
             xorwf    OldPortB,0,0
             movwf   changedB,0
             movff    Temp,OldPortB
             
             movf     PORTC,0,0
             movwf   Temp,0
             xorwf    OldPortC,0,0
             movwf   changedC,0
             movff    Temp,OldPortC
             
             movf     PORTD,0,0
             movwf   Temp,0
             xorwf    OldPortD,0,0
             movwf   changedD,0
             movff    Temp,OldPortD
             
             
    Tach1       
             btfss   changedB,0
             bra     Tach2
             infsnz  Tach1Counter
             incf    Tach1Counter+1
           
    Tach2        
             btfss   changedB,1
             bra     Tach3
             infsnz  Tach2Counter
             incf    TachCounter+1
                    
    Tach3        
             btfss   changedB,2
             bra     Tach4
             infsnz  TachCounter
             incf    TachCounter+1
    Tach4        
             btfss   changedB,3
             bra     Tach5
             infsnz  Tach4Counter
             incf    Tach4Counter+1
           
    Tach5       
             btfss   changedB,4
             bra     Tach6
             infsnz  Tach5Counter
             incf    Tach5Counter+1        
           
    Tach6       
             btfss   changedB,5
             bra     Tach7
             infsnz  Tach6Counter
             incf    Tach6Counter+1 
                     
    Tach7        
             btfss   changedC,0
             bra     Tach8
             infsnz  TachCounter
             incf    TachCounter+1  
               
    Tach8        
             btfss   changedD,5
             bra     Tach9
             infsnz  Tach8Counter
             incf    Tach8Counter+1               
                  
    Tach9        
             btfss   changedD,4
             bra     DoneForNow
             infsnz  Tach9Counter
             incf    Tach9Counter+1  
                         
    DoneForNow
            
             bcf     INTCON,2   ; Clear the TIMER0 interrupt flag
           
            INT_RETURN	 	
    ENDASM

    Set the PRELOAD value for the interrupt period (must be shorter than the shortest tach half-cycle). Set the TachCounter for how many interrupts you want to count over (currently 1000). Clear all the TachCounters and set TPE to 0. Periodically check to see if TPE is set. If so, copy the TachCounters to other variables, zero the variables and start over. All done in the background and does a nice job of averaging - something you will need if there is any kind of noise present.
    Charles Linquist

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thank you guys!!! I'll try the examples you gave me... To tell you the truth, this is my first time with interrupts, so, wish me luck..

    Daniel.

Similar Threads

  1. Tachometer with Interrupts
    By serkanc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 28th August 2009, 08:10
  2. DT interrupts and Pause
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th February 2009, 22:47
  3. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  4. DT Instant Interrupts help
    By perides in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 26th November 2008, 18:41
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 2

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