Jump to content

MrKev

Settled In
  • Posts

    397
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by MrKev

  1. On 12/1/2017 at 3:37 PM, TSD said:

    I think I finally have a general solution...

                                    tmpval = (RATE >> 4) & 0x0003
                                    signbit = RATE & 0x1000
                                    offset = RATE >> 12
                                    
                                    if signbit:
                                        checkword = ((((offset - tmpval) * 2) % 😎 + 0x05) << 4
                                    else:
                                        checkword = ((((offset + tmpval) * 2) % 😎 + 0x05)  << 4

    This could be a general solution in fixed width signed binary, but less obvious in a high level language.

    The speedo works over the range RATE = 2000 to 19542, so very possibly out to 32767, buts that's as far as I've tested. It would take another week to check all the values further up and I'm getting bored of the sound of the power relay clicking :rolleyes:

    I think I will try to write the R-Pi script and then call it done.

    assuming tmpval is "int"

    tmpval = (RATE / 16) & 0x8003    // preserving the sign bit, to save the if later on

    then no need for the "if" block, just have:

    checkword = ((((offset + tmpval) * 2) % 8 + 0x05)  << 4

    • Like 1
  2. On 7/5/2020 at 9:35 AM, doezel said:

    This is the relevant path; you want the complete VisualStudio Project?

            private void tbdesiredODO_changed(object sender, EventArgs e)
            {
                if (int.TryParse(tbDesiredODO.Text, out int desiredODO))
                {
                    int odoPart = desiredODO / 16;
                    int hexPart = 0xffff - odoPart;
                    List<int> hexArray = new List<int>();
                    for (int i = 0; i < 8; i++)
                        hexArray.Add(hexPart);
                    int remainder = (desiredODO - (odoPart * 16)) / 2;
                    for (int i = 0; i < remainder; i++)
                        hexArray--;
                    tbHex.Text = "";
                    for (int i = 0; i < 8; i++)
                        tbHex.Text += hexArray.ToString("X4") + " ";
                    lblStoredODO.Text = ((odoPart * 16) + (remainder * 2)).ToString();
                }
                else
                {
                    tbHex.Text = "?";
                    lblStoredODO.Text = "?";
                }
            }

    sorry I only just got round to replying.

    I would recommend uint (i.e. UInt16) rather than int to avoid complications with sign bits - not likely a problem till lots of miles though!

    Otherwise your code seems fine - and I think the problem is probably endianness in the programmer - as I thnk you've already spotted.

    I'm sure there must be a way to do this my mathematics rather than loops - but it has been a few years since I last looked, and I've not thought much about it in between.

     

    Glad it's of use to people anyway!

    Kevin

  3. Ok, i think its simpler to start with this: Take RATE, right shift 4 (/16), then logical AND with 0xFF, or 256 before wrapping the rest of the equation.

    I haven't got a piece of paper handy, to work out the rest at the moment!

    I think this will lead to a general rule for all rates, and satisfy the below 4096 case at the same time.

     

    Kev

  4. I'm kind of trying to get my brain switched back on to this, but it's been a while :)

    @TSD: I think you're basically right with the observation that -11 is the equivalent of +5.

    The /16 (or shift 4 places) does seem to tie up with the "4096" thing, as the top bit may become the sign/carry flag for an 8 bit micro: i.e. 4096 <<4 = 256 or 0 with carry.

    Kev

    • Like 1
  5. I've always understood this to be the case, but the introduction of computerised records 'instant' update meant that you now flagged as failed, whereas the old paper system meant it took time for anyone official to realise. I don't of course condone that philosophy as safe practice...

×
×
  • Create New...

Important Information

We use cookies to ensure you get the best experience. By using our website you agree to our Cookie Policy