Counter not counting !!!


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try this;
    Code:
    Mainloop:
    TMR0 = 0 ' clear count before each pass
    PAUSE 5000 ' give it some time to count pulses
    Revs = TMR0 ' get TMR0 count
    Counter = Counter + 1
    LCDOUT $FE,1,"Counter1: ", DEC Counter
    LCDOUT $FE,$C0, "Revs: ", DEC Revs
    GOTO Mainloop
    Counter of course is always going to change every 5 seconds or so, but Revs shouldn't until you have pulses in on RA4.

    Timer0 will automatically count pulses. You don't need to check any regs, bits, etc, just read it & clear it as required.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I did output the Revs and it increment without any input:
    not as fast, takes about 2 seconds to get to ten.
    The odd thing is that it increment without changes to RA4.
    I am going to try your code you posted and be back later
    thanks for your time

    Mainloop:
    TMR0 = 0 ' clear count before each pass

    ' output 8 clocks on RB0 to RA4/T0CKI
    'instead, input from sensor


    Revs = TMR0 ' get TMR0 count
    Counter = Revs + 1
    IF OPTION_REG.0 THEN
    LCDOUT $FE,1,"Revs: ", DEC Revs
    ELSE
    lcdout $FE,$C0, "Counter2: ", DEC Counter
    ENDIF
    OPTION_REG.0 = OPTION_REG.0 ^ 1 ' toggle 1:4 or 1:2 prescale

    GOTO Mainloop

    end

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Hi again

    I set my function generator to 100Hz and the Revs outputs 127, when I set it to 1000Hz, I get Revs 225 on my LCD.
    I get a specific number to from different frequency input.

    Ken

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    That's a good sign. Higher frequency should = a higher count in a given time period.

    FYI: You really don't need to keep flipping OPTION_REG.0. That was just a part of my
    previous example to show the count difference with different prescaler values. I would
    leve it set at one prescale if you want valid counts.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Replies: 42
    Last Post: - 14th January 2008, 12:38
  3. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 06:02
  4. Replies: 4
    Last Post: - 18th June 2007, 14:38
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27

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