Count?


Closed Thread
Results 1 to 10 of 10

Thread: Count?

  1. #1

    Default Count?

    I obviously don't understand how the COUNT instruction works. The PBP manual says "The resolution of Period is in milliseconds. It tracks the oscillator
    frequency based on the DEFINEd OSC." In the program below, the period is 1000msec., or 1 second. When I apply a 66 hz. squarewave to RC5, I the LCD says 66. When I change the period to 2000, it says 33. Shouldn't it say 132? Also, if I change the period to 500, the LCD says 33. I don't get it.

    ;****16F946:

    Pause 10 ;for ICSP
    @ __config _WDT_OFF & _CP_OFF & _PWRTE_ON & _MCLRE_ON & _INTRC_OSC_NOCLKOUT

    OPTION_REG = %11000000 ;pullups disabled, rising edge, no prescale
    ANSEL = 0 ;all pins digital
    CMCON0 = 7 ;comparators off
    ADCON0 = 0 ;ADC's off
    WDTCON = 0 ;WDT off

    TRISA = %00000000
    TRISB = %11000001 ;switches on RB6,RB7, INT on RB0
    TRISC = %00000000 ;LED on RC5, LCD bias on RC3
    TRISD = %00000000
    TRISE = %00001000 ;MCLR on RE3
    TRISF = %00000000
    TRISG = %000000

    OSCCON = %01100001 ;4mz. mhz. internal

    LCD_DB4 VAR PORTB.1
    LCD_DB5 VAR PORTB.2
    LCD_DB6 VAR PORTA.7
    LCD_DB7 VAR PORTA.6
    LCD_RS VAR PORTB.3
    LCD_E VAR PORTD.2
    LCD_Lines CON 1 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
    LCD_DATAUS CON 2 ' Data delay time in us
    LCD_COMMANDUS CON 20 ' Command delay time in us

    INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****

    define OSC 4

    W1 var WORD
    X1 var word
    X1 = 0

    PORTC.4 = 0 ;leds off
    PORTD.3 = 0

    Main:

    count PORTC.5, 1000, W1
    lcdout $fe,1, dec W1
    pause 10
    goto Main

    Any help will be greatly appreciated.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Probably you've hit one limitation of COUNT.

    Try this one
    Code:
    @wTimer1 = TMR1L
    wTimer1 var word EXT
    T1CON = %00000111
            'xx--x---- Don't care
            '--00----- Prescaler 1:1
            '-----1--- Do not synchronized external clock input
            '------1-- External clock from TOCKI pin (Rising edge)
            '-------1- Enable Timer1
    
    Main:
            wTimer1=0  ' clear Timer1
            pause 1000 ' acquisition time
            lcdout $fe,1, dec wTimer1
            pause 10
            goto Main
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    And ho, before trying the above, don't forget to set RC5 as an input first...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    DOH...

    Should have wrote T1CKI instead of T0CKI... silly mistake... oh well, it's just comments

    HAVING THE EDIT BUTTON BACK WOULD BE REALLY NICE, BUT IT STILL SEEMS TO BE A REALLY TOUGH THING TO IMPLEMENT!!!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    the period is 1000msec., or 1 second. When I apply a 66 hz. squarewave to RC5, I the LCD says 66
    Returns the same here.
    When I change the period to 2000, it says 33. Shouldn't it say 132?
    Yep. Just tested one with with a 66hz signal, and it does indeed return 132.

    Also, if I change the period to 500, the LCD says 33.
    That's what it should return.

    Are you sure you're not changing anything else when you're testing it with 2000 as the
    period?
    Regards,

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

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Bruce, I just did it again with exactly the same code as posted. The ckecksum is 3174 with 1000, and 3160 with 2000. Could you check your checksums? I'll check the incoming pulses with a scope later tonight, to make sure nothing's changing there.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    After adding the line to enable T1 within the Main loop, Mr. E's program does want I need. Thank you Mr. E!

    Main:

    wTimer1=0 ' clear Timer1
    T1CON = %00000111
    pause 1000 ' acquisition time
    T1CON = %00000110
    lcdout $fe,1, dec wTimer1
    pause 100
    goto Main

    However, the program that uses COUNT does not work! Maybe it's peculiar to the PIC I'm using? I did notice it has something to do with the watchdog timer, but I'm not going to mess with it further right now.

    Thank you everyone for the help.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Great, and it use the internal hardware, use less code space and etc.

    Anyways, out of curiosity, which PBP version you're using?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Yes, I think it is a better solution all around! I am using 2.50b, Haven't installed the latest patch yet. Thanks again!

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    For the record, I tried COUNT with a 16F917, and it worked regardless of the acquisition time. Hard to tell where the issue come from

    Oh well, it works... if it's not broken, don't fix it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  3. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  4. Multiplex Display with count comand
    By mdaweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th October 2005, 04:09
  5. Count command
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th September 2005, 19:04

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