Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12618 Discussions

How to read the Qsys ADC component data register in C directly

Honored Contributor II

I have a Qsys design with NIOS2 C program. The program will read the Altera ADC component of the Qsys system (Max10 on-chip ADC) as each data point becomes ready. The simplest scenario. No 'sample train' or sequencer required. Just check for new ADC value and read the value in the data register. I have the ADC configured in Qsys for dedicated input on ANIN, channel 0.  


Based on my understanding of a similar enquiry here in another thread, 

I am wondering if ADC read is as simple as 'knowing the ADC data register address to read from, and reading it using a pointer'.  


The pages I am reading look to suggest that, to read a Qsys IP register address, we can simply do the following: 


For example, let's say my ADC value register in Qsys is at mem location 0x5000. 


step 1: initialize a pointer to the data address of ADC register as - " int *adc_data = 0x5000; " 

step 2: Read data using - " ADC_value = adc_data[0]; " 


When I 'build' this is get a caution that "initialization makes pointer from integer without a cast [-Wint-conversion]". I'm not sure how to interpret the message, or my mistake, but it looks like I don't have it right yet.  


I'm hoping someone can help me understand the message in context, and provide a simple example if possible. 


0 Kudos
1 Reply
Honored Contributor II

UPDATE: On simplest reading of ADC value, when data is ready 


I was able to sort it out. It was indeed very simple in final analysis, but took days to sort as there seems to be few references on basic ADC read without sequencer and other ADC parameter controls. 


Here's is what i came up with, in case it will help the next person: 

# include "altera_modular_adc.h" 


int main() 








Int AD_value; 


while (1){ 


// check IRQ status and repeat until data ready 



// read data 



// reset IRQ data status bit flag for next sample 



} return 0;  


Perhaps someone with more experience can confirm this basic solution is OK as is when no sequencer and other ADC control is needed, but data values and sample rate are as expected. 



0 Kudos