Altera_Forum
Honored Contributor
8 years agoMax 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);
}