Counting RPM's with Interrupt? Speed Limitations?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Counting RPM's with Interrupt? Speed Limitations?

    I have a PIC that controls a Geared Motor with the PWM output (Works great). It also has a LCD attached, I want to display a count for every RPM, then I also will have a AD setting for a RPM MAX COUNT, basically i can set how many rotations is the limit, it will run and count input pulses till it reaches the max limit then auto shut off motor. my question is can i use the interrupt to count pulses from a magnetic reed switch , max speed or RPM on motor is say 1500, so 1500 / 60 = Hertz
    so 25hz, can the IRQ of a microprocessor handle 25 activations a second?

    if not anyone have another way of doing this?

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Counting RPM's with Interrupt? Speed Limitations?

    Yes, a PIC is more than capable of interrupting at that frequency. The problem will be the reed switch.
    If you use an un-bounced reed switch, you will likely catch a lot of bouncing, and the PIC will interrupt many times due to the bounce.
    You might look into hall effect or light/optical methods of triggering the interrupt that would be less prone to bounce.

  3. #3
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Counting RPM's with Interrupt? Speed Limitations?

    yea, i was going to use a debounce circuit, but i do have a surplus of IR emiter/detector interupters, I can use one of them. thanks

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


    Did you find this post helpful? Yes | No

    Default Re: Counting RPM's with Interrupt? Speed Limitations?

    The following code can be used or modified to do what you want. Everything is done in the background.

    The good thing about it, is that it can be used on any port - not just port B.
    And it will watch a large number of tachs - not just 8 (of course, you have to expand the ASM section).
    It does NOT need a debounce - as long as the sample interval is longer than the expected bounce time.

    The sample interval is set by the TMR0 interrupt rate. The interrupt rate must be high enough to 'catch' every
    HIGH and LOW of the input. So if the HIGH time of the input is 10 mSec and the LOW time of the input is 30 mSec,
    then the interrupt must be faster than 10 mSec.

    As written, the code will run for 1000 interrupt times, then quit. if you don't want it to stop, and only count trasitions, simply eliminate
    the TACHCLOCK part.

    (as written)

    To start,

    Clear the TachCounters
    Clear TPE

    In your main loop, check for TPE to be set. If it is,

    Read the TachCounters
    Clear the TachCounters
    Clear TPE




    Code:
           INCLUDE "DT_INTS-18.bas"         
    
      
    ASM
    INT_LIST  macro    
                  INT_Handler    TMR0_INT,   ReadTachs,   ASM,  yes 
    
              endm
        INT_CREATE               
    ENDASM
                             
    Goto OverInt
    
    '---[TMR0 interrupt handler]---------------------------------------------------
       
    Asm                            
    ReadTachs
             movff    PreloadH,TMR0H  ; Preload depends on clk speed
             movff    PreloadL,TMR0L
     
             btfsc   TPE,0
             bra     DoneForNow
            
           
             infsnz  TachClock        
             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    PORTF,0,0
             movwf   Temp,0            ; Save VAR so can't change between compare and save
             xorwf   OldPortF,0,0
             movwf   changedF,0
             movff   Temp,OldPortF
      
             
    Tach1       
             btfss   changedF,0
             bra     Tach2
             infsnz  Tach1Counter
             incf    Tach1Counter+1
           
    Tach2        
             btfss   changedF,1
             bra     Tach3
             infsnz  Tach2Counter
             incf    Tach2Counter+1
                    
    Tach3        
             btfss   changedF,2
             bra     Tach4
             infsnz  Tach3Counter
             incf    Tach3Counter+1
    Tach4        
             btfss   changedF,3
             bra     DoneForNow
             infsnz  Tach4Counter
             incf    Tach4Counter+1
           
               
    DoneForNow
            
             bcf     INTCON,2   ; Clear the TIMER0 interrupt flag
            INT_RETURN	 	
    ENDASM
    
       
      
    OverInt:  
    
    TachCounter1=0:TachCounter2=0:TachCounter3=0:TachCounter4=0
    
    asm
             movff    PreloadH,TMR0H  ; Preload depends on clk speed
             movff    PreloadL,TMR0L
             bcf     INTCON,2 
    endasm
    
       TPE = 0
    
    INT_ENABLE TMR0_INT
    
    (your code here)
    Charles Linquist

  5. #5
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Counting RPM's with Interrupt? Speed Limitations?

    Ok sorry thats way beyond me, fir right now i just need the single counter, as far as a tachometer, i can just use the pulsein and get a counter for that if i need it. thans everyone for there input, if anyone could show me how to enable those extra irq's, say I want to use all 3 INT's on a 18f4550 (portb 0,1,2)

Similar Threads

  1. PBP vs Assembly interrupt speed
    By purkolator in forum General
    Replies: 1
    Last Post: - 11th July 2012, 15:43
  2. Replies: 6
    Last Post: - 20th November 2011, 23:59
  3. Replies: 0
    Last Post: - 7th August 2008, 10:02
  4. DT Instant Interrupt counting
    By jderson in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 9th March 2008, 23:47
  5. PIC Basic 2.33 limitations
    By emavil in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th August 2006, 04:10

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