Make PIC simulate binary up/down counter - how to calculate how fast can it count?


Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Jan 2007
    Posts
    78

    Default Make PIC simulate binary up/down counter - how to calculate how fast can it count?

    Hello All,
    I have a theoretical question about guesstimating how fast an input signal a PIC can track.

    I'd like to experiment with an 18pin PIC - such as the PIC6F627A
    I'd like to simulate a binary up/down counter
    But this counter will keep track of degrees - with a max value of 359
    Which means it needs to role over when > 359 and role over when < 0

    The input signal to track will be a standard A/B encoder signal requiring 2 input pins.
    The output will be PORTB's 8 pins, and one pin from PORTA to function as 9th bit.
    9 bits can hold our expected values.

    The PIC will be running with internal oscillator at 4mhz
    Is there a way I can guesstimate how fast an encoder pulse the PIC will be able to accurately track?
    Thanks in advance! :-]
    dw


    A description of the process follows:

    PORTA will have 2 input pins with alias names = Pin_A, Pin_B
    PORTA will have 1 output pin with alias name = bit9
    PORTB will have 8 output pins

    main:

    'Here we remain in a loop until Pin_A clock input goes high
    while pin_A = 0
    wend

    'We are now here because pin_A clock input went high starting a clock cycle
    '------------------------------------------------------------------------

    if pin_B = 1 then counter = counter + 1
    if pin_B = 0 then counter = counter - 1
    if counter > 359 then counter = counter - 360
    if counter < 0 then counter = counter + 360
    if counter > 255 then HIGH bit9 else LOW bit9
    PORTB = counter && 255

    'We now wait for pin_A clock input to go LOW
    'In order to be ready for its next clock cycle
    '---------------------------------------------
    while pin_A = 1
    wend

    'we are now here because pin_A has gone LOW and is now ready for its next cycle
    'Start over and get pin_A next clock cycle

    goto main
    Last edited by dw_picbasic; - 9th January 2021 at 20:04.

Similar Threads

  1. Replies: 7
    Last Post: - 19th December 2016, 17:19
  2. Use a PIC ADC like a fast interrupt comparator?
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th August 2011, 05:33
  3. Fast yet reliable PIC-PIC communication?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th September 2009, 15:34
  4. How to calculate PIC sampling frequency
    By minmin in forum General
    Replies: 1
    Last Post: - 26th September 2006, 18:02
  5. Simulate a mouse with a PIC
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st September 2006, 00:13

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