• AVR Freaks

Hot!dsPIC33E ADC Accuracy Problem

Page: 12 > Showing page 1 of 2
Author
thepcman
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2016/11/16 23:32:30
  • Location: 0
  • Status: offline
2019/12/11 05:31:21 (permalink)
0

dsPIC33E ADC Accuracy Problem

Hello,
 
I have a problem with 4 channel simultaneous sampling ADC on DSPIC33EP512MC806 running at 59 MIPS. AN3 AN4 AN5 are connected to current sense amplifier buffered by op-amp and connected to ADC pin via 100ohm/100nF filter (tried 1kohm/1nF filter as well). Each channel output signal is similar in amplitude in operation. AVDD is fed from 3.3V supply via 390nH/1u LC filter (tried zero ohm alternatively). Vref+ is fed from REF2033 (tried changing Vref to Avdd)
 
However CH2 and CH3 readings are of by almost half; i.e. while CH1 is measuring 3.3 Amps peak, CH3 is measuring 1.6 Amps peak. This behavior is similar over whole range.
 
Tried reducing ADC clock, increasing sample time (although auto sample is enabled)
 
My configuration code is below, any suggestions?
 

 
PLLFBD=57;
CLKDIVbits.PLLPOST=0;
CLKDIVbits.PLLPRE=0;
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(0x01);
while(OSCCONbits.COSC != 0b011);
while(OSCCONbits.LOCK != 1);
 
 
 
AD2CON1bits.ADON=0;
AD2CON1bits.ADSIDL=0;
AD2CON1bits.ADDMABM=0;

AD2CON1bits.FORM=3;
AD2CON1bits.SSRC=0;
AD2CON1bits.SSRCG=1;
AD2CON1bits.SIMSAM=1;
AD2CON1bits.ASAM=1;
AD2CON2bits.VCFG=0;
AD2CON2bits.CSCNA=0;
AD2CON2bits.CHPS=2;
AD2CON2bits.SMPI=0;
AD2CON2bits.ALTS=0;
AD2CON2bits.BUFM=0;
AD2CON3bits.ADRC=0;
AD2CON3bits.SAMC=4;
AD2CON3bits.ADCS=5;
AD2CON4bits.ADDMAEN=0;
AD2CHS123bits.CH123NA=0;
AD2CHS123bits.CH123NB=0;
AD2CHS123bits.CH123SA=1;
AD2CHS123bits.CH123SB=1;
AD2CHS0bits.CH0NA=0;
AD2CHS0bits.CH0NB=0;
AD2CHS0bits.CH0SA=2;
AD2CHS0bits.CH0SB=2;

_AD2IF=0;
_AD2IP=6;
_AD2IE=1;

AD2CON1bits.ADON=1;
//PWM
PTCONbits.PTEN=0;
PTCONbits.PTSIDL=0;
PTCONbits.EIPU=1;
PTCON2bits.PCLKDIV=0;
PTPER=PWM_PERIOD;
MDC=0;
PWMCON1bits.ITB=1; PWMCON2bits.ITB=1; PWMCON3bits.ITB=1; PWMCON4bits.ITB=1;
PWMCON1bits.MDCS=0; PWMCON2bits.MDCS=0; PWMCON3bits.MDCS=0; PWMCON4bits.MDCS=0;
PWMCON1bits.DTC=0; PWMCON2bits.DTC=0; PWMCON3bits.DTC=0; PWMCON4bits.DTC=0;
PWMCON1bits.MTBS=0; PWMCON2bits.MTBS=0; PWMCON3bits.MTBS=0; PWMCON4bits.MTBS=0;
PWMCON1bits.CAM=1; PWMCON2bits.CAM=1; PWMCON3bits.CAM=1; PWMCON4bits.CAM=1;
PWMCON1bits.IUE=1; PWMCON2bits.IUE=1; PWMCON3bits.IUE=1; PWMCON4bits.IUE=1;
PDC1=0; PDC2=0; PDC3=0; PDC4=0;
SDC1=0; SDC2=0; SDC3=0; SDC4=0;
PHASE1=PWM_PERIOD; PHASE2=PWM_PERIOD; PHASE3=PWM_PERIOD; PHASE4=PWM_PERIOD;
SPHASE1=PWM_PERIOD; SPHASE2=PWM_PERIOD; SPHASE3=PWM_PERIOD; SPHASE4=PWM_PERIOD;
DTR1=PWM_MIN; DTR2=PWM_MIN; DTR3=PWM_MIN; DTR4=PWM_MIN;
ALTDTR1=PWM_MIN; ALTDTR2=PWM_MIN; ALTDTR3=PWM_MIN; ALTDTR4=PWM_MIN;
TRGCON1bits.TRGDIV=0;
TRGCON1bits.TRGSTRT=0;
TRIG1=PWM_PERIOD;
IOCON1bits.PMOD=3; IOCON2bits.PMOD=3; IOCON3bits.PMOD=3; IOCON4bits.PMOD=3;
IOCON1bits.OVRDAT=0; IOCON2bits.OVRDAT=0; IOCON3bits.OVRDAT=0; IOCON4bits.OVRDAT=0;
IOCON1bits.OVRENH=1; IOCON2bits.OVRENH=1; IOCON3bits.OVRENH=1; IOCON4bits.OVRENH=0;
IOCON1bits.OVRENL=1; IOCON2bits.OVRENL=1; IOCON3bits.OVRENL=1; IOCON4bits.OVRENL=0;
IOCON1bits.OSYNC=0; IOCON2bits.OSYNC=0; IOCON3bits.OSYNC=0; IOCON4bits.OSYNC=0;
FCLCON1bits.CLMOD=0; FCLCON2bits.CLMOD=0; FCLCON3bits.CLMOD=0; FCLCON4bits.CLMOD=0;
FCLCON1bits.FLTMOD=3; FCLCON2bits.FLTMOD=3; FCLCON3bits.FLTMOD=3; FCLCON4bits.FLTMOD=3;
PTCONbits.PTEN=1;
IOCON1bits.PENH=1; IOCON2bits.PENH=1; IOCON3bits.PENH=1; IOCON4bits.PENH=1;
IOCON1bits.PENL=1; IOCON2bits.PENL=1; IOCON3bits.PENL=1; IOCON4bits.PENL=0;
IOCON1bits.OVRENH=0; IOCON2bits.OVRENH=0; IOCON3bits.OVRENH=0; IOCON4bits.OVRENH=0;
IOCON1bits.OVRENL=0; IOCON2bits.OVRENL=0; IOCON3bits.OVRENL=0; IOCON4bits.OVRENL=0;

 
 
 
post edited by thepcman - 2019/12/11 05:32:51
#1

22 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 05:56:57 (permalink)
    0
    First question: are the electrical signals (I assume you're using sense resistors - thus the voltage at the resistors) ok?
    All 3 OpAmp outputs ok as well ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 08:41:22 (permalink)
    0
    Yes 1mohm in phase shunt resistors connected to Amc1301 isolation amplifier. The output is fed to unity gain differential op amp with 1.65v mid bias and 20 Khz low pass. The input resistance of diff amp is 2*10kohms. I measured adc pins and maximum p2p mismatch is around 20milivolts.

    All circuitry for current sense is identical for 3 channels. All components are rated for 1% tolerance.

    Ch0 (bus voltage) and ch1 (phase c current) gives perfect results in the whole range. The measurement matches theoretical gains of circuitry. Ch2 and ch3 drops to half of what is expected by design
    post edited by gokhan.ozcetin - 2019/12/11 08:46:19
    #3
    du00000001
    Just Some Member
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 09:01:23 (permalink)
    0
    1 milli-Ohm shunt resistors ?
    And 20 mV mismatch at the ADC pins ? At what min/max voltages ?
     
    If circuit and population are ok, I'd proceed with checking the analog supply at the controller's pins. Any dips ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 09:22:34 (permalink)
    0
    Yes, The power stage maximum current is 200 amps. amc1301 has a maximum input range of +/- 0.25 volts and fixed differential gain of 8.2. So the output of first amplifier is +/- 1.64 volts. This voltage is mid biased around 1.65 volts.
    20mV mismatch is measured at 13. 5 amps motor phase current ;
    Ch1 input is 220 mv p2p, channel 2 input 200mv. However ch2 measures half.

    3.3 digital vdd ripple is no more than 50 mv. It is fed to avdd though 390nH/1uf filter (I also tried replacing filter L with jumper). Vref + is separately fed by ref2033 series reference ic. No obvious ripple on that line
    #5
    sborden
    Super Member
    • Total Posts : 1960
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 10:42:49 (permalink)
    0
    Are you measuring current through a 3-phase motor, or something? If so, what you are seeing is normal:
    post edited by sborden - 2019/12/11 10:46:16
    #6
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 11:45:24 (permalink)
    0
    I am measuring bldc 3 phase current while driving in trapezoidal Mode. The drive is fully functional except this abnormality. I am also calculating average current per phase by summing readings and they are not close
    #7
    sborden
    Super Member
    • Total Posts : 1960
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 12:15:08 (permalink)
    0
    20kHz low-pass might be too low. Figure that only gets you 10kHz effective sampling for a 5kHz signal (these are on the conservative side), which might be inadequate if the commutation speed is high enough: at 3600RPM, about 104 cycles/phase/second. That would give you about 50 points per second (at 5kHz) you have to measure, but you have to measure in the "clean" area of the waveform (the switching forms can be very noisy at the transition points).
     
    It also might be helpful if you post a schematic.
    #8
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 12:21:44 (permalink)
    0
    Well, it is running at 30000 erpm max. So waveform fundamental freq is 500 hz. Since pwm is 20khz, I am trying to avoid pwm noise. Adc is sync.ed to pwm so i believe adequate sampling is done.

    Besides I can measure one current channel perfectly while 2 channels have error.
    #9
    sborden
    Super Member
    • Total Posts : 1960
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 12:30:02 (permalink)
    0
    One phase is firing to PWM. I'll bet that's the phase reading correctly. The numbers you give are too close to the curve. Have you tested the inputs with a fixed voltage while not running the motor? That would also give you a clue as to what is off.
     
     
     
    post edited by sborden - 2019/12/11 12:45:48
    #10
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 12:47:46 (permalink)
    0
    The 6 step commutation is used so there is not a single phase pwmed.

    I could not get how you ended up with the calculation above. Simsam is enabled so each channel is sampled at 20khz. I am calculating average current for each phase by absolute valuing samples and averaging using a weighted filter.

    I expect 20 harmonics is adequate for current signal. That makes 10 khz required bw. So 20 Khz sampling theoretically seems correct

    I tried the same code using dspic33ep256mc506, Explorer 16/32 board and signal generator. I applied triangle wave to all inputs and they give almost same results. However if I apply 2 triangle waves with 180 phase shift to ch2 and ch3, a similar error appears.
    post edited by gokhan.ozcetin - 2019/12/11 14:21:28
    #11
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/11 20:09:08 (permalink)
    0
    du00000001
    1 milli-Ohm shunt resistors ?
    And 20 mV mismatch at the ADC pins ? At what min/max voltages ? If circuit and population are ok, I'd proceed with checking the analog supply at the controller's pins. Any dips ?


    I now realized why you were suprised to hell :D not shunt of course sense resistors :)
    #12
    du00000001
    Just Some Member
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 01:07:26 (permalink)
    5 (1)
    "sense resistor" and "shunt" are used synonymously in this context.
    What I've been surprised was the low value, indicating "quite some power".

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #13
    sborden
    Super Member
    • Total Posts : 1960
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 04:37:29 (permalink)
    0
    I tried the same code using dspic33ep256mc506, Explorer 16/32 board and signal generator. I applied triangle wave to all inputs and they give almost same results. However if I apply 2 triangle waves with 180 phase shift to ch2 and ch3, a similar error appears.

     
    Simultaneous sampling does not preclude you from aliasing, which is what sounds like is happening. You get same results (verifies your hardware and adc settings for conversions) until you apply out of phase. Then you get consistent results that match phase diagrams.
     
    You have 32K RAM available. assuming you can set up your program to give you, let's say 3K points for each phase [3K * 3ph * 2 byte/ph = 18Kbytes], fill the array (no filtering or processing of any kind), then look at the raw data. You should see three distinct, but equal, waveforms out of phase. If the values (within each phase) look good, then it is your data processing that is throwing you off, not the sampling rate.
    #14
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 13:11:38 (permalink)
    0
    I tried to send the raw adc readings and processed them on the computer to get highest value of each phase The raw reading' peaks do match.
    #15
    sborden
    Super Member
    • Total Posts : 1960
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 13:13:50 (permalink)
    0
    Then it's your data processing. Try to collect the a full 3K points and plot them out to get a good picture of what you're looking at. From there you can get a good handle on how to process the data.
    #16
    du00000001
    Just Some Member
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 14:12:46 (permalink)
    5 (1)
    The raw readings peaks match?
     
    Don't tell me you expected the peaks to occur in (about) the same instant !
     
    For a 3-phase motor, (in theory) the vector sum of all phase currents is 0.
    So 1 phase peaking, the other 2 at (negative) 50 % of the peak value is the expected behavior.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #17
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/12 22:02:35 (permalink)
    0
    Of course I am not expecting peaks at the same time. I Just transmit readings and calculate maximum of each phase. At steady state they should more or less match
    #18
    thepcman
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/11/16 23:32:30
    • Location: 0
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/13 01:12:30 (permalink)
    0
     
    Attached here is the current sense circuity. All traces are routed differentially on the same layer upto the op-amp circuit.
     
    All 3 channels have same circuit. 
    post edited by thepcman - 2019/12/13 01:13:31

    Attached Image(s)

    #19
    du00000001
    Just Some Member
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33E ADC Accuracy Problem 2019/12/13 01:35:53 (permalink)
    0
    @thepcman
     
    In post #15 you state that the raw values are ok. If this applies to the former mentioned 2- and 3-phase situations as well - - - search the problem in your software and not in the hardware!

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5