• AVR Freaks

Hot!ADC glitches

Author
henkebenke
Senior Member
  • Total Posts : 77
  • Reward points : 0
  • Joined: 2008/09/27 23:55:51
  • Location: 0
  • Status: offline
2020/10/13 11:49:23 (permalink)
0

ADC glitches

Hi,  my ADC isn't too good. I would be glad for help.
 
I'm using ADC0/1 and the clock input is PBCLK3 divided by 4, so the Tq is 40ns, witch is within specs. The ADC is configured by Harmony. This is the code:
ADCHS_ChannelConversionStart(ADCHS_CH1);
ADCHS_ChannelConversionStart(ADCHS_CH0);
while (!ADCHS_ChannelResultIsReady(ADCHS_CH1) || !ADCHS_ChannelResultIsReady(ADCHS_CH0));
int val1 = ADCHS_ChannelResultGet(ADCHS_CH1);
int val2 = ADCHS_ChannelResultGet(ADCHS_CH0);
DC = (float) val1 * (3.3 / 4096);
DC = DC - 0.5; // cirka
return (float) (val1 - val2) * (3.3 / 4096) / 0.5; // Volt, ohm - 12 bits
 
It measures the voltage of a current sensing resistor of 0.5 ohm.  The AVSS is bypassed by a 330uf and 100n.
 
Theoretically, the least detectable current should be around 0.5mA, but it constantly reads everything between 0 and 300mA. This suggests problems with noise, etc, so I gradually removed possible sources.
I removed the ICD3 - no good.
Finally, I connected both inputs to Avss, and things got better, but still those glitches.  5mA, -2mA, 44 mA, and even 300mA, from time to time.
I am just so stuck. I need help.
 
Thanks. Btw, it's an Olimex devboard. Oh, I forgot, it's a PIC32MZ - 200Mhz.
 
Henrik
 
#1

9 Replies Related Threads

    Murton Pike Systems
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: ADC glitches 2020/10/13 17:02:42 (permalink)
    3 (1)
    Usually with PIC's trying to read the a2d faster than 1MHz will cause problems.
     
     
    #2
    maxruben
    Super Member
    • Total Posts : 3397
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: ADC glitches 2020/10/14 00:41:47 (permalink)
    0
    Some thoughts:
     
    Any difference if you sample and convert just one channel? (Set the other to a fixed value in the code)
     
    Any difference if you increase the sample time?
     
    Any difference if you decrease the ADC clock rate?
     
    Any change if not using float (floating point calculations may not be reentrant)?
     
    Can you check the AN inputs directly with a scope and see if there is any ripple (from the ADC clock) during sample time and/or conversion time? You may need to use a digital output as external trigger for the scope here.
     
    Usually when I use the adc, I set it to sample and convert a number of consequent samples (6 or 10), remove the highest and lowest results, add the number of samples-2 divided by 2 (for correct rounding) and then divide by the number of samples (with 6 or 10 samples this is a division by 4 or 8 which is easy and quick to do with shifts). If I need more smoothing than that, then the new value = (the old value + (the new value - the old value)/some adequate constant to give a slow enough change of the new value). And I don't use float until in the very last stage of the calculation (if at all, can usually be done with only fixed point arithmetic using "friendly" constants).
     
    Good luck / Ruben
     
    #3
    LdB_ECM
    Super Member
    • Total Posts : 456
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: ADC glitches 2020/10/14 05:27:52 (permalink)
    0
    You might want to first consider your mathematics :-)
    Before doing anything else can you show us the line that displays the value.
    #4
    davea
    Super Member
    • Total Posts : 509
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: ADC glitches 2020/10/14 18:24:16 (permalink)
    0
    ADCHS_ChannelConversionStart(ADCHS_CH1);
    while (!ADCHS_ChannelResultIsReady(ADCHS_CH1));
    int val1 = ADCHS_ChannelResultGet(ADCHS_CH1);

    ADCHS_ChannelConversionStart(ADCHS_CH0);
    while (!ADCHS_ChannelResultIsReady(ADCHS_CH0));
    int val2 = ADCHS_ChannelResultGet(ADCHS_CH0);
    #5
    henkebenke
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2008/09/27 23:55:51
    • Location: 0
    • Status: offline
    Re: ADC glitches 2020/10/14 18:51:37 (permalink)
    0
    OK sometimes there are "dybbuks" in the machine.  I tried to increase Tad to some very large value, to no avail.
     
    My math is good enough. But if I halt the debugger at the line where the result is read from the A/D, the values are somewhere from zero to some hundred LSB.  The sampling time is of no importance, since the inputs are tied to separate ADC's.  In other PIC devices I have used, if the inputs are tied to the ground, the result is always zero, or perhaps one.
    And Ruben, floating point calculations are indeed reentrant. But that filtering, averaging thing seems very good. Perhaps the PIC32 are just too hitech - they are made to be super fast etc, so they perhaps are prone to errors.
     
    But this story brought something good - I found that I didn't need this A/D approach at all. If it would have worked, I probably had been chasing a too complex solution.  I firmly believe in the ghost in the machine. I have experienced so much strange stuff over the years that has no rational explanation.  And those bugs, glitches etc, always appear when I'm mentally unbalanced or impatient, etc. 
    But I also believe that those ghosts only appears when the developer believes in them. A calm, mentally stable , rational, developer usually are left alone from those trolls - they know that it's no use. Even if they produces some far fetched problems, the developer still thinks it has a rational explanation. But since I believe in ghosts, they take the opportunity to make a mess from time to time. But this time they actually were on my side - they helped me to realise that I chased an overly complex solution.
    Well this was a real OOT - out of topic. 
     
     
     
     
    #6
    Murton Pike Systems
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: ADC glitches 2020/10/15 13:40:56 (permalink)
    0
    int val1 = ADCHS_ChannelResultGet(ADCHS_CH1);
     
    try:
    int val1= ADCH ChannelResultGet(0);
     
    #7
    LdB_ECM
    Super Member
    • Total Posts : 456
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: ADC glitches 2020/10/15 18:51:47 (permalink)
    0
    @vexorg
    return (float) (val1 - val2) * (3.3 / 4096) / 0.5;

    val1 - val2 can go NEGATIVE
    The display is not a float it looks like an integer because they have no decimal places
     
    Hence I repeat he needs to show us the line that does the display, we need to see everything of how he is deriving the values from the float.
    post edited by LdB_ECM - 2020/10/15 18:59:19
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5