The wages of sin is debugging.
Ron Jeffries
I have demonstrated that it is possible to use an ESP32 both as an infrared transmitter and receiver, and I mentioned that the IR receiver I used decoded the carrier wave. In today’s post I shall show you how I discovered that fact using a Digilent Analog Discovery 2 (AD 2). The AD 2 is a device I love and I strongly recommend to any hobbyist experimenting with microcontrollers. It is a multi-functional test tool based around an FPGA into which several different profiles may be downloaded. From the Digilent docs:
- Two-channel USB digital oscilloscope (1 MΩ, ±25 V, differential, 14-bit, 100 MS/s, 30 MHz+*)
- Two-channel arbitrary waveform generator (±5 V, 14-bit, 100 MS/s, 12 MHz+ bandwidth*)
- 16-channel digital logic analyzer (3.3 V CMOS and 1.8 V or 5 V tolerant, 100 MS/s)
- 16-channel pattern generator (3.3 V CMOS, 100 MS/s)
- 16-channel virtual digital I/O including buttons, switches, displays, and LEDs, which is perfect for logic training applications
- Two input/output digital trigger signals for linking multiple instruments or providing an external trigger source
- Two channel voltmeter
- Network Analyzer with Bode, Nyquist, Nichols transfer diagrams of a circuit. The Network Analyzer has a range of 1 Hz to 10 MHz
- Spectrum Analyzer capable of power spectrum and spectral measurements (noise floor, SFDR, SNR, THD, etc.)
- Data Logger with exportable data and plot functionality
- Impedance Analyzer for analyzing capacitive and inductive elements
- Curve Tracer to analyze characteristics of discrete semiconductors such as diodes and transistors
- Protocol Analyzer with SPI, I2C, CAN, AVR, and UART
- Two programmable power supplies (0.5 V to 5 V , -0.5 V to -5 V). The maximum available output current and power depend on the Analog Discovery 2 powering choice.
- Stereo audio amplifier to drive external headphones or speakers with replicated Arbitrary Waveform Generator signals
- An available Software Development Kit for programming with Python and C++, and a toolkit for programming with LabVIEW.
- MATLAB support for the Data Acquisition Toolbox
Wow! That’s a lot of capability in a tiny box.
In order for us to use one, first we need to download the WaveForms software from Digilent. Next, plug in the Analog Discovery 2 Logic Analyzer cable. This is the rainbow cable with many leads terminated in .1″ female connectors. Having connected that to the Analog Discovery 2 (it only goes in one way up) we will connect three of these leads: GND to GND on the breadboard, DATA–0 to the IR TX pin, and DATA-1 to the IR RX pin.
In this picture, DATA-0 is pink, DATA-1 is green and GND is black. Orange, red and brown are the connections from the ESP32 to the IR RX, and the remaining black lead is ground to the TX. Next, we need to connect the AD 2 to the host computer via USB, and then check that it is recognized. I like the small utility USBView for this:
Note that is shows up as “USB Serial Converter”. It is connected, so we can switch to WaveForms and select the device in the WaveForms Settings/Device Manager:
Here we are selecting the 4th configuration for the AD 2 device, although we could use configuration 3 to get more sample buffer space if we were using the scope. Since we are going to use the Logic Analyzer, we’re using a profile which has that configured with 16 x 16K sample buffers.
Next, we select the Logic Analyzer tool in WaveForms, and add our two signal lines:
Here we have added the two lines – DATA-0 (DIO 0) and DATA-1 (DIO 1), and named them according to the function to which each is connected.
Next, set the mode to “Record” and start the recording.
Having run the recorder, you should see a result like:
Here we can see the transmit signal on the top line, and slightly behind it on the lower line the receive signal. Note that the transmit signal seems to be a solid block, whilst the received signal is a normal looking active low pulse train. (Note that the sense of the signal is reverse from active high on the transmit signal to active low on the receive signal – more useful information from the AD 2!)
If we zoom in a bit on the signals, we can see why this is the case:
Our transmit signal is not a single, solid block as it appears in the first screenshot, but is a series of short pulses. We have discovered our carrier wave! We can also see that it takes a number of pulses for our IR receiver to lock onto the carrier wave and recognize a pulse has started. We can also see that the receiver pulse train is missing the carrier wave as the IR receiver has decoded the pulses from the carrier wave and removed it. Problem diagnosed!