Hi,
I have not yet received my Lidar-Lite V3 but have studying the data sheet. My application is collision avoidance on a rover using Arduinio Mega. My initial intention is to use PWM, mostly because it seems simpler and doesn’t require use of yet another library. My question is regarding receiver bias correction. Will it occur periodically or repeatedly during PWM measurements?
In order to avoid the blocking of pulseIn, I intend to use pin change interrupts to sense the front and the back of the pulses and calculate my own timing. My assumption is that if the trigger pin is set Low, constantly triggering measurements, it will change to high at pulse beginning and then return to low at end of the pulse, thus triggering another measurement. This baffles me a bit since the Mega is using two pins (one held low), and the Lidar unit is using a single pin for all this.
One worry is that if measurements are being triggered constantly, the interrupt routines will be busy too often and I won’t get control back to do anything else. I suppose I could manage the triggering myself with a timer interrupt. Your thoughts?
Please find below answers to your questions/comments (in-line):
The LIDAR-Lite v3 performs bias correction on every measurement, by default. This can be turned off (and back on again) using I2C commands. Using only the PWM mode, there is no way to configure the device while in use since this interface is read-only.
As you can see in the instructions (right side of page 3), there is a resistor between the trigger pin (output) of the microcontroller and the monitor pin (input)/LIDAR-Lite connection. There is also more details on the operation of the control pin on )Mode Control Pin. As explained there, the wiring of the series resistor is what allows the use of only one pin on the LIDAR-Lite side, which is an input pin by default (high-Z) and changes to an output pin when it is returning the measurement. It then returns to an input pin to sample again until it finds a low signal. The resistor in series with the microcontroller output pin is to prevent two bus drivers to fight each other (bus contention). You could also simply wire the output pin to LOW/GND, which should provide you with continuous measurements, or as said in the instructions:
A simple solution is to only trigger the sensor at the beginning of a state machine, where you would typically take into local buffers the state of your inputs (i.e.: a “snapshot” of all relevant inputs) so they can be processed. Another option would indeed be to use a timer interrupt to trigger the output at a certain fixed rate. This interrupt would also setup whatever code/interrupts/etc. needed to receive the reading. If you feel like being clever, you can possibly do this with just one timer interrupt and pin (changing it between input and output)!
Please note you could possibly also count the frequency of the signal (when constantly held low) using the AVR hardware. You can review the ATmega2560 datasheet (pages 140-142) for details on using ICP hardware features (Input Capture). Specifically, the time stamps provided by the hardware can “…] then be used to calculate frequency, duty-cycle, and other features of the signal applied”, which would possibly work with the “variable frequency” signal provided by the LIDAR-Lite if held in constant measurement mode. Please note that we did not try this, so we are unsure if it would work, but it certainly sounds like a good way to get a value out of the signal.
I first got my Lidar Lite V3 going with PWM using pulseIn. I’ve never liked pulseIn though because nothing else can happen while it waits for the end of the pulse. I switched to using a pin change interrupt (change) to measure the pulse and it worked great. I didn’t measure the frequency at which the pulses come, but it’s probably about the same as RC pulses (~400hz), not so fast as to overwhelm the Arduino sketch with interrupts. This was all done holding the trigger pin low (for “constant” measurements).
I did try pulling the trigger pin low based on a timer interrupt. That was not successful. So anyway, it’s working fine now.