EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

TLC2543 example questions

Started by eccentric_mofo September 19, 2002
Hello, I've been studying the code on peter anderson's website
regarding the TI TLC2543 ADC, and have a few questions for those of
you who are experienced with playing around with it!

Here is the code verbatim from his website:

Program TLC2543_1.Bas
'
' Illustrates how to perform a single measurment on a specific
' channel.
'
' Performs unipolar measurments on each of the 11 channels, displaying
' the results on the terminal (Com 1) and then powers down A/D.
'
' Note that the format of the command byte is;
'
' C C C C L1 L0 LSB BIPOLAR
'
' where C is the channel (0 - 10).
' L1 and L0 = 11 binary indicates 16-bit format.
' LSB is zero for most sig byte first.
' BIPOLAR is 0 for unipolar measurement.
'
' The command byte is sent followed by a dummy byte so as to send 16
bits.
'
' This is followed by a 16-bit read of the result where the 12-bit
result
' is in the high 12-bits. This is shifted right (\16) such that the
result
' is in the lower 12 bits.
'
' Note that in TLC2543_2, the process is speeded up a bit by sending
the
' command for the next measurement while the previous result is being
' fetched.
'
' BX24 TLC2543
'
' MISO <---------------- D_Out (Term 16)
' MOSI ----------------> D_in (Term 17)
' SCLK ----------------> CLK (Term 18)
'
' /CS (term 13) -------> /CS (Term 15)
'
' See http://www.ti.com for a data sheet.
'
' copyright, Peter H. Anderson, Baltimore, MD, Sept, '00

Const CSPin as Byte = 13

Sub Main()

Dim N as Byte, Val as Integer, SPISetUpByte as Byte, SPIChannel as
Byte
Dim BiPolar as Byte
Dim Str as String *10
Str = " ... " ' used for debugging

Call OpenSerialPort(1, 19200)
SPISetUpByte = 1
SPIChannel = 1
BiPolar = 0 ' unipolar measurements
Call OpenSPI(SPIChannel, SPISetUpByte, CSPin)

Do
For N = 0 to 10
Val = TLC2543SingleMeas(SPIChannel, N, BiPolar)
' SPIChannel, Channel N, Bipolar
Call PutB(N)
Call PutStr(Str)
Call PutI(Val)
Call NewLine()
Call Sleep(0.5)
Next

Call TLC2543Sleep(SPIChannel)
Call Sleep(5.0)
Loop
End Sub

Function TLC2543SingleMeas(ByVal SPIChannel as Byte, _
ByVal Channel as Byte, _
ByVal BiPolar as Byte) _
as Integer

Dim PutData(1 to 2) as Byte, GetData(1 to 2) as Byte

PutData(1) = Channel * 16 + bx00001100 + BiPolar
' channel plus 16-bit mode + BiPolar
PutData(2) = bx00000000

Call SPICmd(SPIChannel, 2, PutData(1), 0, GetData(1))
' send command byte followed by dummy byte
Call Sleep(0.05)
' receive 16 bit result
Call SPICmd(SPIChannel, 0, PutData(1), 2, GetData(1))

' Call PutB(GetData(1))
' Call PutByte(Asc(" "))
' Call PutB(GetData(2))
' Call NewLine()
' Put the high and low bytes together. Result is in lower 12-bits.
TLC2543SingleMeas = CInt(GetData(1)) * 16 + CInt(GetData(2))\16

End Function

Sub TLC2543Sleep(ByVal SPIChannel as Byte)
Dim PutData(1 to 2) as Byte, GetData(1 to 2) as Byte

PutData(1) = &H0e * 16 + bx00001100 ' sleep plus 16-bit mode
PutData(2) = bx00000000

Call SPICmd(SPIChannel, 2, PutData(1), 0, GetData(1))
' send command byte followed by dummy byte
End Sub
Ok, questions I have:

1. What is the purpose of the "PutData(2)" and "GetData(2)" bytes
that are defined? I cannot seem to understand why these are part of
the code, as it appears they aren't used.

2. It seems that there are a few commands that he is using that
aren't listed in the library of commands (in the basicx documents).
Examples: openserialport, putb, puti, putstr, etc. Is this code just
for reference, or an actual working example?

3. What is the purpose of the TLC2543Sleep function that he
describes towards the end of the program?

I am taking this step by step, so I appreciate all of your help
regarding this!



To answer a few of your questions:

1) PutData(2) and GetData(2) are the second bytes that are being sent
and received, remember that you are clocking 16 bits of data. If you
tell SPICmd to clock 2 bytes starting at PutData(1), it will send
PutData(2) as the second byte.

2) I'm not sure about the others, but I know that OpenSerialPort is a
sample routine by NetMedia that contains alot of functions you can
incorporate into your code.

I don't know about #3.

Hope that helps!

JeremyB.



The 2024 Embedded Online Conference