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.

FDC2214EVM: I have changed these register values to set the sampling rate of FDC2214evm, but the python logging data are always in 100Hz

Part Number: FDC2214EVM
Other Parts Discussed in Thread: FDC2214

Hi,

I am current trying use this fdc2214evm for a high sampling ratio capacitance sensing work, over 1000hz (T_sample= 1e-3 s), single channel. 

As the given GUI can only have 30hz writing log speed without time output, I attempt to use python based on some predecessors' work, and the test sensor now is the build-in capacitor sensor on evm module.

To control the sampling rate, from the example on the datasheet,  the RCOUNT_CH0 and SETTLECONUT_CH0 register are related to control the conversion time and settle time (channel switching delay is treated as solid, 1 us)

SETTLECONUT_CH0 >Vpk * f_REF0 * C * pi^2 / (32 * IDRIVE0), as the Vpk is at the range of 1.2 to 1.8 (in datasheet), f_REF0 uses the internal clock (40Mhz?), the calculated SETTLECONUT_CH0 would always be smaller than 8, and select 10 for some system clearance, so that the register value is 0x000A

And also we have the settle time ts=SETTLECONUT_CH0 *16 / f_REF0= 4us

 so the ideal conversion time tc should be set as (1e-3 - 1us -4us) = 5.99 e-4 s, as tc = 16* RCOUNT_CH0 / f_REF, the decimal RCOUNT_CH0 = 1497,  and the register value should be 0x05D9

Besides, the CLOCK_DIVIDERS_CH0 = 0x1001

MUX_CONFIG=0x020D, CONFIG=0x1C01 for single CH0 repeat scanning.

I only make these change in register via python, and I can see this values all have been changed via GUI configuration interface, but once I start the loop, the logging data would always be collect with 100hz, if it is due to my computer limit, after I change the sampling ratio to 50 hz, the logging data frequency still has no different.

It looks even I change the register values, I cannot shift this evm board sampling rate, and the sample ratio from the python is always 100hz, or probably I missed any CLOCK settings? Can you give me some suggestions?

following pic is the GUI screenshot after I run the code in Python, to show the register does been re-write

  • Hello, 

    Two questions for you one this: 

    1. When you are reading data through python, how are you getting the data from the EVM? The streaming command or by reading the registers individually? 
    2. When configuring the data graph in the GUI, what value appears in the graph configuration if you change the new data sample rate to EVM output rate? 

    Thank you, 

    Justin Beigel

  • this function is used to read the data from evm

    def read_stream(serial_port):
        stream_bytes = serial_port.read(32)
        if DEBUG_PRINT_RX_DATA:
            print("< " + ":".join("{:02x}".format(c) for c in stream_bytes))
        (error_code, raw_ch0, raw_ch1, raw_ch2, raw_ch3) = struct.unpack('>3xB2xLLLL10x', stream_bytes)
        if error_code:
            print('4- Uh-oh, command returned an error.')
        return [raw_ch0, raw_ch1, raw_ch2, raw_ch3]

    and in the main function just a while loop to read and write in a csv (I have test the time writing and csv writing do not lead a long time interval, and this read_stream may cause the problem)

    async def main():
    
    
        detected_ports = list(serial.tools.list_ports.grep('2047:08F8'))
        evm_serial_port = serial.Serial(detected_ports[0].device, 9600, timeout=1)
    
    
        device_id = read_reg(evm_serial_port, EVM_DEVICE_ID)
        print("device_id=%s" % (device_id))
        evm_config(evm_serial_port)
    
    
        with open('output.csv','a', newline='')as my_csv:
            csv_writer=csv.writer(my_csv)
    
            while True:
    
                   raw_ = read_stream(evm_serial_port)  # get array of 4 channel measurements
                   time_ = time.time()
                   #print(time_,raw_)
                   csv_writer.writerow([time_, raw_])
                   my_csv.flush()
    
    
    
    if __name__ == '__main__':
        asyncio.run(main())

    and for the GUI graph configuration, with this 1797.028hz setting, during the streaming the evm can only achieve around 50 hz maximum output rate

  • Hello, 

    Thank you for the additional information. I have a couple notes for your timing calculations: 

    • The internal clock of the FDC2214 is a 43.4MHz typical value for calculations: 
    • The oscillator included on the EVM is a 40MHz clock. This is what would be used if you set the device to external oscillator 
    • You are configuring the device for single channel mode so there will not be a switching delay. After the first sensor activation (determined by settle count), the sensor will oscillate constantly while conversions happen. 
    • Additionally, the fref that you use for calculations is after the clock dividers. Yours is currently set to 1 so it matches the clock in. 
    • Lastly, for single channel mode, it is recommended to keep fref < 35MHz: 
      • You may need to consider changing your clock divider to 2 

    For the python code, one thing you can do to verify your sample time of the device is to create a loop that writes down the time everytime the DRDY bit of the STATUS register is high. Instead of streaming the data, doing an individual register read and polling for this bit will give you the actual conversion time of the device. This is a good way to double check the expected value for your data collection.

    Best Regards, 

    Justin Beigel

  • Many thanks, following your suggestion I have checked those register values calculation, I think all should be fine, but now the problem is that, the python code always reads via the port communication with around 10 ms time interval. (by changing the register to let the sample ratio as 50 hz, the obtained file would still record the data at 90~100hz, but every two recorded data would be the same as a actual 50hz data reading from the evm board) 

    It looks if I keep using the while loop to run the 'read_stream' function, then the 'read_stream' will always use the 'read' command every loop to communicate through the USB port, so that the 10ms time interval of data acquisition may come from here.

    Is there any other code that can be used to directly stream through the evm, not by using a while loop? as you said a steaming command? any suggestion?

    BR

    Caoyu

  • Hello, 

    The streaming command is outlined in Q3 of this FAQ post. The same protocol applies to the FDC2214EVM. Using this method though, you are subject to the rate at which the EVM firmware outputs the data from the streaming command. 

    Best Regards, 

    Justin Beigel