Shop OBEX P1 Docs P2 Docs Learn Events
Question about the TLc2543 Program from EME Systems. Attn Tracy Allen — Parallax Forums

Question about the TLc2543 Program from EME Systems. Attn Tracy Allen

Paul K.Paul K. Posts: 150
edited 2005-11-26 23:41 in BASIC Stamp
Looking for some answers to a question that I have about this program. Hoping that someone
or Tracy Allen has an answer.

I have tried this program and I couldnt get it to work unless I made a change to it
which was by chance a mistake I made but it started working for me.


1 ' ADread subroutine for OWL2c.
2 ' On command, returns 12 bit digital data from one of 11 analog channels.
3 ' The value of ADch from 0 to 10 selects external analog inputs.
4 ' ADch=14 puts the converter into its sleep mode.
5 ' converter has 5.120 volt reference, for 1.25 mV per bit
6 sclk con 15 ' SPI clock out from BS2 to AD2543
7 sdo con 14 ' SPI data out from BS2 to AD2543 sdi
8 sdi con 13 ' SPI data in from AD2543 sdo to BS2
9 ADcs con 12 ' AD2543 chip select, active low
10 ADch var nib ' selects AD channel 0-10
11 ADv var bit ' selects result as 0:count; 1:millivolt
12 result var word ' result, 12 bit A/D conversion
13 Vconv CON 320 ' 320 */ result is 1.25 * result
14 ' 5120 millivolts / 4096 full scale count
15
16 demo: ' to show off the subroutine below.
17 for ADch =0 to 10 ' specify one of 11 input channels
18 gosub ADread ' get millivolt data from that channel
19 result = 320 */ result ' convert count to millivolts.
20 debug DEC ADch,": ",DEC result,rep 32\5,cr ' display
21 next
22 pause 1000 ' demo delay
23 debug home ' repeat the demo
24 goto demo
25
26 ADread: ' entry point to give result as millivolts
27 low ADcs ' select chip
28 shiftout sdo,sclk,msbfirst,[noparse][[/noparse]ADch<<8\12] ' mode, left justify ADch
29 shiftin sdi,sclk,msbpre,[noparse][[/noparse]result\12] ' get result, 12 bits
30 high ADcs ' deselect chip
31 return
32
33 ADsleep: ' entry point to put TLC2543 to sleep
34 low ADcs ' select chip
35 shiftout sdo,sclk,msbfirst,[noparse][[/noparse]$e0\12] ' command=$e0
36 high ADcs ' deselect chip
37 return

The change I made was on line 28 sdo i changed to sdi and line 29 changed sdi to sdo and it worked.
It showed the reading in mv. Since my Vref was 4.98 I used this in result = result */ 3113 / 10
in line 19 to convert the correct mv. With out these changes I cant get the program to work. But with them
it works fine. Is this a typo in the original or is there something im doing wrong.

My schematic is the same as http://www.emesystems.com/OL2tlc2543.htm I have the sharp GPD12 sensor that
parallax sells with a 330ohm reistor between the tlc2543 and the yellow/signal line from the sharp sensor.
I also have a cap from ground to the signal line which is a 100uf. And the sensor has +V and ground to it.
http://madlabs.info/gp2d12/sharp_gp2d12.shtml has the schematic only difference is cap size.

Thanks
Paul

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-11-26 20:57
    What you did was correct.· SDO on the TLC is an output so you have to shiftin SDO.· SDI is an input so you hve to shiftout to SDA.· It's like talking to another Stamp.· You have to serout to a serin pin· and vice versa.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • NewzedNewzed Posts: 2,503
    edited 2005-11-26 21:02
    By the way, you did not show your pin assignments so I am assuming you labelled the pin going to SDO "SDO".· You should have labelled the pin that goes to SDA "Din" and the pin going to SDA "Dout, and make the necessary changes in your shiftout and shiftin routines.· emember the labels on the chip say what the chip does, not what the Stamp does.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • NewzedNewzed Posts: 2,503
    edited 2005-11-26 21:16
    Another by the way - Tracy's program is correct.· He assumes the user is familiar with the protocol for communicating with the TLC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Paul K.Paul K. Posts: 150
    edited 2005-11-26 21:38
    I kept the same pin assignments as in Tracey's orginal porgram lines 6,7,8, & 9 of the code above. So I didnt change the assignments. The only changes I made were the ones to the sdi and sdo. Im alittle confused if your saying that the orginal program is correct which i assumed it was why does the change work and not the orginal. If at that time all i was looking for was the input of the mv reading from the distance sensor.
  • NewzedNewzed Posts: 2,503
    edited 2005-11-26 21:47
    Neither Tracy's pin assignment nor yours was posted, so I could only guess.· It's important to know how your Stamp pins were connected to the TLC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-26 22:45
    On the TLC2543...
    ...pin 16 is data output
    ...pin 17 is its data input
    ...pin 15 is the chip select
    ...pin 18 is the data clock.

    The program listing and the schematic on the web page assume that the Stamp...
    ... sends data from its pin p14, alias "sdo", to the TLC2543's pin 17, using a command, SHIFTOUT sdo,sclk,msbfirst,[noparse][[/noparse]ADch<<8\12]
    ... receives data into its pin p13, alias "sdi" from the TLC2543's pin 16, using command SHIFTIN sdi,sclk,msbpre,[noparse][[/noparse]result\12]

    Note that sdo and sdi in this program are in fact named from the Stamp's perspective. It can be confusing. Paul, I have to suspect that you have the sdo and sdi pins switched in the wiring. It doesn't matter which pins you use, of course, so long as it is all consistent, that the outputs on one side match up with the inputs on the other, both in hardware and in software.

    I don't see an error or typo in it at the moment. I know there had been one when I first put up the page, and Sid pointed it out to me when he first started using the TLC2543. Sid, my pin assignments are stated in the program header, as well as in the schematic diagram on the web page.
    www.emesys.com/OL2tlc2543.htm

    edit:
    Oops, I had written (expletive)OUT sdo,sclk,msbfirst,[noparse][[/noparse]ADch<<8\12], and we certainly don't want that!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 11/27/2005 2:38:52 AM GMT
  • Paul K.Paul K. Posts: 150
    edited 2005-11-26 23:41
    Yup that was the mistake i made i crossed the wires. I copied that info down and copied it wrong. Did the change and everything works fine now. From the comments that you and Sid posted it cleared things up and I understand it now.

    Thanks
Sign In or Register to comment.