How to implement function analogRead() on Arty

I want to implement function analogRead(). I don’t know how to start. Please give me some suggestion or some reference material. Thanks !

If you’re experienced with FPGAs and Verilog then you might want to look at the Arty documentation on how to use its built in ADC.

Otherwise you’ll probably find in far easier to get an external I2C or SPI ADC chip and talk to it using GPIO. For example:


There’s a lot of information here, most of which will apply to the E300 just as much as to an AVR-based Arduino https://learn.adafruit.com/adafruit-4-channel-adc-breakouts

1 Like

I understand two suggestions you gave.But I still have some doubts about the first suggestion.

I use https://github.com/sifive/freedom and create .mcs file, then programmed onto Arty FPGA board.

  1. I don’t find the ADC related code in freedom. Is there implement ADC?

  2. If there no ADC and I want to implement analogRead(), do I need to add ADC IP module in freedom?

I mean Digilent’s Arty documentation and examples. For example:

https://reference.digilentinc.com/reference/programmable-logic/arty/reference-manual

You’d have to find some way to interface that to the E300. Maybe the converted analogue value could appear as a port in the memory map. Maybe you’d need to make a TileLink adaptor for it. I don’t know – I’m not experienced with FPGA programming. If you are not as well then I suggest you follow my second suggestion.

There is no ADC code in freedom because we don’t have ADC hardware on our chips, and so have not supported the ADC features on the Arty.

1 Like

Thanks a lot, I understand it.

If I use the second method, I will use I2C interface, In FE310-G000 datasheet, just have GPIO PWM SPI UART, not I2C related information, is there any other I2C reference?

I2C is easy to implement with GPIO pins in software. The standard Arduino “Wire” library does this.

https://playground.arduino.cc/Main/WireLibraryDetailedReference

1 Like

Thanks!

In Freedom E300, there is I2C module, I want to implement I2C interface by hardware instead of with GPIO pins in software. Is there any manual like GPIO, UART,etc in Freedom E310-G000 Manul