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

Modular ADC - MAX10

Hello,  

 

I`m currently trying to make the ADC of a MAX10 board work but I can`t seem to get my interruption correctly. 

 

I could configure the modular ADC to the sequence mode with NIOS correctly, but the interruption turned out to be a big hassle in my life. 

 

 

The code below is my int, which I try to initiate the interruption with the API "altera_modular_adc_init" and I try to set up the API "alt_adc_register_callback" (Which doesn't make sense to me... Why do we need it?). Also, I put a "alt_adc_word_read" afterwards cause when I enter the while loop my code does not go to the ISR, which was supposed to go (as I wished). The ISR declaration is static void alt_ic_isr(void* context, alt_u32 id)

 

int main(void){ //Shown at the GUI that the program has started printf("*** The ADC has started ***\n"); alt_u32 *adc_data_ptr; alt_u32 line_in_data; printf("*** Configure and start the sample_store config ***\n"); void* edge_capture_ptr = (void*) &edge_capture; altera_modular_adc_init(edge_capture_ptr, MODULAR_ADC_SAMPLE_STORE_CSR_IRQ_INTERRUPT_CONTROLLER_ID, MODULAR_ADC_SAMPLE_STORE_CSR_IRQ ); /* Arguments: * - *dev: Pointer to adc device (instance) structure. * - callback: Pointer to callback routine to execute at interrupt level - *context: Pointer to adc device structure. * - sample_store_base: Base address of the sample store micro core. * */ alt_adc_callback adc_callback_ptr; alt_modular_adc_dev* devIRQ; devIRQ=altera_modular_adc_open (MODULAR_ADC_SAMPLE_STORE_CSR_NAME); alt_adc_register_callback( devIRQ, adc_callback_ptr, edge_capture_ptr, MODULAR_ADC_SAMPLE_STORE_CSR_BASE ); alt_adc_word_read (MODULAR_ADC_SAMPLE_STORE_CSR_BASE, adc_data_ptr, MODULAR_ADC_SAMPLE_STORE_CSR_CSD_LENGTH); int adcSampleStorageIRQStatus=10; int adcInterruptAsserted=10; printf("*** All enabled ***\n"); while(1){ adcSampleStorageIRQStatus=READ_ALTERA_MODULAR_ADC_SAMPLE_STORAGE_IRQ_STATUS(MODULAR_ADC_SAMPLE_STORE_CSR_BASE); printf("IRQ Status: %d\n",adcSampleStorageIRQStatus); adcInterruptAsserted=adc_interrupt_asserted(MODULAR_ADC_SAMPLE_STORE_CSR_BASE); printf("Interrupt Asserted?: %d\n",adcInterruptAsserted); } return 0; }  

 

I've tried to do many different things, use different drivers and I just didn't get any result. Someone could help me out? Thanks!
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
194 Views

Greetings,  

 

I am not sure if this is still an issue for you but I'm posting my code in the hopes it helps you or someone else. 

 

This code is targeting the MAX 10 development kit for Quartus Prime 16.1. This code uses the ADC IRQ and callback function to signal the main code that the ADC has captured valid data. 

 

/* * "ADC oneshot irq" example. * * This code will setup the ADC interrupt and start the ADC to run once. After the ADC * captures the data and fills the sample_store memory, the IRQ fires. This code grabs * the ADC data and dumps it to the terminal. * */ # include <stdio.h> # include "system.h" # include "altera_avalon_pio_regs.h" # include "altera_modular_adc.h" # define POLL_ADC_RUN while (IORD_ALTERA_MODULAR_ADC_SEQUENCER_CMD_REG(MODULAR_ADC_0_SEQUENCER_CSR_BASE) & ALTERA_MODULAR_ADC_SEQUENCER_CMD_RUN_MSK); //GLOBAL alt_u8 adc_callback_occurred; void my_adc_callback (void *context) { adc_callback_occurred = 1; adc_interrupt_disable(MODULAR_ADC_0_SAMPLE_STORE_CSR_BASE); // sits at offset 0x40 } int main() { alt_u32 adc_data; int n; alt_modular_adc_dev my_adc, *p_my_adc; p_my_adc = &my_adc; //clear the receive buffer to ensure we are capturing ADC data for(n=0;n<10;n++) adc_data = 0xDEADBEEF; printf("Hello from the ADC oneshot IRQ test program!\n"); // write a pattern out to the leds IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,~0x0F); printf("System ID: %08X\n",SYSID_ID); printf("Timestamp: %08X\n",SYSID_TIMESTAMP); // Open the ADC using the sequencer csr name, not the sample_store csr name p_my_adc = altera_modular_adc_open(MODULAR_ADC_0_SEQUENCER_CSR_NAME); //register the adc callback function alt_adc_register_callback ( p_my_adc, my_adc_callback, NULL, MODULAR_ADC_0_SAMPLE_STORE_CSR_BASE); printf("\nInitializing and starting the ADC\n"); adc_set_mode_run_once(MODULAR_ADC_0_SEQUENCER_CSR_BASE); adc_interrupt_enable(MODULAR_ADC_0_SAMPLE_STORE_CSR_BASE); adc_start(MODULAR_ADC_0_SEQUENCER_CSR_BASE); adc_callback_occurred = 0; // wait until adc irq has completed while(adc_callback_occurred==0); alt_adc_word_read(MODULAR_ADC_0_SAMPLE_STORE_CSR_BASE, adc_data, MODULAR_ADC_0_SAMPLE_STORE_CSR_CSD_LENGTH ); // MODULAR_ADC_0_SAMPLE_STORE_CSR_CSD_LENGTH = 10 for(n=0;n<10;n++) printf("adc_data = 0x%08X\n",n,adc_data); // stop the ADC when finished. adc_stop(MODULAR_ADC_0_SEQUENCER_CSR_BASE); return 0; }  

 

Kind regards, 

-Terry
Reply