Mcp3208 adc help


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default Mcp3208 adc help

    Hello
    New problem, I was using a MCP3202 ADC and was liking it but I need more inputs. I designed a board around the MCP3208 because the commands looked like they would be fairly similar. I can not get a valid stable number out of the MCP3208.
    I have AGND and DGND both hooked to GND because I dont have a seperate GND for each. My power is 5V and my Vref is 5V.
    If I hook ch0 input to ground I get 0 to display on my LCD but if I hook ch0 to 5v I get a value bouncing from 1023 to 3071. Alternating everytime the lcd displays the next fetched value from the ADC. I am using it as a single-ended ADC and I give it a command of %1000.
    This device seems pretty straight forward but I cant get it to work.
    Here is the code I am using
    Define OSC 40
    pause 1000
    Include "modedefs.bas"
    Trisc.0 = 0 ' Sets PortC Pin 0 to Output.
    Trisc.1 = 0 ' Sets PortC Pin 1 to Output.
    CS Var PortC.0 ' Chip Select (MCP3208.10).
    Clock Var PortC.1 ' Clock (MCP3208.13).
    DataIn VAR PortC.2 ' --> Data Out (MCP3208.12).
    DataOut Var PortC.5 ' <-- Data In (MCP3208.11).
    LCD Var portC.3 ' LCD Data debuging pin.

    result0 VAR Word ' Conversion Result CH0
    result0 = 0
    high CS ' Disables MCP308 AD Chip.
    Pause 500 ' Pause to allow lcd to bootup.
    Serout2 LCD,16468,[12,"MCP3208 Test"]
    Pause 5000 ' Pause to see display on LCD.
    Main:
    LOW CS ' Enable ADC
    SHIFTOUT DataOut, Clock, MSBFIRST, [%1000\4] ' Select CH0, Single-Ended
    SHIFTIN DataIn, Clock, MSBPOST, [result0\12] ' Read ADC
    HIGH CS ' Disable ADC

    Serout2 LCD,16468,[12,Dec result0] 'Display CH1 on LCD.
    PAUSE 1000 'Pause long enough to read LCD.
    Goto Main

    Thanks
    Shawn

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    try
    Code:
    LOW CS              ' Enable ADC
         SHIFTOUT DataOut, Clock, MSBFIRST, [%11000\5] ' Select CH0, Single-Ended
         SHIFTIN DataIn, Clock, MSBPOST, [result0\12] ' Read ADC
    HIGH CS ' Disable ADC
    Would have been nice to know the PIC you're using
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    Hey
    I will use the 18F8722 but I am using a 18F4585 in a proto board untill I get this figured out. I hope I a can get it figured out. I already have the board made.
    I will try that after work. After reading more about the MCP3208 Chip last night I was wondering if I am not getting the data from it fast enough and the holding cap inside of it is discharging. I'm not sure.
    Anyways Thanks
    Shawn

  4. #4
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    Ok
    I tried that also and it is a no go. Am I reading the result to fast with the shift in command and the hold cap is not charging. I've read the data sheet numberous times now and can't figure this out. The protocol for the mcp3208 looks the same as the mcp3202. Or am I wrong. I am lost.
    Thanks
    Nick

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    So in essence, you are losing bit 11 and 12 from your result. Although at 5V, one would expect a result of 4095. Anyway, are you sure you are following all the clocking rules as outlined in section 6? I have not read it enough to fully grasp it, but it seems like you may have a clocking after the start bit issue.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    OK, Learning time Steve. For me that is. I read through your post to fast sorry I am always on the go. When I added the fifth bit to my shiftout command I did not get the right result but I did get a different result. I got 2047 when I applied 5V to the input. So then Bert said that it looks like I am missing the 11 or 12 bit, and I agree. So I added a 6th bit to the shiftout command. And I got a very strange result. My value turned to zero. I was using input 0, but at this point I thought I would try the other inputs to see if they were reacting because they are all tied to ground except input 0. Turns out that input 4 was now being used and guess what, when I applied 5V to it, it returned 4095. So here is my vague question what the heck is going on? The data sheet for the MCP3208 needs a 4 bit command MSBF.
    First Bit is mode
    Last Three Bits is the analog input selection


    So I originally tried this.
    SHIFTOUT DataOut, Clock, MSBFIRST, [%1000\4] ' Select CH0, Single-Ended
    My result bounced from 1023 to 3047 on input 0.


    Then Steve said to try this.
    SHIFTOUT DataOut, Clock, MSBFIRST, [%11000\5] ' Select CH0, Single-Ended
    My result then was 2047 on input 0, it appears that I am missing the 12 bit like Bert said.


    Then I tried this.
    SHIFTOUT DataOut, Clock, MSBFIRST, [%111000\6] ' Select CH0, Single-Ended
    My result was 0 but input 0 was tied to 5V. I found that the command had changed my input to input 4. And it was tied to ground. When I tied it to 5V I got my 4095 result like I anticipated.


    Then I tried this.
    SHIFTOUT DataOut, Clock, MSBFIRST, [%110001\6] ' Select CH0, Single-Ended
    My result was input 0 4095 with 5V applied. I don't understand this. Its like the MCP3208 chip drops the first and last bit I shiftout to it. I don't see why that works in the data sheet. Could someone explain it to me? I could understand adding the extra bits to one side or the other but not both.
    Also is there a way to do this with a delay instead of extra bits in my command, it seems a bit cobbled.
    I see this command(DEFINE SHIFT_PAUSEUS 100) in the PBP Manual but it just looks like it will slow my clock speed, which I don't think would be good.

    Thanks
    Shawn

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    The way I read the sheet, its not a delay thing. Seems like the A/D uses the SCL to clock the result out, starting some number of clocks after the start bit. So no matter what you do, on the 12th(maybe wrong number, working from memory here)clock, data is comming out. better be ready to catch it. When you "shiftout" the command, thst starts the clock counting. that gives you start bit, then 4 more clocks (i think) then data is comming on the something more clock.

    I will need to re-read section 6 to try and wrap my head around it. Let me know if you need more info, I will read some more.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    That seems odd but I'm rusty, so I've ordered a couple of those ADCs. Should have them tomorrow.

    Another thing you could try (though I may need another strong coffee)... keep your original code, but read the data on clock falling edge instead of rising edge.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Thumbs down Re: Mcp3208 adc help

    Duh?!?
    3.6 Serial Data Output (DOUT)
    The SPI serial data output pin is used to shift out the
    results of the A/D conversion. Data will always change
    on the falling edge
    of each clock as the conversion
    takes place.
    Change your clock idle from low to high, and see what happen.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Mcp3208 adc help

    That was easy
    Code:
            high cs
            Pause 100 ' Pause to see display on LCD.
    Main:
            LOW CS ' Enable ADC
            SHIFTOUT DataOut, Clock, 2, [%11000] ' Select CH0, Single-Ended
            high Clock
            SHIFTIN DataIn, Clock, 6, [result0\13] ' Read ADC
            HIGH CS ' Disable ADC
            Low Clock
            LCDOUT $FE,1,"ADC: ",dec result0
            PAUSE 100 'Pause long enough to read LCD.
            Goto Main
    now read the datasheet to know why it works
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts