Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Jean-Claude
Published © GPL3+

Inductive Sensor Prototyping w/ LDC1000 & Analog Discovery 2

Using the LDC1000 IC + AD2 Protocol & Logic Analyzers, Power Supply, Waveform Generator, and Scope to create a framework sensor prototyping.

IntermediateProtip5 hours483
Inductive Sensor Prototyping w/ LDC1000 & Analog Discovery 2

Things used in this project

Hardware components

Analog Discovery 2
Digilent Analog Discovery 2
×1
Texas Instruments LDC1000EVM
×1
Male-Header 36 Position 1 Row- Long (0.1")
Male-Header 36 Position 1 Row- Long (0.1")
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, 0.048" Diameter
Solder Wire, 0.048" Diameter

Story

Read more

Code

Waveforms Protocol Analyzer Script Editor JavaScript Code

JavaScript
This code is used to show how to read the LDC1000 device Id and status information, initialize the device, power it up, read sensor data every 5 seconds, and then power it down.
// LDC1000 init and test script

// CSB and Clock setup //
Select.Active.value = 1;
Clock.Polarity.value = 0;
Clock.Phase.value = 0;

// LDC Device verification //
readWriteSPIBytes(1, 0x80, 0x00);                  // Read device Id
readWriteSPIBytes(1, 0xA0, 0x00);                  // Read device status

// LDC intialization //  
readWriteSPIBytes(1, 0x01, 0x11);                  // Write RMAX value        --> see datasheet Table 6 
readWriteSPIBytes(1, 0x02, 0x3B);                  // Write RMIN value        --> see datasheet Table 8
readWriteSPIBytes(1, 0x03, 0x94);                  // Write SENSOR FREQ value --> 350kHz - see equation at the bottom of pg16 in datasheet
readWriteSPIBytes(1, 0x04, 0x17);                  // Write LDC CONFIG value  --> see datasheet Table 10
readWriteSPIBytes(1, 0x05, 0x02);                  // Write CLK CONFIG value  --> see datasheet Table 11
readWriteSPIBytes(1, 0x0A, 0x02);                  // Write INT CONFIG value  --> (INTB mode: DRDYB, COMP, wake-up)
readWriteSPIBytes(1, 0x06, 0x50);                  // Write THRESHILSB value  --> ---\/ (Hysteresis upper bound)
readWriteSPIBytes(1, 0x07, 0x14);                  // Write THRESHIMSB value  --> 5200
readWriteSPIBytes(1, 0x08, 0xC0);                  // Write THRESLOLSB value  --> ---\/ (Hysteresis lower bound) 
readWriteSPIBytes(1, 0x09, 0x12);                  // Write THRESLOMSB value  --> 4800

// LDC Power UP //
readWriteSPIBytes(1, 0x0B, 0x01);                  // Write to power pin

// Read the Proximity data every 5 seconds for 5 cycles
var i = 0;
for (i = 0; i < 5; i++){
    wait(5);                                       // change the wait time to read the registers faster or slower. 
    readWriteSPIBytes(2, 0xA1, 0x00, 0x00);        // read Proximity Data
    readWriteSPIBytes(3, 0xA3, 0x00, 0x00, 0x00);  // read Frequency Counter Data
}

// LDC Power DOWN //
readWriteSPIBytes(1, 0x0B, 0x00);                  // Write to power pin

return 0;


// FUNCTION TO READ/WRITE BYTES TO SPI //
function readWriteSPIBytes(dataLen, Reg, Data1, Data2, Data3, Data4) {
    Start();
    Select.Active.value = 0;                                 // placed after start() to switch CSB value immediately before data transfer
    switch(dataLen) {
        case 1:
            ReadWrite(8, Reg, Data1);                        // read/write 1 Byte
            break;
        case 2:
            ReadWrite(8, Reg, Data1, Data2);                 // read/write 2 Bytes
            break;
        case 3:
            ReadWrite(8, Reg, Data1, Data2, Data3);          // read/write 3 Bytes
            break;
        case 4:
            ReadWrite(8, Reg, Data1, Data2, Data3, Data4);   // read/write 4 Bytes
            break;
    }
    Stop();
    wait(0.01);                                              // wait 10ms before switching csb value
    Select.Active.value = 1;
    return 0;
}

Credits

Jean-Claude

Jean-Claude

1 project • 0 followers
I am a hardware engineer working in R&D at a small engineering firm. I enjoy working on RF, embedded systems, and programming projects.

Comments