• AVR Freaks

Hot!PIC32MZ - Can't get ADC to work

Author
Radical Redemption
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/03/10 14:14:32
  • Location: 0
  • Status: offline
2019/05/25 06:21:07 (permalink)
0

PIC32MZ - Can't get ADC to work

//DMA Init
    DCH1CONSET = 0x3;
    
    DCH1SSA = KVA_TO_PA(buffer);
    DCH1DSA = KVA_TO_PA(&ADCDATA2); r
    DCH1SSIZ = 512;
    DCH1CSIZ = 2;
    DCH1DSIZ = 2;
    
    DCH1ECON = 0;
    DCH1ECONbits.CHSIRQ = _ADC_DATA2_VECTOR;
    DCH1ECONbits.SIRQEN = 1;
    
    IFS4CLR = _IFS4_DMA1IF_MASK;
    
    IPC33bits.DMA1IP = 3;
    IPC33bits.DMA1IS = 1;
    
    IEC4SET = _IEC4_DMA1IE_MASK;
    
    DCH1INTbits.CHBCIE = 1;
    
    DCH1CONbits.CHEN = 1;
   
 
    //ADC Init
    ADC0CFG = DEVADC0;
    ADC1CFG = DEVADC1;
    ADC2CFG = DEVADC2;
    ADC3CFG = DEVADC3;
    ADC4CFG = DEVADC4;
    ADC7CFG = DEVADC7;
   
    ADCCON1 = 0;
    ADCCON1bits.FSSCLKEN = 1;
   
    ADCCON2 = 0;
  
    ADCANCON = 0;
    ADCANCONbits.WKUPCLKCNT = 9;
   
    ADCCON3 = 0;
    ADCCON3bits.ADCSEL = 1;
    ADCCON3bits.CONCLKDIV = 1;
    ADCCON3bits.VREFSEL = 0;
    
    ADC2TIMEbits.ADCDIV = 1;
    ADC2TIMEbits.SAMC = 1;
    ADC2TIMEbits.SELRES = 3;
   
    ADCTRGMODEbits.SH2ALT = 0;
   
    ADCIMCON1bits.SIGN2 = 0;
    ADCIMCON1bits.DIFF2 = 0;
   
    ADCGIRQEN1 = 0;
    ADCGIRQEN2 = 0;
    
    ADCGIRQEN1bits.AGIEN2 = 1;
   
    ADCCSS1 = 0;
    ADCCSS2 = 0;
   
    ADCCMPCON1 = 0;
    ADCCMPCON2 = 0;
    ADCCMPCON3 = 0;
    ADCCMPCON4 = 0;
    ADCCMPCON5 = 0;
    ADCCMPCON6 = 0;
   
    ADCFLTR1 = 0;
    ADCFLTR2 = 0;
    ADCFLTR3 = 0;
    ADCFLTR4 = 0;
    ADCFLTR5 = 0;
    ADCFLTR6 = 0;
   
    ADCTRGSNSbits.LVL2 = 0;
    ADCTRG1bits.TRGSRC2 = 5;
   
    ADCEIEN1 = 0;
    ADCEIEN2 = 0;
   
    ADCCON1bits.ON = 1;
   
    while(!ADCCON2bits.BGVRRDY);
    while(ADCCON2bits.REFFLT);
   
    ADCANCONbits.ANEN2 = 1;
   
    while(!ADCANCONbits.WKRDY2);

    ADCCON3bits.DIGEN2 = 1;
    
    ADCDATA2;
 
    T1CON = 0x0;
    
    TMR1 = 0x0;
    PR1 = 0x8;

 
DMA fills buffer with zeroes only.
 
The buffer used is declared as follows:
 
uint16 __attribute__((coherent, aligned(16))) buffer[256] = {0};

post edited by Radical Redemption - 2019/06/05 06:00:59
#1

1 Reply Related Threads

    Radical Redemption
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/03/10 14:14:32
    • Location: 0
    • Status: offline
    Re: PIC32MZ2048EFH100-250I - Can't get ADC to work using DMA 2019/05/25 13:42:06 (permalink)
    4 (1)
    DMA code was wrong, here is the one that works now:
      //DMA Init
        DCH1CON = 0x0;
        DCH1CONSET = 0x2;
        
        DCH1SSA = KVA_TO_PA(&ADCDATA2);
        DCH1DSA = KVA_TO_PA(buffer);
        DCH1SSIZ = 2;
        DCH1CSIZ = 2;
        DCH1DSIZ = sizeof(buffer);
        
        DCH1ECON = 0;
        DCH1ECONbits.CHSIRQ = _ADC_DATA2_VECTOR;
        DCH1ECONbits.SIRQEN = 1;
        
        IFS4CLR = _IFS4_DMA1IF_MASK;
        
        IPC33bits.DMA1IP = 3;
        IPC33bits.DMA1IS = 1;
        
        IEC4SET = _IEC4_DMA1IE_MASK;
        
        DCH1INTbits.CHBCIE = 1;
        
        DCH1CONbits.CHEN = 1;

     
    post edited by Radical Redemption - 2019/06/05 05:59:41
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5