1

I'm trying to read the output of an ADC chip LTC 1867 (need the high precision). I think I understand how it how works. Since it's output is 16 bit I need to send 2 8-bit words to it, the first word starts with a 7 bit input word that controls, what channel, mode and other parameters.

When I ground the channel, it returns 0 as expected but otherwise, it's output is very wrong. A 2.5V reference voltage returns about 1.525. I have tried spidev and pigpio and results seem to be consistent across both.

I decided to use piscope (seems very convenient and useful! especially as I don't have access to an oscilloscope in the evening) to see what was going on with my MISO, MOSI, CLK, CE0. The clock seems to be missing some pulses and I think that is the problem

enter image description here The returned values are something like this enter image description here What I would like to know is:

  • Could it be that one of my pins is not working well, (My digital output from the ADC was 5V so it could have messed it up). How do I check if that is the issue
  • It shows the right value (2.5V) for a like 2 times before returning to the wrong ones (1.524V) and other random values
  • How do I fix the missing pulses? -Does it matter that the clock pulses are uneven -Would software SPI/ bit banging be better?

My Code is

from time import sleep
# Import SPI library (for hardware SPI) and MCP3008 library.
import pigpio
from time import sleep
import os

# Open SPI bus
pi = pigpio.pi()
h=pi.spi_open(0,50000,0)

def twos_complement(input_value, num_bits):
    '''Calculates a two's complement integer from the given input value's bits'''
    mask = 2**(num_bits - 1)
    return -(input_value & mask) + (input_value & ~mask)

## http://cds.linear.com/docs/en/datasheet/18637fc.pdf

#Function to read SPI data from LTC1867 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  #pin 7-GND=244, pin 5-GND=228, pin 1-GND=196
  (count, rx_data) = pi.spi_xfer(h,[228,0])
  print "rx_data"
  #print rx_data
  index=0
  rx_array=[0,0]
  for byte in rx_data:
          rx_array[index]= byte
          index=index+1
  print rx_array
  data = (rx_data[0]<<8) + rx_data[1]
  print "data"
  #print data
  #print "2's complement"
  #data= twos_complement(data, 16)
  print data
  return data

# Converts data to voltage level,
# rounded to specified number of decimal places.
def ConvertVolts(data,places):
  volts = (data * 2.5) / float(pow(2,16))
  volts = round(volts,places)
  return volts

print('Reading LTC1867 values, press Ctrl-C to quit...')

tilt_channel_pos=0
tilt_channel_neg=1
delay=5

while True:
      print "--------------------------------------------"
      tilt_bits_pos = ReadChannel(tilt_channel_pos)
      tilt_volts_pos = ConvertVolts(tilt_bits_pos,3)
      print("Volts: {}V".format(tilt_volts_pos))
      break

      # Wait before repeating loop
      sleep(5)

1 Answer 1

1

piscope will not be seeing all the SPI traffic as the SPI bus is running at the same speed as the pigpio sample rate (default 200ksps).

When you are testing drop the SPI sample rate to something like 50kbps to ensure all the GPIO level transitions are captured.

E.g. use h=pi.spi_open(0,50000,0) rather than h=pi.spi_open(0,200000,0).

The code is sending two bytes (228, 0) to the LTC 1867. So the control byte is 0xE4. Is that correct.

Could you show some sample of the returned data?

6
  • Thanks! Will try it with a reduced sample rate, will I have to keep it at the reduced sample rate even after testing? Yes the control byte for the channel I want is 1110010X s0 0xE4 should be correct. Some of the returned data is rx_data [68, 0] data 17408 Volts: 0.664V -------------------------------------------- rx_data [248, 0] data 63488 Volts: 2.422V -------------------------------------------- rx_data [0, 0] data 0 Volts: 0.0V which all seem very random
    – Baba
    Feb 10, 2017 at 10:43
  • Thanks! Just edited the question to show the new results with smaller sample rate and returned data. Does it matter that the clock pulses are uneven? It still has 16 pulses which is more like what I was expecting! But I still get random values and very wrong values. Any idea why?
    – Baba
    Feb 10, 2017 at 11:03
  • 1
    Command 228 reads channel 5 of the ADC. Could you add a photo showing your connections?
    – joan
    Feb 10, 2017 at 12:30
  • thanks for the help. A photo of my connections is here (only allowed 2 links in my question) goo.gl/photos/ZfhyaF5SgEEzr1UE7 and goo.gl/photos/2LsVP6Y5rbRVJ5348. The grey wire comes from 2.5V reference chip . Blue is CE0, Yellow isMOSI, Green is MISO and Blue is SCLK.
    – Baba
    Feb 10, 2017 at 15:49
  • I think I've seen the problem. It was with my conversion. For single ended inputs, the reference is 4.096V, using g that I get 2.5V but I used 2.5V which gives me a lower value. Could you please confirm if that's the cause or if it's just a coincidence. Thanks for the help with the piscope!!!
    – Baba
    Feb 10, 2017 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.