Hello world :-) I am working on ESP32 (no FPU) and using Quadrature Encoder for motor control and range positioning. Current qencoder implementation stores counted values on int32_t so the maximum and minimum value is only around +/- 32k. I need far bigger numbers to be counted and available for readout quickly.
Long Story Short: 1. I would like to change representing counted values on a big floating number type with a sign, or just a bigger integer type. 2. I would like to ask what type would be best to represent floating numbers in NuttX in terms of portability and efficiency. Short Story Long: I am thinking of extending (configuration time option) Quadrature Encoder implementation so it would hold count number on a signed floating point like R.I where R would indicate full Round and I in the decimal part would indicate counted Impulses. That would enable counting large numbers independently of the used sensor in a single variable. Full round is usually indicated with additional signal line, or it could be counted using modulo of the decimal part with a given sensor resolution (i.e. 100 impulses per round, 1024 impulses per round, etc). This way integer part would indicate full rounds, while the decimal part would indicate actual counted impulses. For instance: 1. We have qencoder sensor with 100 impulses per Round, so initial value would be 0.0 and moving CW (clockwise) 0.0 -> .. -> 0.99 -> 1.0 -> .. 1.99 -> 2.0 -> etc. 2. We have qencoder sensor with 1024 impulses per Round, so initial value would be 0.0 and moving CCW (counterclockwise) 0.0 -> -0.1023 -> -1.0 -> .. -> -1.1023 -> -2.0 -> .. -> -2.1023 -> -3.0 -> etc. This way no matter what sensor is used the integer part of the readout will always indicate full round move of a wheel (both are in a single variable). And the number should be large enough to provide actual position. Does that make sense? Is this a good idea to extend qencoder module for this.. or that functionality should be implemented on the application level? Application level could be too slow to calculate this and it only task is to wait for a specific value and start / stop the motor, then perform other tasks. If this makes sense, then what variable type should be selected for storing counter value? What would be most portable and efficient? float (32bits)? double (64bits)? long double (80bits)? If this does not make sense and integer operations would be always simpler and faster, then what biggest integer type with a sign should I choose? :-) Any hints welcome :-) Tomek -- CeDeROM, SQ7MHZ, http://www.tomek.cedro.info