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


Results 1 to 7 of 7

Threaded View

  1. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

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

    some thoughts, in my experience decoding quadrature signals that way usually miscounts when small back forward movements and or freq direction
    changes occur. plus you only get a quarter of the possible resolution , edge detection on both channels is a better method
    i might add your method will be intolerant to any noise [contact bounce] too
    you could try these ideas and maybe tweak a little more speed.

    PORTB = counter && 255 is not really correct , && is a logical AND you need a BITWISE AND
    PORTB = counter & 255
    or
    PORTB = counter.lowbyte
    or since its an 8bit chip
    PORTB = counter , would do but may get a warning about low byte value being used

    since the count can only inc/dec by 1 count you can simplify to this

    if pin_B = 1 then counter = counter + 1
    if pin_B = 0 then counter = counter - 1
    if counter.15 then counter = 359
    if counter > 359 then counter = 0

    bit9 can be simplified to this

    bit9=counter.8


    making

    Code:
    if pin_B = 1 then counter = counter + 1
    if pin_B = 0 then counter = counter - 1
    if counter.15 then counter = 359
    if counter > 359 then counter = 0
    bit9=counter.8
    PORTB = counter.lowbyte
    Last edited by richard; - 10th January 2021 at 02:54.
    Warning I'm not a teacher

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