Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
2,257 Views

Max 10 ADC with Nios II

I have a Max 10 Neek board, and I am trying to get ADC values into a basic NIOS II processor program (for instance, if the ADC reading is > something, turn on an LED). The board comes with a tutorial for directly using the ADC, and a simple hello world NIOS tutorial. I have worked through both of those, and I have found a tutorial for an Arrow board that addresses using the ADC with a NIOS processor at http://www.alterawiki.com/uploads/4/4d/5_adc_lab.pdf. I have tried applying the concepts from the Arrow tutorial to the Neek board.  

 

The problem I am having is once I start the ADC, it hangs. Running it in debug mode and stepping through, once I start the ADC, it keeps looping through the alt_irq_handler.c, and jumps to the alt_adc_irq. It appears to be clearing the interrupt, but it keeps jumping right back in. I have attached the code below. The program executes, printing out "Hello from Nios II!", then 1, 2, 3, 4, 5, but never gets to 6. It is stuck executing the line "adc_start(MODULAR_AD2C_0_SEQUENCER_CSR_BASE);"  

 

I have also attached a screenshot of my qSys connection diagram. This is new to me, so any help would be greatly appreciated. Thank you for your time!  

 

#include <stdio.h> # include "system.h" # include "altera_avalon_pio_regs.h" # include "alt_types.h" # include "altera_modular_adc.h" # include "altera_modular_adc_sample_store_regs.h" # include "altera_modular_adc_sequencer_regs.h" # include "sys/alt_irq.h" # include "sys/alt_alarm.h" int main() { printf("Hello from Nios II!\n"); int i; int loop_count; int led_output; float scale_factor; int line_in_binned; alt_u32 *adc_data; alt_u32 line_in_data; printf("1\n"); adc_stop(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); printf("2\n"); adc_interrupt_disable(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); // Disable interrupts. printf("3\n"); adc_clear_interrupt_status(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); printf("4\n"); adc_set_mode_run_continuously(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); printf("5\n"); adc_start(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); printf("6\n"); printf("*** Running ***\n\n"); for(loop_count=1;loop_count<100000; loop_count++) { alt_adc_word_read(MODULAR_AD2C_0_SEQUENCER_CSR_BASE, adc_data, MODULAR_ADC_0_SEQUENCER_CSR_CSD_LENGTH); line_in_data = adc_data; // Line in is CH 5, and in the sequencer, Slot 1 is CH5 scale_factor = ( (float)8 / ( (float)4096 - (float)1600 ) ); // create the scaling factor (8 LEDS, 12 bit range, minus ~1V offset) line_in_binned = (unsigned int)(scale_factor * (float)line_in_data); // Scale the data and convert to integer. This is the 'bin' of the current volume } printf("*** Stopping the ADC sequencer ***\n\n"); adc_stop(MODULAR_AD2C_0_SEQUENCER_CSR_BASE); }
0 Kudos
4 Replies
Altera_Forum
Honored Contributor I
190 Views

Hello, 

 

We also faced similar type of issue. Could you try following? 

 

In your Qsys system, just disconnect ADC's IRQ line connection to Nios II and check what happens. You have not written any interrupt routine. So, doing this should not affect you. Also check in reference designs. As per my knowledge, they have not connected IRQ line of ADC to Nios II. 

 

Regards, 

Bhaumik
Altera_Forum
Honored Contributor I
190 Views

Bhaumik, I shall try that. I gave up interfacing the ADC directly to the NIOS II through code, and fed the output of the ADC from one of the hardware-only examples directly into 12 I/O ports into the NIOS II. It's kind of a back-door way of doing it, but it works. It is just frustrating, the lack of examples on how to actually connect the dots in Qsys. That, and it was SOPC Builder, then it was Qsys for a little while, now it's Platform Designer, so there are bits and pieces of information scattered all over the place. A comprehensive "this is how you build things with Platform Designer, and here are all the little pitfalls" would be nice.

Altera_Forum
Honored Contributor I
190 Views

Platform Designer is just a renaming. There is no difference between it and Qsys (unless you're using the Quartus Pro edition, which you're not for MAX 10). If you want to learn all the "bits and pieces", check out these online trainings: 

 

https://www.altera.com/support/training/catalog.html?coursetype=online&keywords=qsys 

 

There's also training on the ADC: 

 

https://www.altera.com/support/training/catalog.html?coursetype=online&keywords=adc
Altera_Forum
Honored Contributor I
190 Views

 

--- Quote Start ---  

Bhaumik, I shall try that. I gave up interfacing the ADC directly to the NIOS II through code, and fed the output of the ADC from one of the hardware-only examples directly into 12 I/O ports into the NIOS II. It's kind of a back-door way of doing it, but it works. It is just frustrating, the lack of examples on how to actually connect the dots in Qsys. That, and it was SOPC Builder, then it was Qsys for a little while, now it's Platform Designer, so there are bits and pieces of information scattered all over the place. A comprehensive "this is how you build things with Platform Designer, and here are all the little pitfalls" would be nice. 

--- Quote End ---  

 

 

This is exactly the information i am also seeking. I have been contemplating a non Platform Designer/Qsys integrated ADC block, just as Joe641 has done, and was taking a last sweep before taking this route, after several days of research. Thanks for the confirmation that the approach works, Joe641. Thanks for the links, Bhaumik.