Shop OBEX P1 Docs P2 Docs Learn Events
MCP3004 Program — Parallax Forums

MCP3004 Program

NewzedNewzed Posts: 2,503
edited 2007-09-29 13:23 in General Discussion
Here is some test code I dreamed up for the MCP3004.· Can some one take a look at it, especially the shiftin/shiftout statements, and see if it is correct?

Sid

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.

That is why they call it the present.

Don't have VGA?
Newzed@aol.com

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-24 21:55
    Sid,

    You've left off the start bit (has to be a "1") from the beginning of your command: ch0 should be %11100. And I believe this should be shifted left by two, rather than four. Also, you're sending ten clocks with the command, which is fine, but I think seven would suffice. The best bet is to try it with a known input and see if the right data comes out.

    -Phil
  • NewzedNewzed Posts: 2,503
    edited 2007-09-24 22:39
    Phil, I read the data sheet again.· It looks like the 3004 is expecting·three bytes - first the start byte %00000001, then the·CH0 byte %1100XXXX and then a 'don't care' byte.· So it looks like I should write:

    CH0· CON· %1100

    SHIFTOUT Do, clk, MSBFIRST,·[noparse][[/noparse]%00000001\2]
    or
    SHIFTOUT Do, clk, MSBFIRST, [noparse][[/noparse]1\2]

    and

    SHIFTOUT Do, clk, MSBFIRST, [noparse][[/noparse]%1100_0000_0000_0000\16]
    or
    SHIFTOUT·Do, clk, MSBFIRST, [noparse][[/noparse]CH0<<12\16]

    Or am I reading something wrong?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-24 22:46
    I'd try:

    SHIFTOUT Dout, clk, MSBFIRST, [noparse][[/noparse]%1110000\7] 'Start (1), command (1100), and two extra clocks (00).
    SHIFTIN Din, clk, MSBPRE, [noparse][[/noparse]result\10]
    
    
    


    You don't have to break it into bytes. Just send the exact number of clocks necessary to get the command in and the data out.

    -Phil
  • NewzedNewzed Posts: 2,503
    edited 2007-09-24 22:47
    On second thought, maybe it would be better to write:

    SHIFTOUT Do, clk, MSBFIRST, [noparse][[/noparse]CH0<<4\8]
    SHIFTOUT Do, clk, MSBFIRST, [noparse][[/noparse]0\8]

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • NewzedNewzed Posts: 2,503
    edited 2007-09-27 18:10
    Phil, received my MCP3004 chip today and plugged it into my·little module.· After a couple of program corrections the module is working great.· I have attached a copy of my program.· I noted that a change in the raw count of 1 equals·a .1 degree change in temperature when using the LM34DZ.

    Sid





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
  • NewzedNewzed Posts: 2,503
    edited 2007-09-28 22:34
    Hi, Phil

    Plugged my MCP3004 module into the Proto Board and it is working perfectly.· Had a little problem adjusting the raw·count to display the true temperature.· The */ operator is not available in Spin but I was able to get within about .3 of a degree using raw count*32/27.· Now I can log the temperature with a date/time stamp into the upper half of my EEPROM.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-28 22:42
    Sid,

    Good going! I got the board you sent me. Many thanks! Your mill does really clean work, and the board looks nice. Can you post a photo of the finished module?

    -Phil
  • NewzedNewzed Posts: 2,503
    edited 2007-09-28 22:57
    Phil, I'll post a picture tomorrow.· Glad you got the board OK.

    Sid



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • NewzedNewzed Posts: 2,503
    edited 2007-09-29 13:23
    Phil, here is a picture of the assembled MCP3004 Module.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    450 x 314 - 7K
Sign In or Register to comment.