1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

most efficient way to perform ncd

Discussion in 'Oshonsoft' started by sheepdog, Oct 24, 2010.

  1. sheepdog

    sheepdog New Member

    Joined:
    Mar 14, 2008
    Messages:
    11
    Likes:
    0
    hi i require a fast way to check several sensors and obtain the highest value from them all, using the ncd command if it were available would be ideal for this. So i am thinking of rotating the bits of each value and checking if the bit is set then comparing the results. For speed i was going to code it in assembly.
    Do you think this method would be the best way forward, or would xoring the values etc be more expedient.
    many thanks
     
  2. ot1

    ot1 New Member

    Joined:
    Oct 24, 2010
    Messages:
    9
    Likes:
    1
    Hi Sheepdog,

    You don't specify how you obtain sensor data, so I am only able to generalize, but doing it in Basic, I don't think you will notice much difference in speed vs. ASM with this compiler. But the simulator will tell you how many clock cycles it takes for "data polling", so you can compare methods.

    Dim i as byte
    Dim highval as long
    Const maxsensors = 4

    Exec:
    For i = 0 to maxsensors
    gosub pollsensor

    Next i

    'do other stuff here

    goto exec
    end

    pollsensor:
    'maybe use i to point to sensor port
    If iportdata > highval then highval = iportdata
    'highval will now contain the highest data value read from a sensor

    return
     
    Last edited: Oct 24, 2010
  3. sheepdog

    sheepdog New Member

    Joined:
    Mar 14, 2008
    Messages:
    11
    Likes:
    0
    thanks for the reply, the data is sampled via numerous adc`s then each averaged, i was going along the ncd route as it also gave me the highest value of a magnitude of 2 or more over the next highest reading which would then be acted upon, if less than 2 no action needs to be taken.
    many thanks
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE

    What is ncd?

    Mike.
     
  6. sheepdog

    sheepdog New Member

    Joined:
    Mar 14, 2008
    Messages:
    11
    Likes:
    0
    Hi Mike, ncd returns the highest bit of a byte, ncd %01111110 would return 7. Useful if you have say 2 light sensors and only want to move position if one result is higher than the other i.e each bit is double the magnitude of the previous bit.
     
  7. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,568
    Likes:
    128
    Location:
    Caribbean
    I don't quite understand.
    You want to sort the adc values from highest to lowest?

    Or you want to know which ADC values have the highest order bit set, this won't tell u very much as many can have bit7 set from value 128 thru 255.

    The bit 7 u mention above is a 0, when counting bits 7,6,5,4,3,2,1,0. It's not set so I am confused as to what you want.
     
  8. sheepdog

    sheepdog New Member

    Joined:
    Mar 14, 2008
    Messages:
    11
    Likes:
    0
    Hi, the number returned relates to the bit number but plus 1 to cater for a no bit set which returns zero. Most basic compilers have the function, easily enabling large differences to be detected, and acted upon say via a select case. I managed to achieve the same by decreasing the w reg by 1,rlf the file reg and waiting for the status.c flag then exiting.
    Cheers
     
    Last edited: Oct 27, 2010
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    ONLINE
    Do they really count 1 to 8 rather than 0 to 7?

    Mike.
     
  10. sheepdog

    sheepdog New Member

    Joined:
    Mar 14, 2008
    Messages:
    11
    Likes:
    0
    has to be that way to cater for no bit being set, 8 to 1 leaves zero if the byte = 0, if it was 7 to 0 then if ncd returned 0 you would not know if the byte was 0 or bit 0 was set
     
    Last edited: Oct 27, 2010

Share This Page