Shop OBEX P1 Docs P2 Docs Learn Events
Count Fonction — Parallax Forums

Count Fonction

ArchiverArchiver Posts: 46,084
edited 2004-05-12 16:26 in General Discussion
Hi every body,

Is there a way to get real time count using the Count format, Because
I need to count pulse from rotary encoder then serial out to visual
basic prog. Some one can be give some tip about.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-05-12 00:16
    --- In basicstamps@yahoogroups.com, "vermettechristian"
    <christian_vermette@v...> wrote:
    > Hi every body,
    >
    > Is there a way to get real time count using the Count format,
    Because
    > I need to count pulse from rotary encoder then serial out to visual
    > basic prog. Some one can be give some tip about.


    Christian,

    Attached is a bit of code to read an encoder. It will
    track which direction the encoder is turning and will run
    up to 50 Hz if you can keep the program short.

    ' {$stamp bs2}

    ' Program to act as high speed quadrature counter


    ' Program Name: quadhicount.bs2
    ' Last Update: Mar 10/01 tjs

    DIRH=%11111111

    counter VAR Word
    counter2 VAR Word
    counter3 VAR Word
    old VAR Nib
    new VAR Nib
    direct VAR Byte

    ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    quad:
    counter=127 'load a dummy value so can count up or down
    new = INB & %0011 ' get initial condition

    start:
    old = new & %0011 ' remember initial setting

    again:
    new = INB & %0011 ' get new reading
    IF new=old THEN again
    direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit
    of old to get direction
    IF direct=1 THEN cw ' jump here to increment
    LOW 0 ' pin 0 turns led off if turning counter-
    clockwise
    counter=counter-1 ' jump here to decrement
    OUTH=counter.LOWBYTE
    GOTO start

    cw:
    HIGH 0 ' pin 0 turns on led if turning clockwise
    counter=counter+1
    OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch
    count
    GOTO start



    Cheers,

    Tom Sisk
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-12 01:17
    Thank you Tom
    for your quick response, but I am not able to run the program you given me,
    I have signal going to pin 6 and 7 (Channel A and B) and signal is clean I
    already place an Schmitt trigger, led on pin 8 doesn't go on even the way I
    turn the motor.

    Can you give me more in

    Regards,

    Christian

    Original Message
    From: stamptrol [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=88IpXPd8U31CwLKzQxEE8usTTJDiJDaRdEbV3WMNSiROjMIkIN4BXcWmZw8HsMjK5naJEsSx7wVfCfLC1EtpdQ]sisk1404@n...[/url
    Sent: 11 mai, 2004 19:16
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: Count Fonction

    --- In basicstamps@yahoogroups.com, "vermettechristian"
    <christian_vermette@v...> wrote:
    > Hi every body,
    >
    > Is there a way to get real time count using the Count format,
    Because
    > I need to count pulse from rotary encoder then serial out to visual
    > basic prog. Some one can be give some tip about.


    Christian,

    Attached is a bit of code to read an encoder. It will
    track which direction the encoder is turning and will run
    up to 50 Hz if you can keep the program short.

    ' {$stamp bs2}

    ' Program to act as high speed quadrature counter


    ' Program Name: quadhicount.bs2
    ' Last Update: Mar 10/01 tjs

    DIRH=%11111111

    counter VAR Word
    counter2 VAR Word
    counter3 VAR Word
    old VAR Nib
    new VAR Nib
    direct VAR Byte

    ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    quad:
    counter=127 'load a dummy value so can count up or down
    new = INB & %0011 ' get initial condition

    start:
    old = new & %0011 ' remember initial setting

    again:
    new = INB & %0011 ' get new reading
    IF new=old THEN again
    direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit
    of old to get direction
    IF direct=1 THEN cw ' jump here to increment
    LOW 0 ' pin 0 turns led off if turning counter-
    clockwise
    counter=counter-1 ' jump here to decrement
    OUTH=counter.LOWBYTE
    GOTO start

    cw:
    HIGH 0 ' pin 0 turns on led if turning clockwise
    counter=counter+1
    OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch
    count
    GOTO start



    Cheers,

    Tom Sisk



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.679 / Virus Database: 441 - Release Date: 04-05-07
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-12 16:26
    Hi everyone,
    I am looking for a way to read pulse from rotary encoder, at this time I use
    the program below, but I have problem it only decrease the value even if the
    motor turning CW or CCW. Some one have some tips for me.


    ' {$stamp bs2}
    '{$PORT COM1}


    DIRH = %11111111

    counter VAR Word
    counter2 VAR Word
    counter3 VAR Word
    old VAR nib
    new VAR Nib
    directn VAR Byte

    ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    quad:
    counter = 125 'load a dummy value so can count up or down
    new = INB & %0011 ' get initial condition

    start:
    old = new & %0011 ' remember initial setting
    Again:
    new = INB & %0011 ' get new reading
    IF new = old THEN again
    directn = new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit of
    old to get direction
    IF directn = 1 THEN CW ' jump here to increment
    LOW 0 ' pin 0 turns led off if turning
    counter-clockwise
    counter = (counter+1) ' jump here to decrement
    OUTH = counter
    DEBUG DEC counter,cr
    GOTO again

    CW:
    HIGH 0 ' pin 0 turns on led if turning clockwise
    counter = (counter-1)
    OUTH = counter 'turn on leds on pins 8 through 15 to watch
    DEBUG DEC counter,CR
    GOTO start

    Thank you

    Christian

    Original Message
    From: Christian Vermette [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=O9namEkaxjT0YFVDQJMsdLTwYcjs5GEXMXVhoYquiK48LUt7JVoVask9yeYnbY6E1hjQvszne2D0fC_ORy7k_LH4KVDTEQ]christian_vermette@v...[/url
    Sent: 11 mai, 2004 20:17
    To: basicstamps@yahoogroups.com
    Subject: RE: [noparse][[/noparse]basicstamps] Re: Count Fonction

    Thank you Tom
    for your quick response, but I am not able to run the program you given me,
    I have signal going to pin 6 and 7 (Channel A and B) and signal is clean I
    already place an Schmitt trigger, led on pin 8 doesn't go on even the way I
    turn the motor.

    Can you give me more in

    Regards,

    Christian

    Original Message
    From: stamptrol [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=kRS180G_NI5J4RiIqxrbagFC4fi-PB-S6LnMavykzACM9Y-pINrvl_yUSTiCvGShZo52b6HRW2SzVVO-l-v6ZlAqOA]sisk1404@n...[/url
    Sent: 11 mai, 2004 19:16
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: Count Fonction

    --- In basicstamps@yahoogroups.com, "vermettechristian"
    <christian_vermette@v...> wrote:
    > Hi every body,
    >
    > Is there a way to get real time count using the Count format,
    Because
    > I need to count pulse from rotary encoder then serial out to visual
    > basic prog. Some one can be give some tip about.


    Christian,

    Attached is a bit of code to read an encoder. It will
    track which direction the encoder is turning and will run
    up to 50 Hz if you can keep the program short.

    ' {$stamp bs2}

    ' Program to act as high speed quadrature counter


    ' Program Name: quadhicount.bs2
    ' Last Update: Mar 10/01 tjs

    DIRH=%11111111

    counter VAR Word
    counter2 VAR Word
    counter3 VAR Word
    old VAR Nib
    new VAR Nib
    direct VAR Byte

    ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    quad:
    counter=127 'load a dummy value so can count up or down
    new = INB & %0011 ' get initial condition

    start:
    old = new & %0011 ' remember initial setting

    again:
    new = INB & %0011 ' get new reading
    IF new=old THEN again
    direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit
    of old to get direction
    IF direct=1 THEN cw ' jump here to increment
    LOW 0 ' pin 0 turns led off if turning counter-
    clockwise
    counter=counter-1 ' jump here to decrement
    OUTH=counter.LOWBYTE
    GOTO start

    cw:
    HIGH 0 ' pin 0 turns on led if turning clockwise
    counter=counter+1
    OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch
    count
    GOTO start



    Cheers,

    Tom Sisk



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.679 / Virus Database: 441 - Release Date: 04-05-07





    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.679 / Virus Database: 441 - Release Date: 04-05-07
Sign In or Register to comment.