Counting led blinks..


Closed Thread
Results 1 to 40 of 93

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    FYI, the missing % is a new Code Box forum feature...
    Steve

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

  2. #2
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi,
    I searched in the forum and found a peice of code by Bruce...
    Code:
    DEFINE LCD_DREG PORTBDEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    PAUSE 100
    
    
    TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
    TRISB.0 = 0 ' RB0 = output for LED
    CMCON = 7   ' All digital
    
    
    i var byte
    i=0
    ' Assign prescaler to WDT for 1:1 prescale on TMR0
    ' TMR0 clock will be from your external input on RA4/T0CKI
    ' Increment on high-to-low transitions
     OPTION_REG = 111000
     
    ' If you prefer, then increment on low-to-high transitions
    ' OPTION_REG = 101000
    Lcdout $fe, 128, "Counter: ", #i 
    pause 100
    Main:
        TMR0 = 0     ' Clear TMR0 count before start
        
    Loop1:
        WHILE TMR0 = 0 ' Wait for high-to-low transition
        WEND           ' on RA4/T0CKI
        PORTB.0 = 1    ' LED on to indicate transition seen 
        i=i+1       ' Increment
        Lcdout $fe, 128, "Counter: ", #i   
        PAUSE 200
        PORTB.0 = 0    ' LED off
        GOTO Main      ' Start over
        END
    Everytime I press RA.4 it toggle RB0, I also put a variable that will display the value to the LCD, from the code I observed (please correct me if I wrong).
    a. Timer0 is selected
    b. The signal entry is RA.4
    c. It increments on low-to-high transitions
    d. Pre scale value is 1:2 (000 of Bits 2,1)
    d. The configuration setting used OPTION_REG = 111000

    So if connect the multi coin acceptor to the RA.4 this should count the number of pulse?

    thanks in advance,
    tacbanon
    Last edited by tacbanon; - 1st October 2011 at 07:01.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi,
    Yes, that would work. I'd probably add a little pause directly after the WHILE-WEND loop to allow the coin acceptor to push out all the pulses before the code reads the timer.

    As for the prescaler, yes, the bits indicate a a 1:2 ratio but since bit 3 is set the prescaler isn't assigned to TMR0 but to the WDT so you get a 1:1 ratio which is what you want in this case.

    Steve,
    Thanks for the heads-up on the % character, great feature... Must try/verify:
    Code:
    This is a test, percent char %00110011
    This is a test, no percent char 00110011
    And here's how my post looks in preview:

    Name:  Preview.jpg
Views: 2116
Size:  28.2 KB
    Looks fine in the preview. (Appologies to tachbanon for trying this here).
    EDIT: And in the final post, I don't see a problem... Is it when there's a = infront?
    Code:
    OPTION_REG = %00110011
    Again, looks fine in the preview.
    EDIT: And in the final post.

    /Henrik.
    Last edited by HenrikOlsson; - 1st October 2011 at 08:13.

  4. #4
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, now I'm trying to incorporate the coin acceptor, but I observered that when I connect PULSE line to RA4..it continues to count, even if the device is turned off or if I touched the wire. Please see the attachment, I'm using easypic6. What do you think causing it?


    regards,
    tacbanon
    Attached Images Attached Images  

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi,
    Try adding a pullup or pulldown resistor on the input.

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    I tried both using the built in switch to enabled Pull up/down.. no changes.
    Please see attach image, I'm using the blue wire.
    thanks,
    tacbanon
    Attached Images Attached Images  

  7. #7
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, I finally got it right, what was missing was the GND. Thanks Henrik for the help, my next target is to run the codes on PIC18F4550..hope it wont be a problem.

    regards,
    tacbanon

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