Py_joulescope_driver with auto range current - Error in current values

I have been having an issue with using the pyjoulescope_driver when current range is set to Auto.

In short, when I select a fixed current range, the current and voltage profile is as expected, I have sleep current levels of 150nA with short spikes of current up to 1mA. When I select the auto range for current, the recorded current profile just shows a noisy flat line. There is no change in my measurement setup other than setting the range setting. I can tell the device is operating correctly, because I can see the voltage line blips that coincide with where I expect to see the current spikes.

The auto range feature has no issue in the Joulescope GUI, current profile is as expected, though obviously you can see the range switching artifacts.

I have pasted my basic script ‘recorder.py’ which just records 5 seconds of data when launched. To fix the error and see the expected current values I simply set the range to manual and select 1.8mA range ( comment out line 33, and remove comment ‘#’ from lines 37 & 38 - the recorder.py script is also attached).

I feel I am missing some step in setting up auto range feature - or perhaps the data needs to be handled differently when auto range feature is set?

from pyjoulescope_driver.record import Record
from pyjoulescope_driver import Driver
import datetime
import time
import os

import logging

SAMPLING_FREQUENCY_HZ = 1000000
logging.basicConfig(level=logging.DEBUG)

def construct_filename(out_dir):
    timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
    filename = 'IVT_' + timestamp + '.jls'
    os.makedirs(out_dir, exist_ok=True)
    full_file_path = os.path.join(out_dir, filename)
    return full_file_path


filepath = construct_filename("recordings")

with Driver() as d:
    devices = d.device_paths()
    device = devices[0] # open first device - 
    d.open(device)

    d.publish(f'{device}/s/i/range/mode', 'auto')
    #d.publish(f'{device}/s/i/range/max', '180 mA') # Limits max range to 180mA
    #d.publish(f'{device}/s/i/range/min', '18 µA') # Limits min range to 18µA

    #d.publish(f'{device}/s/i/range/mode', 'manual')

recorder.py (1.6 KB)


    #d.publish(f'{device}/s/i/range/select', '1.8 mA')
    
    d.publish(f'{device}/s/v/range/mode', 'auto')
    d.publish(f'{device}/h/fs', SAMPLING_FREQUENCY_HZ)

    try:
        print(f'STARTING RECORDER....')
        recorder = Record(d, device, signals = 'current,voltage')
        recorder.open(filepath)
        logging.info("Recording started...")  
        time.sleep(5)
        recorder.close()
        logging.info("Recording ended...")

    except Exception as e:
        logging.error(f'Error: failed to start recording: {e}')

EDIT TO THIS POST:

I had access to a second joulescope device and tried the same recorder.py script, I did not see the same error. However I was able to reproduce the error after I set the range max and min values ( uncommented lines 34 and 35). But I could not recover operation after commenting these lines out again. It seems I must be making a mistake in setting the range max and min values and in re-setting default max and min values.

Hi @hjw - The issue is with the min / max setting. The JS220 uses the current range index (not the actual current range) for these bounds. The order is opposite what you have. 10 A is 0 and 18 µA is 5. You need to swap the min/max, like this:

    # Constrain the autoranging current limits
    d.publish(f'{device}/s/i/range/min', '180 mA')
    d.publish(f'{device}/s/i/range/max', '18 µA')

While testing this, I also found that the JS220 is not restoring these to defaults on open:

    def open(self, device_prefix, mode=None, timeout=None):
        """Open an attached device.

        :param device_prefix: The prefix name for the device.
        :param mode: The open mode which is one of:
            * 'defaults': Reconfigure the device for default operation.
            * 'restore': Update our state with the current device state.
            * 'raw': Open the device in raw mode for development or firmware update.
            * None: equivalent to 'defaults'.
        :param timeout: The timeout in seconds.  None uses the default timeout.
        """

Your code does not provide mode, which is equivalent to defaults. However, I see that the min/max settings are not being restored to the default full range.

I created issue #16.


Does swapping min & max values fix the issue for you?

1 Like

Yes! Swapping the limits does fix this issue for me!

Thank you for the speedy reply.

1 Like