Community
cancel
Showing results for 
Search instead for 
Did you mean: 
jamie_m
Beginner
66 Views

ADC timing on MAX 10

Hello,

I am trying to read 9 values via the Nios ADC interface and running into some timing issues. Below is the pseudocode for the routine plus the specific API call:

// Configure and start the ADC
adc_stop(ADC_SEQUENCER_CSR_BASE); // ADC must be stopped to change the mode
adc_interrupt_disable(ADC_SEQUENCER_CSR_BASE); // Disable interrupts.
adc_clear_interrupt_status(ADC_SEQUENCER_CSR_BASE);
adc_set_mode_run_continuously(ADC_SEQUENCER_CSR_BASE);
adc_start(ADC_SEQUENCER_CSR_BASE);

while(1) {
 
   // Read ADC values
   alt_adc_word_read(ADC_SAMPLE_STORE_CSR_BASE, adc_data, ADC_SEQUENCER_CSR_CSD_LENGTH);
   curr_48 = adc_data[0];
   curr_24 = adc_data[1];
   volt_48 = adc_data[2];
   volt_24 = adc_data[3];
   volt_6 = adc_data[4];
   volt_5 = adc_data[5];
   ind_temp = adc_data[6];
   pmic_temp = adc_data[7];
   tsd = adc_data[8];
 
/* Do the rest of the state machine here */
 
} // end while(1)
 
Further below are timing diagrams of two test cases. In each shot, I pull the I/O high when I start the loop and then pull it low when I get back to the beginning of the loop again. I have outlined the loop timing with cursors.
 
In the first picture, the ADC code above is running. In the second picture, it has been commented out. Note that the ADC is still initialized in the same way, I'm just commenting out the call to alt_adc_word_read() and the subsequent assignments to local variables. As you can see, the loop timing for reading nine values is nearly double when the ADC read is in the loop. This indicates to me that the ADC is probably blocking while all conversions complete before returning the values. 
 
My two questions are the following:
1) Why does the ADC take so long and/or is there a way to check to see if a conversion is complete so that I can only grab values that are immediately available? Another way to state this is to ask if my assumption that the ADC blocks upon calling alt_adc_word_read() is valid, and if not, what is happening to cause this delay?
2) I have been exploring using the DMA to transfer the completed conversions to an array rather than access the ADC directly. I've gone through the documentation for the DMA Controller IP but found it lacking. Can anyone point me to (or provide) a good example of how to hook up a DMA to an ADC in Platform Designer and how to initialize it in the Nios code?
 
Thanks,
Jamie
 
Figure 1 - ADC in the loop
NewFile2.png
 
Figure 2 - ADC code commented out
NewFile1.png

 

0 Kudos
3 Replies
JonWay_C_Intel
Employee
54 Views

I would suggest that you try the Design Store Example Design as a reference and work from there: https://fpgacloud.intel.com/devstore/platform/16.0.0/Standard/adc-data-capture-with-nios-ii-processo...

There are other examples that you may find useful: https://fpgacloud.intel.com/devstore/platform/?search=nios&ip_core=ADC&acds_version=any&family=max-1...

 

jamie_m
Beginner
45 Views

Thanks. I just checked the Design Store and I see several examples for using the ADC, but none of them seem to include a DMA. In fact, it is not explicitly apparent from the descriptions that any of these include an example of DMA transfer from the ADC to memory. Can you please point me to a specific example for that?

Thanks,

Jamie

JonWay_C_Intel
Employee
31 Views

Take a look at this how-to video in implementing a scatter gather dma with NIOS, and see if you can combine that with NIOS with ADC.

https://www.youtube.com/watch?v=iaRkjkpMBH8