Counter


Closed Thread
Results 1 to 5 of 5

Thread: Counter

  1. #1
    Join Date
    Mar 2004
    Location
    Manila
    Posts
    18

    Default Counter

    What can be a good solution for a very low speed counter? 2 pulse per sec.

    loop:
    If flagA=1 then goto check_low_pulse
    If porta.o = 1 then flagA = 1
    goto loop

    check_low_pulse:
    If porta.0 = 0 then
    flagA=0
    count1=count1 + 1
    endif

    goto loop

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


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    The dawback of the "event counter" method is a very, very, very bad resolution ...

    Sooo, the best would be to measure the period, and then convert it to speed.


    Depends on your skills ... but a 16 Bits timer looks compulsory. The TMR1 of a 16F628a gives a 524288 µs period ( 1.907 Hz) with 1:8 prescaler enabled.

    may be a bit "short" for what you intend to do; you should then have to increment a counter for each overflow ( interrupt ) ... and truncate some bits of TMR1 result, just to keep a 16bits word for your calculations.

    a more precise explanation of what you're looking for will surely help ( Freq. range and precision required ... at least )

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

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This might get you started.

    I use this for counting parts passing on a conveyor where the parts hit a mechanical switch.

    16F873A is used.

    Near the top of your code
    Code:
    ON INTERRUPT GOTO MYINT
    
    INTCON = %10010000
    setup variables and other stuff then
    Code:
    LOOP:
    'DO STUFF
    GOTO LOOP
    
    '#############################################
    'PART COUNT
    '############################################
    DISABLE
    MYINT:
    IF PORTB.0 = 1 THEN
        PC = PC + 1
    	WRITE 3,PC.BYTE0
    	WRITE 4,PC.BYTE1
        READ 3,PCNT.BYTE0
    	READ 4,PCNT.BYTE1
        pause 100
    ELSE
    	PC = PC
    ENDIF
    INTCON.1 = 0
    RESUME
    ENABLE
     'THE ABOVE WILL ALSO DEBOUNCE THE SWITCH
    '#############################################
    PS.
    What is that in your mouth?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post

    PS.
    What is that in your mouth?

    Ohoh, Dave

    Did not recognize the strawberry ??? ...

    yours to offer the Champagne, then

    Alain

    But keep cool , the photo surely is not Brenda's ...
    ************************************************** ***********************
    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 " !!!
    *****************************************

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Ohoh, Dave

    Did not recognize the strawberry ??? ...

    yours to offer the Champagne, then

    Alain

    But keep cool , the photo surely is not Brenda's ...
    Now I see it.

    Must be a sour one.
    Dave
    Always wear safety glasses while programming.

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. Counter not counting !!!
    By lerameur in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 20th February 2009, 22:15
  3. Replies: 42
    Last Post: - 14th January 2008, 11:38
  4. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 05:02
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27

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