Counter not counting !!!


Results 1 to 25 of 25

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    As Joe already mentioned earlier, RA4 T0CKI is a Schmitt Trigger input. If your sensor doesn't output a minimum voltage of 0.8 * VDD for logic 1 and 0.2 * VDD or less for logic 0, then the Schmitt Trigger input isn't seeing the correct logic levels, and TMR0 isn't counting your pulses.

    Here's a quick little test program to show how it works when RA4/T0CKI is connected to an I/O-pin to increment the counter.
    Code:
    @ DEVICE pic16F88, INTRC_OSC, CCPMX_ON, MCLR_OFF
    
    DEFINE HSER_BAUD 2400
    
    Loops VAR BYTE
    Revs var BYTE
    
    OSCCON=$60 ' use internal 4MHZ osc
    
    ANSEL = 0  ' disable A/D so RA4 is digital
    CMCON = 7  ' disable comparators
    
    TRISA.4=1  ' RA4/T0CKI = input (Timer0 clock input)
    PORTB.5=1  ' USART TX pin idles high
    PORTB.0=1  ' clock output pin to RA4 starts high
    TRISB.0=0  ' clock out pin to RA4/T0CKI = output
    TRISB.5=0  ' USART TX = output
    
    ANSEL = 0     ' disable A/D so RA4 is digital
    CMCON = 7     ' disable comparators
    OPTION_REG = %10110001 ' clk on RA4/T0CKI, falling edge, 1:4 prescale
    
    Mainloop:
        TMR0 = 0      ' clear count before each pass
        
        ' output 8 clocks on RB0 to RA4/T0CKI
        FOR Loops = 0 TO 7
          PORTB.0=1   ' RB0 connects to RA4/T0CKI
          PAUSE 5
          PORTB.0=0   ' counter increments on falling edge
          PAUSE 5
        NEXT Loops
          
        Revs = TMR0   ' get TMR0 count
        IF OPTION_REG.0 THEN
           HSEROUT ["Counts at 1:4 prescale: ",dec Revs,13,10]
        ELSE
           HSEROUT ["Counts at 1:2 prescale: ",dec Revs,13,10]
        ENDIF
        OPTION_REG.0 = OPTION_REG.0 ^ 1 ' toggle 1:4 or 1:2 prescale
        GOTO Mainloop 
        
        end
    It works great, but only as long as the input signal meets the threshold levels the Schmitt Trigger input buffer on RA4/T0CKI expects.
    Last edited by Bruce; - 20th February 2009 at 17:32. Reason: Quckie test program
    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