counter for counting magnetic microswich press


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Location
    Ankara -Turkey
    Posts
    27

    Default counter for counting magnetic microswich press

    Hi Everyone.
    I want to count microswich open-close positon to count disk rotation.
    ı have a micro magnetic swich which is produce 2 signal when maghnetic disc rotating 1 time.magnetic swich debounce time is 20 uSec.
    I use Pic16F877
    This is my code:

    ..PORTA.4 input pin...
    ........
    ..........
    loopHy:
    IF PORTA.4 = 0 THEN loopHy
    count = count+50
    Lcdout $fe, $C0, #count:Pause 250(debounce time for slow rotation)
    goto loopHy
    ........

    is it Ok .or anybody give me advise.
    Thanks.
    Last edited by turkuaz; - 16th June 2007 at 10:55.

  2. #2
    Join Date
    Mar 2006
    Location
    Ankara -Turkey
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by turkuaz View Post
    Hi Everyone.
    I want to count microswich open-close positon to count disk rotation.
    ı have a micro magnetic swich which is produce 2 signal when maghnetic disc rotating 1 time.magnetic swich debounce time is 20 uSec.
    I use Pic16F877
    This is my code:

    ..PORTA.4 input pin...
    ........
    ..........
    loopHy:
    IF PORTA.4 = 0 THEN loopHy
    count = count+1
    Lcdout $fe, $C0, #count:Pause 250(debounce time for slow rotation)
    goto loopHy
    ........

    is it Ok .or anybody give me advise.
    Thanks.
    I solve this problem myself as follows:
    .............
    loopHy:
    IF PORTA.4 = 0 THEN loopHy
    count = count+1
    While portA.4=1 Then
    Lcdout $fe, $C0, #count
    Wend
    goto loopHy
    .............................
    It is working nice
    thanks everyone.

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


    Did you find this post helpful? Yes | No

    Default

    Carefull when you use reserved word... COUNT is also a PBP statement. You should change it to something else

    Now JUST FOR FUN, and as your current hardware is setuped to use it, try this one which use TMR0
    Code:
            ADCON1 = 7
            pCount    VAR BYTE
            OldpCount VAR BYTE
            CLEAR
            TMR0 = 0
            OLDPCOUNT = 1
    Start:
            pCount = TMR0
            IF pCount != OldpCount then
                LCDOUT $FE,$C0, #pCount
                OldpCount = pCount
                ENDIF
            GOTO Start
    Last edited by mister_e; - 17th June 2007 at 22:22.
    Steve

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

  4. #4
    Join Date
    Mar 2006
    Location
    Ankara -Turkey
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Carefull when you use reserved word... COUNT is also a PBP statement. You should change it to something else

    Now JUST FOR FUN, and as your current hardware is setuped to use it, try this one which use TMR0
    Code:
            ADCON1 = 7
            pCount    VAR BYTE
            OldpCount VAR BYTE
            CLEAR
            TMR0 = 0
            OLDPCOUNT = 1
    Start:
            pCount = TMR0
            IF pCount != OldpCount then
                LCDOUT $FE,$C0, #pCount
                OldpCount = pCount
                ENDIF
            GOTO Start
    Thanks for your advice.
    I chanced count to sayim(in Turkish)
    I do not want to use timer because when disk begin to rotation ( which is slow rotation)micro magnet take to time to pass under the magnetic swich so swich is on position and count is going to count I do not this. I want only one time not elong with passing is going on.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question Some more info, please

    Hi Turkuaz,

    Could you tell us what's your MAX RPM ( or half freq ...) counting rate expected ???

    Will help for a solution.

    I think we could detect only the Low-to-High ( or High-to-Low ) transitions, to get rid of the rotation speed span.

    But the debouncing time must fit the max RPM !!!

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

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. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 05:02
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. How to set TMRO & TMR3 as Counter?.
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th May 2007, 08:52
  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 : 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