Forum Discussion
Ahmed_H_Intel1
Frequent Contributor
7 years agoBTW, The DE0 nano SOC has a SPI connection with ADC on board, use the following example to understand how to use the SPI ADC.
I have created this example before, not officially released
Here is the main code to read from the ADC (DE0_Nano_SoC)
/*
* "ADC" example.
*
* This example gets the data of the ADC and convert it to digital to implement on LEDs
* Developer: Embedded guy
* Nov 2018
* DE0 Nano SoC
*/
#include <stdio.h>
#include "system.h"
#include "altera_up_avalon_adc_regs.h"
#include "altera_up_avalon_adc.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
alt_up_adc_dev * ADC_DEV;
unsigned int ADC_DATA=1;
int main()
{
printf("Starting \n");
//Enable ADC auto update
alt_up_adc_auto_enable(ADC_DEV);
//Open the ADC device
ADC_DEV= alt_up_adc_open_dev("/dev/adc_0");
if (ADC_DEV==NULL){
printf("Cannot open ADC");
}
while (1){
unsigned ch=0;
ADC_DATA = alt_up_adc_read(ADC_DEV,ch);
printf("ADC data of CH0= %d \n",ADC_DATA);
int delay=0;
while (delay<5000000){
delay++;
}
}
return 0;
}Please feel free to ask for support if needed.
Regards.