• AVR Freaks

Hot!Adc Non DMA in dsPIC33EV256gm106 Alternative sampling issues.

New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2016/11/24 01:34:58
  • Location: 0
  • Status: offline
2019/09/06 05:27:44 (permalink)

Adc Non DMA in dsPIC33EV256gm106 Alternative sampling issues.

Hi everyone,
I am using dsPIC33EV256GM106. I am trying to read 10 bit Adc (4 channel each) in alternate selection ways in interrupt mode(PWM special event trigger). According to datasheet, Mux A is sampled one sweep and Mux B is sampled next sweep so on. MUX A and Mux B respective values are exactly fine but when Mux A is sampled Mux B buffers are filled with garbage values and Mux B is sampled Mux A buffers are filled with garbage value.  how to over come these problem.
void adcinit(){
AD1CON1 = 0x6C;
AD1CON2 = 0x305;  // 4 channel simultaneous sampling and smpi = 1;(every 2 interrupt)
AD1CON3 = 0x0;
AD1CHS0 = 0xE0B; // MuxA ch0+:AN11; Mux B ch0+: AN14; MuxA ch0- VREFL; MuxB ch0- VREFL;
AD1CSSH = 0x0;
AD1CSSL = 0x0;
AD1CON4 = 0x0;
AD1CHS123 = 0x8; // MuxA Ch1+=AN3,ch2+=AN0,Ch3+=OA3/AN6; Mux B Ch1+=AN0; ch2+ =AN1 ch3+ =An2
AD1CON1bits.ADON =1;
IEC0bits.AD1IE = 1;

void __attribute__ ( ( __interrupt__ , auto_psv ) ) _AD1Interrupt ( void )
IFS0bits.AD1IF = 0;

void adcReadBufData(){
while (!AD1CON1bits.DONE);
AD1CON1bits.DONE = 0;
PACurrent = ADC1BUF0; //AN11 - AN11/C1IN2-/U2CTS/FLT4/RC11
DCDCCurrent = ADC1BUF1; //AN3 
PAVoltage = ADC1BUF2; //AN0 - OA2OUT/AN0/C2IN4-/C4IN3-/RPI16/RA0
DCDCVoltage = ADC1BUF3; //AN6 - OA3OUT/AN6/C3IN4-/C4IN4-/C4IN1+/RP48/RC0
DCDCTemp = ADC1BUF4; // AN 14
PATemp = ADC1BUF5;

whether can we know which mux is going to sampled? Guys, please give your valuable suggestions.
thanks you.

1 Reply Related Threads

    Starting Member
    • Total Posts : 44
    • Reward points : 0
    • Joined: 2015/03/15 02:30:18
    • Location: Hungary
    • Status: offline
    Re: Adc Non DMA in dsPIC33EV256gm106 Alternative sampling issues. 2019/10/23 13:46:27 (permalink)
    I would check AD1CON2 value. If you sample 4 channels simultaneously you will have 4 conversation followed by. If you get the interrupt after 2 the data in the buffer will not be ready. Also after at the second interrupt you will have data still from MUXA.
    The correct value for the SMP bits is 0b00011.
    Also the AD1CON1bits.DONE bit will clear automatically at the end of the sampling. You find this bit high only because the conversation is not yet done. You don't need the while loop too.
    And there is a note from page 294:
    "Do not clear the DONE bit in software if auto-sample is enabled (ASAM = 1)."
    Which is your case.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5