This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Proximity data via USB CDC

I'm attempting to continuously stream the proximity data over the serial port and I have a couple of questions:

Is there a way to stream proximity data without tampering with the firmware? If not I was either going to poll proximity as fast as I'm allowed or stream inductance and calculate proximity from there.

What is the max polling rate of the proximity sensor, I remember reading that baudrate is irrelevant with USBCDC, any sort of clarification would be nice.

Lastly, can you help me make sense of the data returned by polling proximity? Writing "1" to the EVM returns:
"  30768   25393   12599    2573 " as 16bit signed integers, I've been trying to implement my proximity grapher as a way to test it's functionality but I feel like I'm not massaging the data just right. I'm aware that proximity has an MSB and an LSB but from what I can infer the C code only reads the LSB...I'm a little confused.

Here is the C code that reads the proximity


static void menuReadProx() {
    uint8_t i;
    uint16_t data;
    uint8_t printString[16];
    if (!spi_readBytes(NULL, LDC1000_CMD_PROXLSB, &printString[0], 2)) {
        i = sprintf ((char *)printString,"err timeout\r\n");
    }
    else {
#ifdef HOST_DEVICE_LDC1000
            data = printString[0] | (printString[1] << 8);
#endif
        i = sprintf ((char *)printString,"0x%x\r\n",data);
    }
    sendString((char *)printString,i);
}

where PROXLSB is defined as register 0x21

Here is the readbytes function:

uint8_t spi_readBytes(SPI_1P1_CS_Pin * cs, uint8_t addr, uint8_t * buffer, uint8_t len) {
    if (done != TRUE) return FALSE;
    txlen = 0;
    rxlen = len;
    rxbuf = buffer;
    txaddr = addr | SPI_RWBIT;
    if (!spi_exec(cs)) return FALSE;
    return TRUE;
}

  • Hello Bergur,

    Please note that you cannot calculate the proximity data from the inductance data. The communication agrees with the standard SPI protocol. Please, refer to the page 19 of the datasheet.

    Best Regards,

    Natallia Holubeva

  • Thanks for taking the time to answer I really appreciate it, but, this doesn't answer the most important question. Can you please explain to me how to interpret the proximity data returned via USB CDC because the documentation is either lacking or does not make sense.

  • Hello Bergur,

    The proximity data reports the resonance resistance. You can calculate the resistance based on proximity data using the conversion formula below:

    Best Regards,

    Natallia Holubeva

  • I'm not sure you understand me correctly, I'm not trying to calculate Rp but rather figure out how the 5000 proximity value is retrieved from the registers. Writing a "1" to the EVM via USB CDC returns something along the lines of "30768   25393   12599    2573" (signed 16 bit integers) and it's not quite clear to me how that translates to a 5-6 digit proximity value.

  • Hello Bergur,

    In your code, you are only reading register 0x21. You need to read both registers 0x21 and 0x22. The proximity data is written in the register field that contains 2 registers (0x21 and 0x22). The register field contains 16 binary values that you can then translate to the decimal value. The maximum decimal value you can thus get is 65535. 

    Best Regards,

    Natallia Holubeva

     

  • The code in question is actually from TI and I figured it out after reading your responses and talking it over with my colleagues. With the latest firmware sending "1" over the serial port returns the proximity in ASCII format, something like  "0x1217clrf", this data is actually 8 bytes,

    bytes 1&2 = 0x

    bytes 3&4 is the first digit represented as hex

    bytes 5&6 is the second digit represented as hex,

    bytes 7&8 is the return newline characters


    With this in mind it gives us a general idea of how to process this information. In order to automate the polling I turned to C# and the .Net library. First I create the port, open it, send the command, then read all 8 available bytes from the buffer (stored in data[])

    //grab the ascii representation of the two HEX numbers, disregard 0x and \r\n, inefficient, I know

    byte[] proxarray = new byte[] { data[2], data[3], data[4], data[5] };

    //convert the array to a string with ascii encoding

    string hexFromASCIIBytes = System.Text.Encoding.ASCII.GetString(proxarray);
    //parse the HEX string as an integer

    int proximity = int.Parse(hexFromAsciiBytes, System.Globalization.NumberStyles.AllowHexSpecifier);
    //profit

    Console.Write(parsed);
    I'll be posting the full source on GitHub within the next few days so anyone else interested can fiddle with the code :), thanks a lot for talking this through with me.
  • Hello Bergur,

    Thank you very much for sharing your work with the community.

    Best Regards,

    Natallia Holubeva

  • You can find the source at

    https://github.com/Bergur1/LDC1000ProximityPlot.Net

  • Bergur,

    Thank you for sharing.

    Best Regards,

    Natallia Holubeva