ADC error on MBED

classic Classic list List threaded Threaded
3 messages Options
Thiago Naves Thiago Naves
Reply | Threaded
Open this post in threaded view
|

ADC error on MBED

When using ADC on a MBED i'm getting this weird error that seems to be random:
I'm using a voltage divider ( with a potentiometer ) as an input to the ADC. Using a multimeter I verify that I get voltages in 0~0.59 V range. When I leave the voltage at max and keep reading the ADC with the program below, I get values in range 720~760 most of the time, but at some point I start getting random values in range 1000~4095 … after a fiew samples it getts back to normal….and then the problem happens again and so on….

I'm using eLua trunk rev 762.
I'm having this problem on MBED, but EK-LM3S8962 runs as expected with the same hardware and code ( only changing the ADC port )…

Thanks for any help =)


I'm using this code:

local port = 4

function sample( smoothing, clock, buffer )
  local tmp, key

  -- No blocking
  adc.setblocking( port, 0 )

  -- Smoothing
  adc.setsmoothing( port, smoothing )

  -- Clock
  adc.setclock( port, clock, 1 )

  -- Start sampling
  adc.sample( port, buffer )

  while true do
    -- If samples are not being collected, start
    if adc.isdone( port ) == 1 then
      adc.sample( port, buffer )
    end

    -- Get a sample
    tmp = adc.getsample( port )

    -- Got something ?
    if tmp ~= nil then
      term.print( 1, 1, string.format( "%04d", tmp ) )
    end

    -- Hit ESC to stop
    key = term.getchar( term.NOWAIT )
    if key == term.KC_ESC then
      break
    end
  end

  term.clrscr()
  term.moveto(1, 1)
end

sample( 0, 4, 4 )


----------------------------

Thiago

_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|

Re: ADC error on MBED

I get the same behavior here. When I was initially testing I figured
it might be only happening on 4&5, but I can get it to happen on other
pins as well.

It appears to be a hardware bug, actually:
http://mbed.org/forum/mbed/topic/131/

I can reproduce similar results with code generated from their online
compiler as with your example program.

I'm working on a change that will lower the ADC peripheral clock when
possible by increasing the clock divider, but what I've tried doesn't
seem to eliminate the issue.

Another solution, which should work is reducing the impedance on the
input to the ADC, which you could do by putting a buffer op-amp
between the input pin and your voltage divider (or anything else
you're measuring).  I seem to be able to generate these spurious
spikes even with only about 150-300 ohms between p20 (eLua ADC 5) and
ground, but I don't see any with a wire directly connected to ground.
Trying higher impedances above 1k or so increase the frequency of the
inaccuracies significantly.



On Wed, Jul 28, 2010 at 6:49 PM, Thiago Naves <[hidden email]> wrote:

> When using ADC on a MBED i'm getting this weird error that seems to be
> random:
> I'm using a voltage divider ( with a potentiometer ) as an input to the ADC.
> Using a multimeter I verify that I get voltages in 0~0.59 V range. When I
> leave the voltage at max and keep reading the ADC with the program below, I
> get values in range 720~760 most of the time, but at some point I start
> getting random values in range 1000~4095 … after a fiew samples it getts
> back to normal….and then the problem happens again and so on….
>
> I'm using eLua trunk rev 762.
> I'm having this problem on MBED, but EK-LM3S8962 runs as expected with the
> same hardware and code ( only changing the ADC port )…
>
> Thanks for any help =)
>
>
> I'm using this code:
>
> local port = 4
>
> function sample( smoothing, clock, buffer )
>   local tmp, key
>
>   -- No blocking
>   adc.setblocking( port, 0 )
>
>   -- Smoothing
>   adc.setsmoothing( port, smoothing )
>
>   -- Clock
>   adc.setclock( port, clock, 1 )
>
>   -- Start sampling
>   adc.sample( port, buffer )
>
>   while true do
>     -- If samples are not being collected, start
>     if adc.isdone( port ) == 1 then
>       adc.sample( port, buffer )
>     end
>
>     -- Get a sample
>     tmp = adc.getsample( port )
>
>     -- Got something ?
>     if tmp ~= nil then
>       term.print( 1, 1, string.format( "%04d", tmp ) )
>     end
>
>     -- Hit ESC to stop
>     key = term.getchar( term.NOWAIT )
>     if key == term.KC_ESC then
>       break
>     end
>   end
>
>   term.clrscr()
>   term.moveto(1, 1)
> end
>
> sample( 0, 4, 4 )
>
>
> ----------------------------
>
> Thiago
>
> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
>
>



--
James Snyder
Biomedical Engineering
Northwestern University
[hidden email]
PGP: http://fanplastic.org/key.txt
Phone: (847) 448-0386
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
Thiago Naves Thiago Naves
Reply | Threaded
Open this post in threaded view
|

Re: ADC error on MBED



On Fri, Jul 30, 2010 at 1:46 AM, James Snyder <[hidden email]> wrote:
I get the same behavior here. When I was initially testing I figured
it might be only happening on 4&5, but I can get it to happen on other
pins as well.

It appears to be a hardware bug, actually:
http://mbed.org/forum/mbed/topic/131/

That's not good.....=/
 

I can reproduce similar results with code generated from their online
compiler as with your example program.

Not our problem then xD
 
I'm working on a change that will lower the ADC peripheral clock when
possible by increasing the clock divider, but what I've tried doesn't
seem to eliminate the issue.

Another solution, which should work is reducing the impedance on the
input to the ADC, which you could do by putting a buffer op-amp
between the input pin and your voltage divider (or anything else
you're measuring).  I seem to be able to generate these spurious
spikes even with only about 150-300 ohms between p20 (eLua ADC 5) and
ground, but I don't see any with a wire directly connected to ground.
Trying higher impedances above 1k or so increase the frequency of the
inaccuracies significantly.


I'll try the op-amp =)
 
Thanks a lot =)


Best,

Thiago



 
On Wed, Jul 28, 2010 at 6:49 PM, Thiago Naves <[hidden email]> wrote:
> When using ADC on a MBED i'm getting this weird error that seems to be
> random:
> I'm using a voltage divider ( with a potentiometer ) as an input to the ADC.
> Using a multimeter I verify that I get voltages in 0~0.59 V range. When I
> leave the voltage at max and keep reading the ADC with the program below, I
> get values in range 720~760 most of the time, but at some point I start
> getting random values in range 1000~4095 … after a fiew samples it getts
> back to normal….and then the problem happens again and so on….
>
> I'm using eLua trunk rev 762.
> I'm having this problem on MBED, but EK-LM3S8962 runs as expected with the
> same hardware and code ( only changing the ADC port )…
>
> Thanks for any help =)
>
>
> I'm using this code:
>
> local port = 4
>
> function sample( smoothing, clock, buffer )
>   local tmp, key
>
>   -- No blocking
>   adc.setblocking( port, 0 )
>
>   -- Smoothing
>   adc.setsmoothing( port, smoothing )
>
>   -- Clock
>   adc.setclock( port, clock, 1 )
>
>   -- Start sampling
>   adc.sample( port, buffer )
>
>   while true do
>     -- If samples are not being collected, start
>     if adc.isdone( port ) == 1 then
>       adc.sample( port, buffer )
>     end
>
>     -- Get a sample
>     tmp = adc.getsample( port )
>
>     -- Got something ?
>     if tmp ~= nil then
>       term.print( 1, 1, string.format( "%04d", tmp ) )
>     end
>
>     -- Hit ESC to stop
>     key = term.getchar( term.NOWAIT )
>     if key == term.KC_ESC then
>       break
>     end
>   end
>
>   term.clrscr()
>   term.moveto(1, 1)
> end
>
> sample( 0, 4, 4 )
>
>
> ----------------------------
>
> Thiago
>
> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
>
>



--
James Snyder
Biomedical Engineering
Northwestern University
[hidden email]
PGP: http://fanplastic.org/key.txt
Phone: (847) 448-0386
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev


_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev