Tachometer Rollover

General topics and discussions about the VESC and its development.
Posts: 2
Joined: 04 May 2017, 18:01
Location: Oregon

Tachometer Rollover

Postby Atrer » 04 May 2017, 18:03

Is there a way to reset the Tachometer values using UART? I'm using the difference of two tachometer values to see how far I have traveled, but I'm concerned about a rollover.

Posts: 904
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Tachometer Rollover

Postby rew » 05 May 2017, 15:01

When you have two signed or unsigned integers, and you do:

Code: Select all

  signed int diff;

  diff = newvalue - oldvalue;

That difference value will be correct EVEN when a rollover happens. This is true independent of if the rollover happens at 0x7fffffff - 0x80000000 for signed, or at 0xffffffff - 0x0 for unsigned ints.

If you don't believe me write a program that tests this for a smaller datatype, like a char.

Code: Select all

  // unsigned
  char a, b;
  int aa, bb, wanteddiff;

  for (aa = 0 ; aa < 256;aa++)
      for (wanteddiff = -10; wanteddiff < 10;wanteddiff++) {
          bb = aa + wanteddiff;
          a = aa;
          b = bb;
          // insert code from above here.
          if (diff != wanteddiff ) printf ("aa = %d, bb=%d, a = %d, b=%d, wd = %d, d=%d.\n",
             aa, bb, a, b, wanteddiff, diff);
A modern computer should test all 5120 possibilities in less than a millisecond.

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests