Pulse count matching


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2007
    Posts
    65

    Default Pulse count matching

    Hi all;

    -In a 16F628A, I receive a pulse into a timer, in counter mode, let's say timer1.
    Question:
    -Is there any kind of interrupt flag or trick that tells me when it matches a specified count? (example: when TMR1=231)


    I know QEI does it great in 18F4431 family members, but I don't have them, and I have 12 units of 16F628A here in my desktop.

    Thanks for any ideas or comments
    Last edited by RodSTAR; - 21st April 2008 at 09:32.
    "Beethoven had his critics too, see if you can name 3 of them"

  2. #2
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Another detail is that at the same time I want to get pulse rate (to calc speed).
    ¿ Should I use:
    -Timer0 (or timer1) as Timer and
    -Timer1 (or timer0) as Counter...
    ... to feed my variables to calculate speed?
    "Beethoven had his critics too, see if you can name 3 of them"

  3. #3
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    I think in a possible solution:
    Connect my pulse wire to RB6/T1CKI, that is Timer1 input pin, PORTB. Hope I can use RB Port Change Interrupt at the same time as Timer1 is ON. If it is possible, then:

    To get pulse count:
    -when INTCON.0=1 (alias RBIF) interrupt onchange in PORTB, increment MyCounter variable 'manually',
    To get time interval:
    -use Timer1 and calculate speed on each Timer overflow interrupt PIR1.0=1 (alias TMR1IF) or whenever i want

    Is it possible that solution??



    PD:
    [It has come to my mind another question about Interrupts Identification in a new Thread...'Interrupts Identification']
    Last edited by RodSTAR; - 21st April 2008 at 09:39.
    "Beethoven had his critics too, see if you can name 3 of them"

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Too many questions at the same time for me.... I'll start with the first one:
    -In a 16F628A, I receive a pulse into a timer, in counter mode, let's say timer1.
    Question:
    -Is there any kind of interrupt flag or trick that tells me when it matches a specified count? (example: when TMR1=231)
    There's at least two ways of doing this as I see it. Either you preset the TMR register with 65535-231 (for a 16bit timer) and when the timer/counter overflows you'll get your interrupt. OR you can use the CCP-module in compare mode, it's designed for doing exactly that. When TMR1 matches the CCPR1 register you'll get an interrupt.

    /Henrik.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Just open the '628 datasheet ... CCP1 chapter

    11.2 Compare Mode
    In Compare mode, the 16-bit CCPR1 register value is
    constantly compared against the TMR1 register pair
    value. When a match occurs, the RB3/CCP1 pin is:
    • Driven High
    • Driven Low
    • Remains Unchanged
    The action on the pin is based on the value of control
    bits CCP1M3:CCP1M0 (CCP1CON<3:0>). At the
    same time, interrupt flag bit CCP1IF is set.
    FIGURE 11-1: COMPARE MODE
    OPERATION BLOCK
    DIAGRAM
    11.2.1 CCP PIN CONFIGURATION
    The user must configure the RB3/CCP1 pin as

    ....
    Isn't life superb ???

    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 " !!!
    *****************************************

  6. #6
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Wink

    Hi Henrik & Alain;

    I'm amazed with both excelent solutions you gave me . I'll use them in other projects I have in mind.
    Nevertheless, Alain's solution can't fit in this particular project, because it is a motor controller. (sorry, but I didn't tell it before to focus the thread on the specific part of the problem)

    Why can't fit in my project?

    Alain's CCP1 solution can't be possible, because as motor controller, I use the unique CCP module in PWM mode to drive motor's H-bridge. (remember it's a PIC16F68A)
    Well, of course Alain (Acetronics) couldn't guess that CCP was unavailable: I had not told it.

    To Henrik's solution, I'll add TMR0 in timer mode, as time reference, for speed calculation. A little bit uncomfortable (8-bit variable), but factible (I hope).

    Thank you Alain and Henrick.

    PD: I would be still more gratefull if any of you give me an opinion on my Post#3.

    Regards!
    Rodrigo
    "Beethoven had his critics too, see if you can name 3 of them"

Similar Threads

  1. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 01:59
  2. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  3. Indexer not indexing...a basic PBP problem??
    By jellis00 in forum General
    Replies: 8
    Last Post: - 24th March 2009, 16:53
  4. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  5. Replies: 3
    Last Post: - 13th September 2008, 17:40

Members who have read this thread : 1

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