Shop OBEX P1 Docs P2 Docs Learn Events
A/D Help — Parallax Forums

A/D Help

Tom PTom P Posts: 97
edited 2009-01-22 07:28 in Propeller 1
Need some help!
I have a Propeller demo board w/LTC1298.
I·went to the Propeller Exchange and located the LTC1298 folder.
I connected the LTC1298 as per the diagram in the CD_LTC1298 program file within the main folder.
I do not see, how this particular program displays and output of the A/D
I've tried the CD_Test_LTC1298 and that displays, what looks like binary reading for two channels.

I want to be able to collect data using the LTC1298 with a Propeller and send the data in "volts" out a serial port.
Can anyone help with this???
tom

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-12 21:07
    The CD_LTC1298.spin file, in case you haven't figured out, is an I/O driver. It gets called by another program with requests like "start a conversion" or "get the actual ADC value" and does the necessary I/O pin manipulation to get the LTC1298 to do the requested function. All the rest is simply an example / demonstration of how to call the I/O driver. It's intended to be a starting point for the user's own program.

    Unless it's a "pain" using the TV screen, I suggest you modify the test program so that you're displaying the exact text strings that you want to see go out a serial port. It's then trivial to add the Simple_Serial.spin I/O driver to the test program and output the text string out a serial port as well as the screen. If you want, you can leave the TV display code there and just not connect the TV.

    Most of the code in the test program is there just to set up the TV driver and you can ignore it. The main part you need to be concerned about is what's labelled as the "Main Program Loop". Do take a look at the Simple_Serial object and the example that comes with it.

    The ADC and the current display routine shows the output of the two channels of the LTC1298 in binary form and in decimal form and the data is provided as integers ranging from 0 to 4095, always positive and representing the voltage <value> * Vref / 4096. You'll need to decide how you want your voltage displayed. Is there an offset? How many decimal places do you want to display? Is there a multiplicative scale factor? There are easy ways to do all this using integer arithmetic or you can use the Propeller's Floating Point Package to do this (have a look at it).
  • Tom PTom P Posts: 97
    edited 2009-01-05 14:11
    I·would like to continue working on using the LTC1298 to collect·dual voltage readings and display both via video and through serial port. I'am pretty new to the Propeller, so I need some help.· I understand the CD_TEST_LTC1298 program outputs binary and decimal output on the TV display, ranging from 0 to 4095.
    OK, so I want to display the voltage collected as volts, there is no offest and would like to display 0 to 3 volts. How do would I do this? Can you·help to better understand what has to be done?
    thanks in advance for your help
    Tom
  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-05 15:41
    In CD_Test_LTC1298, there are two lines that read

    Temp := adc.GetADC(0)

    and

    Temp := adc.GetADC(1)

    To convert the readings (ranging from 0 to 4096) to voltage, the scale needs to be adjusted. 4096 corresponds to 5V for the LTC1298. Say we assume 3 decimal places, so 5000 milliVolts corresponds to a reading of 4096. If you use the following line, you get a display in milliVolts:

    Temp := adc.GetADC(0) * 5000 / 4096

    If you want your display to be in Volts with the embedded decimal point, the Num.ToStr result will have to be modified. If a milliVolt display is adequate, the above formula will do. Note that the voltage range is 0-5V because the LTC1298 runs off 5V and uses the supply voltage as the reference voltage for the conversion.
  • Tom PTom P Posts: 97
    edited 2009-01-05 20:51
    Mike:
    Thanks I got the program to display both values channels in decimal form on the TV screen displaying millivolts.
    For now I wiil experiment with Millivolts rather than volts.

    Ok, So finally I want to send the two readings out a pin desginated as a serial port output using Simple_serial.spin or Duplex_Serial.spin. How do I assign a single pin as a serial port? How do I incorporate that into the program? And what else do I need to consider?

    Once again thats for your kind help!
    Tom
  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-05 21:13
    Simple serial works fine for transmitting only. I think you can use -1 for the receive pin # when you initialize it if you're not going to use the receive side. You can pass strings (including Num.ToStr) to Simple serial just like the demo passes them to the display driver
  • Tom PTom P Posts: 97
    edited 2009-01-06 13:09
    Mike:
    I 'am confused and do not understand your last response below!
    [noparse][[/noparse] I think you can use -1 for the receive pin # when you initialize it if you're not going to use the receive side.]

    I'am using the Propeller Demo board, with P0 and P1 commuicating with the LTC1298.
    I want to use a single pin such as P2 for the serial output to send voltage reading out the serial port.
    I only want to send voltage readings one-way out of the Propeller Demo board to remote serial display.

    So, using the modified CD_TEST_LTC129 program, how do I declare pin P2 as a serial output and how do I send the serial info out the serial port pin P2??

    Thanks
    tom
  • Tom PTom P Posts: 97
    edited 2009-01-06 18:15
    I forgot that P0,P1 and P2 are used by by LTC1298 - ADC.
    So how do I assign P3 as an output on the Propeller Demo board, then how can I send serial millivolt reading out the serial port at P3 using "FullDuplexSerial"?

    any help would be greatly appreicated!
    thanks
    Tom
  • JTCJTC Posts: 60
    edited 2009-01-22 05:56
    Mike I need to make the LTC1298 work with 4 pins rather than using the resistor
    and am having trouble getting it to work.
    Set the din pin to pin+3 and set it to input
    I set the dataio pin to out. I compiles but I get nothing.
    Can you see where I am going wrong. I am sure it something simple I am overlooking.
    Thanks guys

    PUB GetADC( chan ) : adcr | ADC_Val

    if (chan == 0)
    ADC_Val := convert(0)
    if (chan == 1)
    ADC_Val := convert(1)
    return ADC_Val

    PRI init( cs_, clk_, dataio_,Din_ )
    cs := cs_
    clk := clk_
    dataio := dataio_
    Din := Din_
    dira[noparse][[/noparse]Din] := 0
    dira[noparse][[/noparse]clk] := 1 ' set clk pin to output
    outa[noparse][[/noparse]clk] := 0 ' Set clk to Low
    dira[noparse][[/noparse]cs] := 1 ' set Chip Select to output
    outa[noparse][[/noparse]cs] := 1 ' set Chip Select High


    PRI convert( ad_chan ) : datar_val

    if (ad_chan == 0)
    ADC := CH0
    if (ad_chan == 1)
    ADC := CH1

    dira[noparse][[/noparse]dataio] := 1 ' Set Din/Dout to output
    outa[noparse][[/noparse]dataio] := 0 ' Set Din (output) Low

    datar := write(ADC) ' write MUX Address to start conversion for SDC channel (delay needed???)
    return datar

    PRI write( cmd ) : datar_val | i

    datar := 0 ' Clear the data storage LONG

    outa[noparse][[/noparse]cs] := 0 ' set Chip Select Low
    writeByte( cmd ) ' Write the command to start conversion for X port
    'dira[noparse][[/noparse]dataio] := 0 ' set data pin to input
    delay_us(2) ' Clock delay

    ' Ok now get the Conversion for this channel
    repeat i from 12 to 0 ' read 12 bits 11-0 for MSB
    outa[noparse][[/noparse]clk] := 0 ' toggle clk pin High
    ' delay_us(2) ' Clock delay
    if ina[noparse][[/noparse]Din] == 1
    datar |= |< i ' set bit i HIGH
    else
    datar &= !|< i ' set bit i LOW
    outa[noparse][[/noparse]clk] := 1 ' toggle clk pin Low
    ' delay_us(2) ' Clock delay

    outa[noparse][[/noparse]cs] := 1 ' set Chip Select High

    return datar

    PRI writeByte( cmd ) | i

    repeat i from 0 to 3 ' LTC1298 has 1 start bit and 3 data bits
    outa[noparse][[/noparse]dataio] := cmd ' send LSB bit
    outa[noparse][[/noparse]clk] := 1 ' toggle clk pin High, Chip reads on rising edge.
    ' delay_us(2) ' Clock delay
    outa[noparse][[/noparse]clk] := 0 ' toggle clk pin Low
    ' delay_us(2) ' Clock delay
    cmd >>= 1 ' shift to next bit

    PRI delay_us( period )
    ' CLK HIGH/LOW time = 2µS MIN
    waitcnt((clkfreq / 100000 * period) + cnt) ' Wait for designated time
  • JTCJTC Posts: 60
    edited 2009-01-22 07:28
    MIke never mind I fund it. I had my Datin and Dataout swapped.
    I will be trying hi speed opto couplers in the 4 lines next.
    thanks
    Jim
Sign In or Register to comment.