Shop OBEX P1 Docs P2 Docs Learn Events
Using MCP3001 a Microchip 10-bit A/D converter with BS2 — Parallax Forums

Using MCP3001 a Microchip 10-bit A/D converter with BS2

po2lepo2le Posts: 76
edited 2008-11-11 16:11 in BASIC Stamp
I've tried Using MCP3001 a Microchip 10-bit A/D converter with BS2.· The converter has SPI serial interface, and is 8 pin DIP.· I connected it to my BS2 homework bd. in the manner shown on an attachment to this post.· Is it possible that the MCP3001 cannot be used on a BS2?

·I found this circuitry information on the net at this address:
http://www.instructables.com/id/Digital-Voltmeter/Digital-Voltmeter.pdf· .

According to the MCP3001 data sheet:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010527· "The MCP3001 features a successive approximation register (SAR) architecture and an industry-standard SPI serial interface, allowing 10-bit ADC capability to be added to any PIC® microcontroller."

I put the circuitry together for DIGITAL VOLTMETER. I used an MCP3001 and connected it to my BS2 microcontroller kit (PIC16C57C), as shown on the diagram of the instruction sheet. I downloaded the Pbasic code and entered it directly into my Basic Stamp editor. To check out the circuitry, I applied a 1.5v battery, the +terminal, to pin 2 of the MCP, (with neg to gnd).· My output was·Zero's for all. So attached a 3v battery in the same manner with the same results: a lot of zero's. I looked over the code, it was exactly the same as·the download, checked the circuitry hook-ups, numerous times; can't find anything out of place. I have the 10k pull down resistor in place, which is MCP pin-2 to gnd.·

In the code is the statement: "make sure there is a pull-up resistor (10k) on the data pin". I did this too, still no help, still getting zero's.

MAIN PART OF CODE:
cs PIN 0·············· 'chip select is pin 0
clk PIN 1·············· 'clock is pin 1
dat PIN 2············· 'dat is pin 2
························· ·'make sure there is a pull-up resistor (10k) on the data pin


refv CON 5············ 'reference voltage
refvbin CON 1023··· 'the max value for 10 bits


pt CON 1

value VAR Word····· 'the reading results is stored here
voltage VAR Nib····· 'the calculated voltage is here


HIGH cs··············· 'unselect chip
PAUSE 250
GOTO mainloop:
mainloop:
LOW cs····················· 'select that chip
LOW clk·····················'idle clock cycle 1, two are needed
PAUSE pt
HIGH clk
PAUSE pt
··································· 'idle cycle 2
LOW clk
PAUSE pt
HIGH clk
PAUSE pt
··································· 'end idle clock cycles, start null bit
LOW clk
PAUSE pt
HIGH clk
PAUSE pt
'end null bit
'start shift in
SHIFTIN dat, clk, MSBPOST, [noparse][[/noparse]value\10]·······
·'shift in serial data
····························································· 'dat and clk pin are defined
·······························································'msbpost means read bit after clock cycle
·······························································'the 10 bit data is stored into "value"
······························································ 'change the 10 to the resolution of your chip
HIGH cs························ 'unselect chip



voltage = (value * 100 / 1023) * refv / 100···

DEBUG HOME

DEBUG "Binary Read: "
DEBUG BIN value


DEBUG "············ ", CR
DEBUG "Decimal Read: "
DEBUG DEC value
DEBUG "············ ", CR
DEBUG "Voltage: "
DEBUG DEC voltage, CR·········· 'this is rounded down
DEBUG ? voltage


PAUSE 1····························· 'loop delay
value = 0··························· ·'resets the value variable
voltage = 0··························'resets the voltage variable
GOTO mainloop···················· 'repeat


THANKS,· PO2LE




3397 x 4672 - 2M

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-11-11 00:55
    I think you need the grounds of the stamp and the circuit tied together.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • po2lepo2le Posts: 76
    edited 2008-11-11 02:57
    All circuitry is on·the little breadboard that is included with the homework kit.· Stamp and MCP3001 are all attached to the same power source and to the same ground, which is the 5v volt regulator system that is powered by the homework board's 9v battery.· the 5v reference is also from the board's 5v regulator.

    I used the Pbasic code for operating·an·ADC0831 8-bit analog-to-digital converter
    this code·is included with the basic stamp editor's help file.· It worked to a certain extent, but the output was not right.sad.gif· Part of it is listed below.· I was using the MCP3001, though.
    ·This program uses the SHIFTIN instruction to interface with the ADC0831
    ' 8-bit analog-to-digital converter from National Semiconductor.

    Main:
    · DO
    ··· LOW CS····································· ' activate the ADC0831
    ··· SHIFTIN AData, Clk, MSBPOST, [noparse][[/noparse]adcRes\9]···· ' shift in the data
    ··· HIGH CS···································· ' deactivate ADC0831
    ··· DEBUG ? adcRes····························· ' show conversion result
    ··· PAUSE 1000································· ' wait one second
    · LOOP········································· ' repeat
    · END
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-11 16:11
    As a note, the null sent on the first clock cycle can be realized by just shifting in the extra bit. This way there’s no need for all those HIGH/LOW commands before the SHIFTIN command. There may be a minimum clock cycle issue here, though I didn’t look at the datasheet in any detail.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.