Is there a faster way to compare?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    I have not tested the idea.

    Instead of writing each IF-THEN test to the port, writing to a variable and at the end that variable to the port will be faster?

    Ioannis

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,

    Have you considered using timer derived periodic interrupts and performing just one PWM "step" per interrupt? Perhaps spreading out 256 "steps" across the 8.333-msec period (8333-usecs/256 = 32.55-usec interrupts)?

    Here's another method like Darrel's which would work well if you group the outputs consecutively (B7..B3 or B4..B0 for example). Updating the port from a 'shadow' register allows precise bit update timing (multiple bits with same duty cycle value will update at exactly the same time).

    Regards, Mike

    Code:
    ;
    ;  1/256th step, 18 cycles (isochronous), active high output
    ;  on duty cycle match until end-of-period
    ;
            clrf    shadow          ; clear 'shadow'                  |B0
            movf    led+4,W         ; led[4] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[4] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+3,W         ; led[3] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[3] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+2,W         ; led[2] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[2] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+1,W         ; led[1] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[1] >= dcy               |B0
            rrf     shadow,F        ;                                 |B0
            movf    led+0,W         ; led[0] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[0] >= dcy               |B0
            rlf     shadow,W        ; W = led 'step' output           |B0
            movwf   PORTB           ; update LEDs                     |B0
            incf    dcy,F           ; bump duty cycle counter         |B0
    ;

  3. #3
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Thanks, Ioannis and Mike. Let me noodle with your suggestions for a bit.

    Meanwhile, for anyone interested:

    For an IF A [comparison] B THEN statement, without the appended action, the execution time at 8MHz if A and B are WORDs appears to be about 22-24us; if A and B are BYTEs, it appears to be about 5-6us. These numbers are not down to a gnat's whisker; they are as measured on my scope (Tektronix 465M).
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

Similar Threads

  1. How to compare strings/array? RFID Project
    By dan-tron in forum mel PIC BASIC Pro
    Replies: 100
    Last Post: - 10th April 2017, 08:21
  2. how to compare data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 1st November 2009, 23:30
  3. Compare Data
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th February 2008, 21:40
  4. 12F675 compare voltage help.
    By geckogrotto in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 2nd February 2007, 17:46
  5. OT - Firefox browser - faster performance
    By malc-c in forum Off Topic
    Replies: 2
    Last Post: - 14th August 2006, 11:33

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