Shop OBEX P1 Docs P2 Docs Learn Events
Ncd operator — Parallax Forums

Ncd operator

ArchiverArchiver Posts: 46,084
edited 2003-11-08 18:53 in General Discussion
Hi all
Trying to use and do the impossible I think part of program below I think I have
total gone na na

HOW CAN I MAKE AN ARRAY Byte size but in relation to a word.
Tracy has stuff on his web that I have read and kind of understand but is it
allowed and or possible to do below

'{$STAMP BS2}
CHKLV VAR W1

CHK VAR Byte(20)

BEGINNING:
STARTB:
PULSIN 0,1, CHKLV 'wait for right pulse above 0 below 4
'IF CHKLV> = 0 AND CHKLV< =4 THEN STARTB
PULSIN 0,1, CHK(NCD(0)) ' capture a wordsized increasing or decreasing
value 0 - 3000 in Pulsin value debug to a PC screen through a looping pulsin
word size program

REPEAT PULSINS DOWN TO

PULSIN 0,1, CHK(NCD(19))
do MATH stuff here with results then back to beginning

Thanks

Rob
This email is confidential and may also be privilege.
If you are not the intended recipient, please notify us immediately.
You should not copy or use it for any purpose, nor disclose it's contents to any
other person.

[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-08 18:53
    Hmmmm. If you could explain a little more where these pulses are
    coming from, maybe we could provide more useful help. I'll put some
    comments in your code...


    >Hi all
    >Trying to use and do the impossible I think part of program below I
    >think I have total gone na na
    >
    >HOW CAN I MAKE AN ARRAY Byte size but in relation to a word.
    >Tracy has stuff on his web that I have read and kind of understand
    >but is it allowed and or possible to do below
    >
    >'{$STAMP BS2}
    >CHKLV VAR W1
    >
    >CHK VAR Byte(20)
    >
    >BEGINNING:
    >STARTB:
    >PULSIN 0,1, CHKLV 'wait for right pulse above 0 below 4
    >'IF CHKLV> = 0 AND CHKLV< =4 THEN STARTB

    If you de-comment that if, you will come here for all pulses >4.
    It could be written, "IF CHKLV <5 THEN STARTB". The Stamp IF
    statement considers all numbers positive, so there is no need to test
    for >=0.

    >PULSIN 0,1, CHK(NCD(0)) ' capture a wordsized increasing or
    >decreasing value 0 - 3000 in Pulsin value debug to a PC screen
    >through a looping pulsin word size program

    This statement will always put the value in array element CHK(0).
    The value of NCD (0) is a constant, always zero.

    >
    >REPEAT PULSINS DOWN TO
    >
    >PULSIN 0,1, CHK(NCD(19))

    Here is a table of NCD X versus X:
    X NCD X
    0 0
    1 1
    2 2
    3 2
    4 3
    5 3
    6 3
    7 3
    8 4
    9 4
    10 4
    11 4
    12 4
    13 4
    14 4
    15 4
    16 5
    17 5
    18 5
    19 5
    Does that help you understand how NCD works? If you want to capture
    the word value and put the "compressed" value in your array, you
    would do something like the following:

    FOR I=0 to 19
    PULSIN 0,1,x
    IF x>4 THEN
    y=NCD x MIN 1 -1 ' this is a value from 0--15
    y=y<<4+((x - DCD y)>>(y MIN 4 - 4)) ' bitlog value from 0-255
    CHK(I) = y ' put bitlog x into array
    ENDIF
    NEXT
    ' do processing here

    For example, if the pulse value is x=3000, then the value put into
    the array will be 183. That corresponds to a log base 2 value of
    183/16 = 11.44 compared to the true value log2(3000)=11.551

    -- Tracy Allen
    http://www.emesystems.com






    >do MATH stuff here with results then back to beginning
    >
    >Thanks
    >
    >Rob
Sign In or Register to comment.