Shop OBEX P1 Docs P2 Docs Learn Events
Problems with MCP3008 and ADC_INPUT_DRIVER: — Parallax Forums

Problems with MCP3008 and ADC_INPUT_DRIVER:

MorrisMorrisMorrisMorris Posts: 16
edited 2011-06-22 07:41 in Propeller 1
I'm having an issue with ADC_INPUT_DRIVER running in 10bit mode with the MCP3008. The strange thing is that my servo begins at 0 goes to 255 then skips to 768 and runs fine all the way up to 1023. So, somewhere, I think bit 9 is getting jacked. Anyone else had this problem?

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-06-19 01:41
    Hi Morris,

    first of all welcome to the propellerforum.

    I'm really willing to help, but therefore I need more information. An ADC is not a device that is usually directly connected to a servo. Of course the propeller is inbetween.
    But how? It might be even a MCP3208 which is a well known ADC with a driver in the obex.

    Please give us (the forum-members) an overview about what you want to do in the end. If this is known much better solutions can be found.
    The last couple month this forum went a little boring to me as there are not much beginner threads. Answering on newbees questions is what I personally enjoy most.
    So please do me a favor and write in detail what you are doing.

    Please create an archive with the propellertool.
    Compile your project using F8.
    Then choose from the main menu file - archive - project ... this will create a zip-archive that contains all *.spin-files that are nescessary tocompile the code
    Use the "Go advanced" button and then attach the zip-archive to a posting.

    best regards

    Stefan
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-19 01:45
    The servo is a potentiometer, not an encoder, so this is standard. I think I'm just going to write my own driver. MCP3208 seems to have an abundant amount of support from prop users. Not sure why 12bit is required for so many projects. Anyway, I'm working under an NDA so I can't share any code and I have to be careful about certain details. I was just wondering-- on the off chance that someone here was working below 12bit-- if this had been a problem for them.
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-19 01:47
    Also, the code for this driver is in the object exchange. I'm not doing anything except fetching the channel's value and displaying it.
  • LeonLeon Posts: 7,620
    edited 2011-06-19 01:51
    Forget about the servo pot for now and check your ADC code with a standard linear pot.
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-19 01:53
    How would that cause a direct jump from 255 to 768? I've been extremely thorough hardware side-- my servos are linear.
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-19 02:03
    I'm on deadline, so I'm going to write a driver for the MCP3008 and move on. The ADC_INPUT_DRIVER has a lot of options, none of which I need for this project which makes troubleshooting the code a little complicated. I've written all my own code for this project, but I thought I'd shave some development time down by using an ADC driver from the object exchange. If anyone else tests this driver with a 3008 (or something besides a 3208), please post your findings.

    I'll post my 3008 driver in the Object Exchange when it's complete and add an update to this thread in case anyone needs it.
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2011-06-19 07:46
    Here is a version for the 3008. The Propeller ASC uses an MCP3008 chip.
    MCP3008.spin
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-19 09:10
    Anyone else had this problem?

    I had this with my first MCP3202 driver because the interface is slightly different than with that MCP3204 and MCP3208 -- I have good drivers for all and have used them in several professional projects.

    I suggest you start with a Spin driver which may be all that you need for this particular project. If you need to move to PASM, that's fine, but I always start in Spin to verify connections and behaviors before adding another layer of sophistication.

    My driver includes a method called scale() which I created for converting ADC values into servo position values. The modified version works like this:
    pub scale(raw, minOut, maxOut)
    
    '' Scales raw (0 to 1023) value to new range: minOut to maxOut
    
      raw := 0 #> raw <# 1023                                       ' constrain input
    
      if (minOut < maxOut)                                          ' if good range
        return ((raw * (maxOut - minOut)) / 1023) + minOut
      else
        return raw
    

    I would use a (filtered) reading from the ADC and pass my servo constraints (1000-2000, or 600-2400).

    The nice thing about the MCP3208 is that it seems to be more abundant and it's better to have to chuck resolution than wish you had it. The pin-out is the same as the MCP3008, so I suppose you can try both.
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-19 09:21
    Works beautifully-- Thanks a bunch!
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-19 09:47
    Are you referring to my code or Martin's? I don't have a '3008 to test with -- that said, I checked the timing diagrams and am quite confident in what I posted.
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2011-06-19 10:05
    The problem stems from the fact that both the 3008 and 3208 read out big-endian and then litte-endian back to back. So when you use the MCP3208 driver to read from the 3008 you get a bit pattern with the last two least-significant bits mirrored and repeated. Like this:
    MSB             LSB
    |                 |
    9-8-7-6-5-4-3-2-1-0-0-1
    
  • MorrisMorrisMorrisMorris Posts: 16
    edited 2011-06-20 09:27
    Are you referring to my code or Martin's?
    Martin's. Thanks.
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2011-06-20 10:58
    Martin's. Thanks.

    It's really Parallax's. All I did was strip out the DAC parts -- so I could better understand the driver -- and reduce the number of bits the driver clocks in from 12 to 10. Glad it's working for you!

    (BTW: I added it to the OBEX.)
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-22 07:41
    Martin's. Thanks.

    Good to know (that I still need to test my code). I bought one of Martin's boards with the MCP3008 so I'll give the Spin version a try before moving to ObEx.
Sign In or Register to comment.