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