Chapter 8. Analog Inputs
There are eight analog inputs on the Mojo, accessible though the 10-pin connector. However, FPGAs don’t usually have any analog circuitry built in. Because of this, these analog inputs are from the microcontroller on the Mojo. After the microcontroller does its job of programming the FPGA, it becomes a USB-to-serial converter as well as an analog-to-digital converter (ADC).
In this tutorial, we are going to read the analog inputs and use their values to vary the brightness of the eight LEDs on the Mojo.
The AVR Interface
We’ve used the AVR Interface component before, in Chapter 6. However, this time we are going to use the ADC portion of it instead of the serial portion. The ADC on the AVR takes a voltage input in the range of 0–3.3 V and converts it to a number from 0–1,023 (a 10-bit value). As before, we will start by creating a new project based on the AVR Interface example project.
If you take a look at the avr_interface
module, there are four signals we care about when trying to read the analog inputs:
// ADC Interface Signals input channel[4], // ADC channel to read from, use hF to disable ADC output new_sample, // new ADC sample flag output sample[10], // ADC sample data output sample_channel[4], // channel of the new sample
You’ll probably notice that only one of these is an input. That means the value we have to worry about providing is channel
, which is the number of the input we want to read. If you look at your Mojo, there are eight analog ...
Get Learning FPGAs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.