Shop OBEX P1 Docs P2 Docs Learn Events
Help with ADC INPUT DRIVER object — Parallax Forums

Help with ADC INPUT DRIVER object

ADZ_916ADZ_916 Posts: 30
edited 2013-02-15 08:47 in Propeller 1
I'm having trouble getting the object: http://obex.parallax.com/objects/488/ to work correctly. Here is the code I am currently trying:
OBJ
  adc      : "ADC_INPUT_DRIVER"
  pst      : "Parallax Serial Terminal"
  
PUB Main

  pst.start(921_600)
  adc.start(MCP_DIO_PIN, MCP_DIO_PIN, MCP_CLK_PIN, MCP_CSL_PIN, 8, 8, 12, 1, true)
    repeat
      pst.Str(String(pst#cs, pst#NL, pst#HM, "adc channel 0= "))
      pst.dec(adc.getval(0))
      pst.Str(String(pst#NL, "adc channel 1= "))
      pst.dec(adc.getval(1))
      pst.Str(String(pst#NL, "adc channel 2= "))
      pst.dec(adc.getval(2))
      pst.Str(String(pst#NL, "adc channel 3= "))
      pst.dec(adc.getval(3))
      pst.Str(String(pst#NL, "adc channel 4= "))
      pst.dec(adc.getval(4))
      pst.Str(String(pst#NL, "adc channel 5= "))
      pst.dec(adc.getval(5))
      pst.Str(String(pst#NL, "adc channel 6= "))
      pst.dec(adc.getval(6))
      pst.Str(String(pst#NL, "adc channel 7= "))
      pst.dec(adc.getval(7))
      waitcnt(clkfreq/10 + cnt)        '10Hz screen refresh
The output on the serial terminal looks like this:
adc channel 0= 737
adc channel 1= 1
adc channel 2= 738
adc channel 3= 0
adc channel 4= 739
adc channel 5= 0
adc channel 6= 0
adc channel 7= 2048


This is with ch0 pulled high, ch1 low, ch2 on a 10k pot and the rest of the pins are left unconnected. Changing the voltage on ch0 seems to also effect ch2 and ch4. I have tested everything with the object: http://obex.parallax.com/objects/180/ so i know all hardware is working well. If I switch the first two channels so that ch0 is gnd and ch1 vref I get:
adc channel 0= 0
adc channel 1= 3039
adc channel 2= 1
adc channel 3= 2048
adc channel 4= 0
adc channel 5= 2051
adc channel 6= 0
adc channel 7= 2048

Anybody have any idea what is going on here? Isn't 3039 out of range for a 12-bit adc? I would really like to use this object as I like the ability to store and reset min and man values for each channel.

Any help is appreciated!

-ADZ

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-02-13 10:37
    I'm the author of the object, I'm away from my computer right now, so I can't do any testing at the moment, but the simplest thing to try is setting FastMode to false (change the "true" at the end of the .start call to "false").

    Depending on your clock speed, and the ADC's operating voltage, FastMode will probably be running your ADC out of specification. FastMode should only be used on 12-bit ADCs when running under 40MHz (or 32MHz -- I forget). 10-bit ADCs work at much higher sample rates and can handle the faster reading better (but still FastMode should be used with caution at 80+MHz). So try turning off FastMode, or run the clock speed at a lower speed.
  • ADZ_916ADZ_916 Posts: 30
    edited 2013-02-13 16:39
    Hey Bob, Thanks for the response, I just gave it a go with fast mode false and set my pll to 4x for a 40Mhz clock (10Mhz xtal) and got similar results. My output now looks like:
    adc channel 0= 2046
    adc channel 1= 4095
    adc channel 2= 2046
    adc channel 3= 0
    adc channel 4= 2047
    adc channel 5= 12
    adc channel 6= 0
    adc channel 7= 13


    It also seems as though again ch0, ch2, and ch4 are some how interfering with each other as touching the resistor on p0 affects all three channels. Thanks again for helping me out with this!
    -ADZ
  • frank freedmanfrank freedman Posts: 1,983
    edited 2013-02-13 16:46
    Watch out on this ADC family. The max clock rate into the clock pin is 1MHz @ 2.7v supply and 2.0MHz @ 5.0v supply.

    FF
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-02-13 16:53
    I'll be able to test the driver tomorrow for specifics, but I've been using this driver on a daily basis for years now without a problem. But I do know the supply voltage and other electrical characteristics have cause problems during setup for myself and others.

    The other question is how are the inputs held high or low? With a resistor? Or shorted? Or and opamp? I doubt this is a problem as you are getting weird readings on many inputs.

    Double check your wiring and make sure there is a decoupling capacitor on the power and reference pins. Are you running the ADC at 3.3V or 5V?
  • ADZ_916ADZ_916 Posts: 30
    edited 2013-02-13 16:53
    If I use PLL2x or none it seems to work ok and give me the values I expect. So I guess the question would be is there a way to "slow down" the driver so i can use this object with an 80mhz propeller clock speed?

    Edit: I'm running the ADC at 5v
  • frank freedmanfrank freedman Posts: 1,983
    edited 2013-02-13 17:35
    I used the counter to provide the clock to the ADC for MCP3201s. I have a .0 object in the obex that needs some cleanup from what has been learned since then, but it does run on an 80MHz clocked prop. Bob beat me to the de-coupling on the supply and reference. Is the spin code a wrapper to test Bobb's object? If not see if his object has a demo/test program to play with the object.

    FF
  • ADZ_916ADZ_916 Posts: 30
    edited 2013-02-13 17:49
    Thanks for the help guys, I am still a beginner and have much to learn about the counters as I think they will be a huge part of my eventual finished project. It looks as though I may end up using Chip's 3208 object as it seems to work at 80mhz clk speed. Bob I noticed the Nikola Tesla quot in your signature. I'm actually using the prop to develop a solid state Tesla coil controller. The first program I'm working on will use the synth object to step through a range of frequency and collect feedback from the MCP, the frequency at which the MCP has the highest output should be the freq of resonance (At least that's the way it made sense in my head). So you can see where the Min Max and AVG would be helpful. Thanks again for the help! Its good to see a forum where people are so willing to help others, hopefully I will get to a point someday where I can return the favor.
    -ADZ
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-02-14 09:07
    ADZ_916 wrote: »
    It looks as though I may end up using Chip's 3208 object as it seems to work at 80mhz clk speed....So you can see where the Min Max and AVG would be helpful.
    It's not nearly as fast, and as you mentioned it is missing some features that my object has. The read speed is much slow because it doesn't get the values until you ask for them, where as my object is constantly getting the values to populate the variables, so per-channel access is way faster.
    ADZ_916 wrote: »
    Bob I noticed the Nikola Tesla quot in your signature. I'm actually using the prop to develop a solid state Tesla coil controller.
    Very cool. I've always wanted to build a tesla coil and the new solid state ones look like a blast to play with!


    You never mentioned if you had decoupling capacitors or not, this is very important for these ADCs (really for any IC). Also, the power supply is important, as the read speeds get faster, more spikes in the power draw are generated. Thus, if you are running the device off a limited power supply like a battery or USB (or the like) the increase in power draw or the noise on the power line could be causing an issue, capacitors, again, may fix this (but this time larger power rail filter capacitors). What is your power supply like and what kind of filtering/decoupling capacitors do you have?
  • ADZ_916ADZ_916 Posts: 30
    edited 2013-02-14 21:06
    All rails are well filtered with 2x 2200uf lytics per rail and IC's decoupled with 10uf tantalum. I've checked both the 5v and 3v3 rails with my o-scope and have nice solid voltages at the supply pins of the IC's I am currently using usb for power but have tested with a 10A bench supply with the same results. As I said before it seems to work fine if I lower my clock speed to 20mhz or below. Would love to get this working with a 80mhz clock. Is it possible that my 10mhz xtal has something to do with this?
    Very cool. I've always wanted to build a tesla coil and the new solid state ones look like a blast to play with!

    They are a lot of fun to play with however you should see the pile of dead mosfets. Lol, Its silicon genocide! That's the reason I decided to get the prop involved, eventually I would like to use it to control phase lead/lag, switching dead time, over-current and over-voltage, audio/midi modulation and the list goes on. Hopefully the a/d will be able to display things like dc buss voltage, average current ( with use of a CT), and I'm sure I'll find a few other things to monitor.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-02-15 08:47
    ADZ_916 wrote: »
    IC's decoupled with 10uf tantalum.
    Tantalums aren't the best for that, usually small ceramics are used (0.1µF, 0.01µF), they respond to higher frequencies better. I've even seen recommendations for some very noisy components to use a 0.1µF, a 0.01µF, and a 1000pF cap, because they all compensate for different frequencies. Of course, I don't think that is the case here, the tantalums are probably enough.

    I know when I wrote the driver I tested it at 80MHz with out FastMode and it worked, else I would have created a SlowMode, but again I might have been running above specifications and my IC just sucked it up. I just found my MCP3208, I couldn't find it yesterday, I'll do some testing today and see if I can duplicate something. I use many (hundreds) MCP3008s every day using this driver, but the 3008 has a higher sample rate and the project runs at 40MHz, so most of this stuff isn't comparable to your problem.

    I'll let you know.
Sign In or Register to comment.