I have a hall encoder that can communicate its reading with a PWM. However, I'm having issues with accessing its full resolution, since the sensor is hardcoded with a PWM frequency of 1 kHz (+-10%) and has a resolution of 12 bits, meaning the wave width is between 3.8 and 998, with increments of 0.24 usec.
I'm using pulseIn to read the width of the signal. It's currently working, but the function return microseconds under the form of an unsigned long, rounding down every reading while doing so.
Are Arduino's even capable of acquiring such a fast signal? If yes, would there be a "pulseIn_short", or any solution easier than soldering tiny wire onto a tssop 14 chips with a cheap imported soldering iron and using SPI/I2C?
Get an adapter board to solder the chip on and connect wires or headers to the wide spaced pads. Then use SPI with the 'A' version or I2C with the 'B' version.
I already have a board with the required component to make a functional circuit. If you use the amazon link, you can see it. Using the pwm would be easy, but the rest of the pinout does not have a lot of surface area to solder onto.
There might be problems calling PulseIn from within a print statement? May be better to wait for the pulse measurement, then print it? I believe pulseln is a blocking function. Which Arduino are you using? I've had problems with PulseIn on the Due, I went back to a Uno. Also i think the answer it gives you has a granularity of 4 microseconds.
Because the pcb the chip is soldered on doesn't allow a lot of space for soldering a connection to the SPI/I2C/Serial. After measuring the board, the 8 thin soldering area are only 0.75mm wide are separated by only 0.3mm.
If there is an edge connector with those dimension, it would probably solve the issue, but I'd like to find a software solution for the sake of learning.
That sound promising! However, I looked at the entirety of the "chapter" 15 and didn't find anything about the acquisition speed. Are you aware if this method would be able to digitalize the duty cycle within a precision of 0.25 usec (about the minimal increment of this chip output)?
If the PWM is constant, unrelated-unsynchronized to the processor, and you have "all day" you can take, say 1000, readings and then find the average. For example, at 50% PWM you'd expect about 500 high readings (and you don't need to count the low readings). It's probably better (more "random" and uncorrelated) the more slowly you read.
Or you can make a low-pass filter to get an analog-average and read the analog.
Unfortunately, the code must be fast since I'm trying to control a mechanism and I'd rather have the loop run as fast as possible. With a single pulseIn, I'm already at 3 ms just to get my angle.