In SX Microcontrollers, SX/B Compiler and SX-Key Tool, alex41 wrote: [2]Hello again,[/2] [2][/2] [2]I have written the following program to use the LTC1257 12bit DAC. I gathered all the info I could and wrote the code. The N&V column #4 and #43 were very helpful. Of course I read the LTC1257 datasheet too. It seems these articles were written before the SHIFTIN and SHIFTOUT commands were available, so I'm kinda shooting in the dark with setting those up.[/2] [2][/2] [2]The program is basically working, but not 100%.[/2] [2][/2] [2]I'm using a pot with RCTIME to input a number between 0 and 4095. The code seems to be working somewhat, but the output is from 0v to about 3.6 volts. I'm looking for a range of 0 to 5v. The output of the LTC1257 goes through a LM356 op amp and I've read the voltage out of the chip and the op-amp and they are the same, so it appears to be hooked up correctly.[/2] [2][/2] [2]I would guess the code with the SHIFTIN may not be correct, but really don't know where to go from here. Any input?[/2] [2][/2] [2]Thanks,[/2] [2]Alex[/2] Code is below ' ========================================================= ' ' File...... LTC1257R1.SXB ' Purpose... Simple program to use LTC1257 DAC ' Author.... Alex41 ' E-mail.... ' Started... Feb 18 2008 ' Updated... Feb 19 2008 ' ' ========================================================= ' Revision 1, ' ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' This is a simple program to test programming of the LTC1298 DAC chip ' A pot is used to provide a value for the DAC to use ' ' Chip connections, ' ' 1 CLK - RC.0 8 Vcc to 9v pos ' 2 Din - RC.1 7 Vout - output amplified by LM358 ' 3 LOAD- RC.2 6 Vref - 5v pos ' 4 Dout - not used 5 Gnd - Ground ' ' Note - pin 8 on chip is provided with 9v to allow a 0-5v output range ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42 FREQ 4_000_000 ID "LTC1257" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Clk PIN RC.0 OUTPUT Din PIN RC.1 OUTPUT PinLoad PIN RC.2 OUTPUT Potpin PIN RC.7 OUTPUT ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- TmpW1 VAR Word Pottime VAR Word ' ========================================================= PROGRAM Start ' ========================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- DELAY_MS SUB 1, 2 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: ' initialization code here Main: ' main code here DO ' RCtime - read pot to get value HIGH potpin ' charge the capacitor PAUSEUS 300 ' Pause for 50 us RCTIME Potpin, 1, Pottime ' measure in 2 us units IF Pottime > 4095 THEN ' max input of 4095 for DAC chip Pottime = 4095 ENDIF PinLoad = 0 ' activate chip to receive data SHIFTOUT Din,Clk,MSBFIRST,Pottime_MSB ' send high nib SHIFTOUT Din,Clk,MSBFIRST,Pottime_LSB ' send low byte PinLoad = 1 ' de-active chip to output voltage DELAY_MS 500 LOOP ' ------------------------------------------------------------------------- ' Subroutine / Function Code ' ------------------------------------------------------------------------- ' Use: DELAY_MS duration SUB DELAY_MS IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ' save byte value ELSE tmpW1 = __WPARAM12 ' save word value ENDIF PAUSE tmpW1 ENDSUB ' ========================================================= ' User Data ' ========================================================= ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=251301 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)