Why not just use exact width types everywhere.
https://en.wikibooks.org/wiki/C_Programming/stdint.h#Exact-width_integer_types

Am Sa., 25. Apr. 2020 um 18:53 Uhr schrieb andy pugh <[email protected]>:

> On Sat, 25 Apr 2020 at 16:18, Jon Elson <[email protected]> wrote:
>
> > OK, so there's two parts.  One is to handle the sign
> > extension/rollover of the 24-bit hardware encoder
> > to 32-bits.  What I'm seeing so far (on 2.7.14) is that that
> > IS working.  But, then the 32-bit value
> > is placed into a presumably 64-bit signed integer, while the
> > upper 32-bits are allowed to
> > stay at zero.  So, minus numbers don't work.
>
> Yes. On amd64 it seems that a "long" is 8 bytes, and the the Union in
> ppmc.c line 1080 assumes 4 bytes.
>
> So, swapping "long" for "int32_t" should make it work like it used to.
>
> The next question is whether you would prefer to store counts as 64
> bits to be sure that nobody wraps an encoder while this universe
> exists.
> (the other encoder counters all use 64 bit accumulators)
>
> I worked out a way to do encoder wrapping for arbitrary bit-lengths
> for the Mesa smart-serial (which has 8-bit mpg counts but potentially
> much longer ones too)
>
> https://github.com/LinuxCNC/linuxcnc/blob/master/src/hal/drivers/mesa-hostmot2/sserial.c#L2067
> Ignore the index-enable code after line 2079, that is emulated index,
> just in case)
>
> Basically the N-bit buffer is sign-extended to be a signed int (in
> this case a 64-bit buffer is used, but any signed int that arithmetic
> works for would do.) and then the difference between the current value
> and the old value of the N-bit buffer is added to the 64-bit
> accumulator.
>
> There is a bit in the middle where, if the old and new differ by more
> than 2^(N-1) then a wrap is assumed, and 2^N is added or subtracted,
> to account for wrap)
>
> But, the real point is that by tracking the cycle-by-cycle delta
> counts and adding that to the 64-but buffer, you don't need to do any
> fancy bit-jiggling to store the result in a 64-bit (or 128 bit)
> buffer.
>
> --
> atp
> "A motorcycle is a bicycle with a pandemonium attachment and is
> designed for the especial use of mechanical geniuses, daredevils and
> lunatics."
> — George Fitch, Atlanta Constitution Newspaper, 1912
>
>
> _______________________________________________
> Emc-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/emc-developers
>

_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to