Bits and Bytes

AB&CRRone Apr 10, 2007

  1. AB&CRRone

    AB&CRRone TrainBoard Supporter

    1,700
    1
    28
    I have no understanding of bits and bytes referred to in decoder manuals. Is an understanding really necessary? Usually, after going into long and detailed programming requirements, referring to bit this or bit that, the manuals list the CV programming possiblities in a table along with the CV value needed. Am I missing something?

    Ben
     
  2. aluesch

    aluesch TrainBoard Member

    74
    0
    18
    Not really, although it never hurts to know how things work ;-)
    What you need to know is that the bits are numbered from right to left so you can identify them. Also some manufacturer number the 8 bits from 1 – 8, some others stick to the proper bit numbers 0-7. In any case, once the bit is recognized that you want to change you simply add/subtract the value given in the decoder manual to turn a function on or off.
    If the manual doesn’t use bit numbers but rather just values for certain functions, you don’t need to know any of the above. Some cabs, such as the ZIMO, also display the bits on screen and you simply toggle the appropriate number key to turn the bit on or off (i.e. press the #4 key to change bit #4, the cab does the calculation).
    The trend is to get away from bits and bytes all together or use incremental programming as was recently introduced in the large-scale ZIMO sound decoders.

    Regards,

    Art
    ZIMO Agency of North America
    www.mrsonline.net
     
  3. Phil Olmsted

    Phil Olmsted TrainBoard Member

    317
    1
    14
    And, a byte is 8 bits.
     
  4. Mike Sheridan

    Mike Sheridan TrainBoard Member

    1,763
    0
    33
    Some systems (NCE for sure, but I think some others are catching up) shield you from this altogether for all normal programming. It just asks you (in English) whether you want that operation on or off, or whatever, and you choose. The system then sorts out the bits in the bytes or words.

    As a controls engineer I'm currently building an application that has to set/decode bits in a double word = 32 bits long. You can imagine how big some of the numbers get :( . I have resorted to doing the math once, so to speak, by putting the required numbers in variables named for the operation that bit relates to, so I can program in English (well, it's called structured text, but you can 'read' it :) )
     
  5. Mark Smith

    Mark Smith TrainBoard Member

    306
    9
    18
    Pretty much my Digitrax 400 throttle takes care of the bits and bytes. All I have to put in is the correct decimal numbers in the various CVs. Of course you need to know what they are. The problem might be that a decoder supplier only gives you the bits needed, not the decimal value. Then you'd like to understand what they are talking about and how to use their information.

    So it's partly a matter of the features on the DCC equipment you have as well.
     
  6. AB&CRRone

    AB&CRRone TrainBoard Supporter

    1,700
    1
    28
    Art, Phil, Mike and Mark,

    Thanks, these comments help. I'm using Digitrax Zephyr and have mostly used Digitrax decoders. Recently I encountered a Soundtraxx decoder and things got a little more complicated. At least the manual helped me to arrive at the proper decimal value. And the manual has a "Basics of Programming" section that I only scanned. I see now that I need to study the section in greater depth.

    Thanks again,
    Ben
     
  7. swdw

    swdw TrainBoard Member

    108
    1
    14
    You working with PLC's, Delta V, or some other applicatoin?

    Ben,

    You might want to look into the JMRI interface software. It's an open source program that allows you to program decoders in real words and regular numbers. Depending on the DCC system, you can hook up directly for programming, or you may need to purchase an interface like a SPROG.

    Here's the link for the software:
    http://jmri.sourceforge.net/

    Decoder pro is the portion for decoder programming.
     
  8. Mike Sheridan

    Mike Sheridan TrainBoard Member

    1,763
    0
    33
    Sorry Ben, didn't realize you were already trapped in a system :)
    Yes, sorting out the bits for more complex decoders can be a chore.

    I have a number of SoundTraxx decoders myself and when I bought them (a few years ago now) I received a "SoundTraxx DCC CV Slide Rule". I don't know whether it came with one of the decoders or from Tony's Train Exch who I got them from, but it's quite useful and converts any 8-bit binary string into the equivalent decimal and hex numbers (or vice-versa). It also has other info about CV setting printed on it, but I'd normally check the manual too as some things may vary a bit with the model. I expect other companies make similar things, so may be worth trying to get one.

    SWDW,
    "You working with PLC's, Delta V, or some other applicatoin?" Basically yes, but Delta V is the competition :)
    I'm making some library modules to interface from Profibus connected switchgear into ABB 800xA DCS systems.
     
  9. jlbos83

    jlbos83 TrainBoard Member

    336
    8
    19
    I'll go a bit more techie, just to describe why 0-7 is proper, and whoever dreamed up 1-8 was not an engineer (in my opinion). When you start the numbers at zero, the value of each bit set to a one is 2 raised to that power. So, if bit 2 is set, the value is 4. That makes it quick and easy to figure out the values, especially as you get to 16 bit words and such.

    That said, as has been mentioned, DCC systems are getting farther away from this every day, and that's a good thing. I think the user interface is still the weak link in DCC, and because the actual functions of bits and CVs in decoders is not (and probably should not) be totally standardized, it is going to be a tough nut to crack. Hence being at least a tiny bit (oops!) binary competent is a good thing.

    Jeff
     
  10. dstuard

    dstuard TrainBoard Member

    981
    1
    20
    Computers (and thus decoders and command statiions) work on bits, which taken 8 at a time are called bytes. You don't need to speak Japanese to drive a Toyota, and you don't (or shouldn't) need to speak buinary to program a decoder.

    It does help to know a little about the lingo, and knowing how some of the CV values (particularly CV29) are constructed makes the mystery of CVs easier to crack.

    Just remember, in decimal the columns in addition represent 1's, 10's, 100's, etc, while in binary they represent 1's, 2's, 4's, 8's etc. A 3 digit decimal number of 327 is 300+20+7=327, while an 8-bit byte of binary 11111111 in decimal is 128+64+32+16+8+4+2+1=255 decimal.

    Fun with numbers!

    Doug
     
  11. Mike Sheridan

    Mike Sheridan TrainBoard Member

    1,763
    0
    33
    Exactly.

    Eg. It wouldn't be hard to make a CV input screen on the command station that you choose Value or Bit entry. Value is then set same as now, but if Bit is chosen you then enter the bit to be set and if it is to be 0 or 1. The user should never have to work out decimal/hex values for the whole CV because that means he has to check/set seven other settings that he probably isn't interested in just now.

    OK, the 0-7/1-8 thing is still an issue, but that is like having a diesel or petrol Toyota - 99% of the time it works just the same and most people can handle the slight difference when plugging into it :)
     
  12. AB&CRRone

    AB&CRRone TrainBoard Supporter

    1,700
    1
    28

    Considering the above, here is where I become confused:

    The manual for the decoder (Soundtraxx Tsunami) with which I am working gives these instructions in the section Preset Speed Tables: "CV25 is used to select which speed curve will be used.."
    Then
    "In order for the speed table selection in CV25 to take effect, bit 4 of CV29 must be set to 1."

    My confusion comes from why, and who determines, that bit 4 of CV29 must be set to 1? Then, if you will walk me through the computation to arrive at the actual decimal to use maybe it will help me see it more clearly.

    Thanks,
    Ben
     
  13. jlbos83

    jlbos83 TrainBoard Member

    336
    8
    19
    OK, here we go....
    This link http://www.nmra.org/standards/DCC/standards_rps/rp922.html is the NMRA's 'Recommended Practice' for CV's and what they mean. (I'm not sure how it is just recommended, since anyone who didn't follow it is just asking to be incompatible, but that's a different discussion.
    There is a table a little way down listing all of the available CVs and what they contain. Some are madatory, some optional, some reserved for manufacturers (to put in unique stuff), etc. Following that is a text description of what each controls, and through which bits. So, looking at CV 29, bit 4 (the fifth bit), which has a value of 16 (2 to the fourth power), determines whether the speed table is set by CVs 2,5,and 6, or by CV 25. This is also in Soundtraxx's Tsumnami Technical Reference, it is easier to read there, I think. So, if you want to use CV 25 to select the speed table you make sure that CV 29 bit 4 is set. Now is the tricky bit, depending on how your DCC system shows you the values in a CV, and where a good user interface can make a big difference. I don't have enough experience with any system to know which do what, but I can generalize. Ideally, there would just be a little box to check, or something along that line, to choose this. Then it is easy. If you see the CV in HEX notation it may look a bit scary, but it is really easier than decimal. Hex translates to bits like this:

    Hex number / bits / Decimal
    0 / 0000 / 0
    1 / 0001 / 1
    2 / 0010 / 2
    3 / 0011 / 3
    4 / 0100 / 4
    5 / 0101 / 5
    6 / 0110 / 6
    7 / 0111 / 7
    8 / 1000 / 8
    9 / 1001 / 9
    A / 1010 / 10
    B / 1011 / 11
    C / 1100 / 12
    D / 1101 / 13
    E / 1110 / 14
    F / 1111 / 15

    Since an 8 bit bit is represented by two hex digits, you just string them back to back and you can see the bits, right in the open. Decimal is harder, because if you don't know if a bit is set or not, it is a lot harder to just look at the number and see. Here a decimal to binary calculator is handy. And the calculator in windows can do it for you. It's under accessories, if you haven't used it. Select the scentific view, and you'll see selections for Hex, Decimal, Octal (Base 8, if you care) and binary. Select what you have, enter the number, and select what you want.

    Let's do an example, then. Let's say you want to set bit 4 to a one, but you don't know what is currently is. You read the CV, and it has a value of 231 Decimal (just making this up, I don't know if that is a real possibility, but it doesn't matter). Stick 231 into the calculator (with decimal selected), then select binary. It is 11100110. Bit four is not set. So, we need to add 16 to the CV, making it 247, and we're done.

    I think I'll stop now and see if this makes any sense, rather than confusing anyone further!

    Jeff
     
  14. AB&CRRone

    AB&CRRone TrainBoard Supporter

    1,700
    1
    28

    Jeff,

    Good! Let me study what you have presented so far.

    I did do a read of CV29 which was value 2, even read it several times and each time it was 2. Reset factory defaults, read CV 29, and still 2. I was expecting a larger number. But in any event I did the calculation entering 2 with decimal selected, then selected binary and the calculation was 10. At least I can do the calculation. After I study more I may even know what the calculation means.

    I'll owe you big, this a lot of work on your part. As well as that of the others.

    Ben
     
  15. jlbos83

    jlbos83 TrainBoard Member

    336
    8
    19
    I'm happy to do it.

    Anyway, if it is a 2 and you want to set bit 4, it turns into 18, or 00010010 binary (see bit four set?), or 12 hex.

    Have a look at CV 29 in this document: http://soundtraxx.com/documents/manuals/tsutechreference.pdf
    and you can see what the 2 means (and why nothing else is set).

    Jeff
     

Share This Page