Micropython support LTC1864

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Micropython support LTC1864

Post by nir_bec » Mon Nov 22, 2021 8:28 am

Hi,
I'm trying for few days already to read LTC1864 ADC to the Pyboard without any success.

Here is the component's datasheet:
https://www.analog.com/media/en/technic ... 8645fb.pdf

The problem have to be related to my code as i'm using off the shelf modules and not any custom solution.

As far i understand it should be very easy component to integrate with, but i'm not sure regarding the SPI commands setup.

i configures pin 'X1' as CS,
according to the datasheet it should go 'high', wait around 4us and go 'low',
Than i should be able to read the ADC data, but i'm getting non reasonable garbage values,

Anyone have any experience with this device?

Thank you,

rkompass
Posts: 66
Joined: Fri Sep 17, 2021 8:25 pm

Re: Micropython support LTC1864

Post by rkompass » Mon Nov 22, 2021 7:52 pm

Hi,

I think you are correct. I found that the setup of spi may be critical.
I read the datasheed and would suggest to try something like this:

Code: Select all

from machine import Pin, SPI
from time import sleep_us

conv = Pin('B12', Pin.OUT_PP, value=0)              # use any i/o pin
spi = SPI(2, baudrate=1000000, polarity=1, phase=1) # and a matching SPI, or something like
            # spi = SoftSPI(baudrate=1000000, sck=Pin('A7'), miso=Pin('A6'), polarity=1, phase=) # again use any i/o pins
# miso = sdo on ltc1864, mosi = sdi is not existent on ltc1864
# meanings of: polarity = 1: SCK is high if idle; phase=1: data read at second flank of sck

data = [0] * 100
for i in range(100):
    conv.high()      # start conversion
    sleep_us(4)      # perhaps not necessary: the micropython interpreter takes more than 3-4 us for one command ?
    conv.low()       # conversion finished, terminate sleep mode, start spi transfer
    data[i] = int.from_bytes(spi.read(2), 'big')
                     # spi transfer finished
    sleep_us(100000) # now wait e.g. 1/10 second

nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Re: Micropython support LTC1864

Post by nir_bec » Wed Nov 24, 2021 7:17 am

rkompass wrote:
Mon Nov 22, 2021 7:52 pm
Hi,

I think you are correct. I found that the setup of spi may be critical.
I read the datasheed and would suggest to try something like this:

Code: Select all

from machine import Pin, SPI
from time import sleep_us

conv = Pin('B12', Pin.OUT_PP, value=0)              # use any i/o pin
spi = SPI(2, baudrate=1000000, polarity=1, phase=1) # and a matching SPI, or something like
            # spi = SoftSPI(baudrate=1000000, sck=Pin('A7'), miso=Pin('A6'), polarity=1, phase=) # again use any i/o pins
# miso = sdo on ltc1864, mosi = sdi is not existent on ltc1864
# meanings of: polarity = 1: SCK is high if idle; phase=1: data read at second flank of sck

data = [0] * 100
for i in range(100):
    conv.high()      # start conversion
    sleep_us(4)      # perhaps not necessary: the micropython interpreter takes more than 3-4 us for one command ?
    conv.low()       # conversion finished, terminate sleep mode, start spi transfer
    data[i] = int.from_bytes(spi.read(2), 'big')
                     # spi transfer finished
    sleep_us(100000) # now wait e.g. 1/10 second
Thank you so much for your time and support.
I just tried the code you posted,
As a result I'm reading around half of the full scale (16bit->65,536 values) back, no matter the input voltage to the ADC.

I used SPI #2 on Pyboard (MISO -> Y7, SCK->Y6) and CS as 'X1' pin.
with this function to init the SPI communication
spi = SPI(2, baudrate=1000000, polarity=1, phase=1)

For some reason i couldn't import SoftSPI,
'ImportError: cannot import name SoftSPI'
Could be related to my Pyboard version which is v1.11-412-g2863dcdf4 on 2019-10-10 ?

Thank you again for your time.
Attachments
01.png
01.png (33.07 KiB) Viewed 21184 times

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython support LTC1864

Post by Roberthh » Wed Nov 24, 2021 7:48 am

The limited range may be caused by the wiring and setting the reference voltage. If Vcc is 5V, Vref connected to Vcc, IN- connected to GND, the you shoul get the full range at Vin of 5V.
It may as well be possible, that you get a +/- 32767 range by setting IN- to 2.5 V.

nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Re: Micropython support LTC1864

Post by nir_bec » Wed Nov 24, 2021 8:20 am

Hi,
My wiring is as follows:
-VREF and VCC tied together to 5V coming out of LTC6655 5V voltage reference.
Datasheet:
https://www.analog.com/media/en/technic ... 6655ln.pdf

The LT1864 is the Mikroelectronica ADC11 click
Schematic attached:
https://download.mikroe.com/documents/a ... c-v101.pdf



I connected programmable bench power supply with 1mA current limit to the ADC inputs,
Positive probe of the power supply to the IN+ of ADC, and negative probe to IN- of the ADC.
attached is also the drawing of the LTC1864

Hopefully this information will help to evaluate if i have any connection/wiring problem.

Thank you
Attachments
drawing.png
drawing.png (29.24 KiB) Viewed 21176 times

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython support LTC1864

Post by Roberthh » Wed Nov 24, 2021 12:45 pm

What happens if you swap the inputs? Do you then get negative values?

nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Re: Micropython support LTC1864

Post by nir_bec » Wed Nov 24, 2021 1:17 pm

Roberthh wrote:
Wed Nov 24, 2021 12:45 pm
What happens if you swap the inputs? Do you then get negative values?
When looking more carefully there is some feedback on the results,
With very low voltage < 1V, values are averaged 32834.44 ,
at 4V the average jumps to 33747.27, and when applying 4V on the other direction/polarity the average is around 31812.15,

That's repeatable , I checked every voltage level few times.

Could be related to the Mikroelectronica Click ADC11 schematic i posted in my previous comment? lots of big resistor there on the input lines?
Or something with MSB/LSB order?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython support LTC1864

Post by Roberthh » Wed Nov 24, 2021 1:49 pm

The click module sets Vref to Vcc = 5V, the board input - is tied to a 2.5V virtual level. The IN- input of the chip is tied to GND.
Tjhe virtual GND at Vcc/2 is the reason for a ~32768 reading with low of no input voltage. The input divider has a ratio of 38/2038, which results in an effective range of +/- 134V! That' strange and maybe that is not what you expected,

nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Re: Micropython support LTC1864

Post by nir_bec » Wed Nov 24, 2021 2:04 pm

Roberthh wrote:
Wed Nov 24, 2021 1:49 pm
The click module sets Vref to Vcc = 5V, the board input - is tied to a 2.5V virtual level. The IN- input of the chip is tied to GND.
Tjhe virtual GND at Vcc/2 is the reason for a ~32768 reading with low of no input voltage. The input divider has a ratio of 38/2038, which results in an effective range of +/- 134V! That' strange and maybe that is not what you expected,
Thank you for your feedback.
Going over the ADC 11 Click description these reading manipulations are not mentioned, this module should integrate with another board from the same company, so maybe they do other manipulations there to normalize the reading..

According to the schematic, does it make sense to remove components from the PCB as in the attached image? (Hopefully its clear enough)
I'm able to short the pads of the unmounted resistors / solder small wires even they are small.
Attachments
suggestion.png
suggestion.png (91.45 KiB) Viewed 21127 times

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython support LTC1864

Post by Roberthh » Wed Nov 24, 2021 3:49 pm

If you remove R5 or R6, the range should be about +/- 2.5V.

Post Reply