In SX Microcontrollers, SX/B Compiler and SX-Key Tool, fiveslo wrote: I've been trying this for awhile now and just can't seem to get the 12 bits of data from the TLC2543 A/D.. the code I'm using, posted below, is a hack/conversion of what I've found on Tracy Allen's website, emesystems.com, this combined with the code for the Parallax compass module, since I had the example of reading 11 bits? of data in the sample code for the SX, anyways here is what I've found, with the code presented, I can only get from I observe as 8 bit data, meaning that in the result watch window, my result variable only gives back a 0-255 value. I think I'm reading in the result as a byte array? but cannot get the display to ever show anything beyond 255, then when I tried to hack the line: result=14464**result+result from Tracy's program I got errors from the compiler, after researching I found that you can't supposedly multiply a variable by itself or something to that effect, which from what I gather I'm trying to do. Can someone, anyone please point me in the right direction and/or tell me what's wrong with my SX/B program, on how to modify the BS2 program to work on the SX, using SX/B. I'm a complete newbie with this SX/B stuff and completely lost, I have gotten the results from the BS2 program to work flawlessly, and now am trying to construct this program and circuit to accept a serial string from my BS2p to get a voltage reading from any of the channels of the TLC2543 on demand, which the SX/28 will then serially transmit back to the BS2p.. but in any case my example is only dealing with channel 0, and I still can't seem to get it to work... Please help..... Rob ' ========================================================================= ' ' File...... TLC2543.SXB ' Purpose... Read inputs from TLC2543 A/D and transmit results serially. ' Author.... RKacer ' E-mail.... ' Started... 30 MARCH 2007 ' Updated... 08 APRIL 2007 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' Connections: ' ' RC.7 ----> clock out from SX/28 to AD2543 ' RC.6 ----> data out from SX/28 to AD2543 sdi ' RC.5 <---- data in from AD2543 sdo to SX/28 ' RC.4 ----> AD2543 chip select, active low ' RC.3 ----> End Of Converion pin from AD2543 ' RA.0 ----> Serial Output of result ' ' Components: ' ' Texas Instruments TLC2543, 12bit 11 channel A/D converter. ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- sclk VAR RC.7 ' clock out from SX/28 to AD2543 sdo VAR RC.6 ' data out from SX/28 to AD2543 sdi sdi VAR RC.5 ' data in from AD2543 sdo to SX/28 ADcs VAR RC.4 ' AD2543 chip select, active low ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- ADch VAR Byte ' selects AD external channel 0-10 result VAR Byte (2) ' result, 12 bit A/D conversion ' ------------------------------------------------------------------------- ' Watch Directives ' ------------------------------------------------------------------------- WATCH result,12,SDEC ' display 12-bit result variable WATCH result.0,12,SDEC WATCH result.1,12,SDEC ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: HIGH ADcs ' make CS output LOW sclk ' make clock 0-1-0 Main: DO LOW ADcs ' select chip GOSUB ADwake ADch=0 ' acquire TLC2543 channel 0 GOSUB ADread BREAK() ' update result variable in watch window LOOP END ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ADread: LOW ADcs SHIFTOUT sdo,sclk,MSBFIRST,ADch<<8\12 SHIFTIN sdi,sclk,MSBPRE,result(1)\4 ' get result, 12 bits <--- the next two shiftin lines are cut and modified? from the Parallax compass app for SX/B SHIFTIN sdi,sclk,MSBPRE,result(0) <--- I changed the "/3" in the compass app to "/4" since the compass app looks for? 11 bits???? HIGH ADcs ' deselect chip 'result=14464**result+result <-------- commented out because it fails miserably and doesn't seem to agree with the compiler... RETURN ADwake: ADch=$b GOTO ADread ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=183991 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)