Due to the U.S. Thanksgiving holiday, please expect delayed responses during the week of 11/22.

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.

EnergyTrace oddities

Other Parts Discussed in Thread: MSP430FR4133, ENERGYTRACE, MSPDS

Hi there,


while experimenting with the MSP430FR4133 Launchpad I noticed that the current measured by EnergyTrace doesn't match up with the current measured using a shunt resistor.

To extract the EnergyTrace data  in an easy way, I wrote a small application (see https://gist.github.com/carrotIndustries/f0a09b7224a2ecefb247) using the EnergyTrace functions from the libmsp430 library. I checked with CCS to confirm that my programs reads the data correctly.

The green trace shows the current directly measured by the ezFET, the blue one shows the current calculated from the energy value reported by the ezFET. The latter one resembles the current measured with a low-value (1 Ohm) shunt and a Tek 7A22 differential amplifier much more than the first one.
Can someone explain what's going on? Is this due to the measurement principle, or am I doing something wrong?

Regards,

Lukas

  • Hi Lukas,

    Your github repository is blocked by TI's web security, can you please attach the code directly to this thread? Can you also further detail the difference between the two measurements? Is the green trace directly measured by EnergyTrace while the blue is measured across the 3V3 jumper on the Launchpad? Do you have any other lab bench equipment that you could measure the current with other than the Tektronix 7A22 differential amplifier to confirm its precision? It appears that you are exiting a LPM to service an ISR or otherwise and the level of current consumption is very similar but one spends a lot more time in the active mode as compared than the other.

    Regards,
    Ryan
  • Lukas,

    Just want some clarification on your post here.

    Lukas K. said:
    green trace shows the current directly measured by the ezFET

    Current or Energy?

    Lukas K. said:
    one resembles the current measured with a low-value

    Is there a separate image for the current measured using the tek scope?


    Regards,

    William

  • Hi William,

    I've attached my code below:

    et.c
    #include <stdio.h>
    #include <unistd.h>
    #include <stdbool.h>
    #include <inttypes.h>
    #include <assert.h>
    #include <MSP430.h>
    #include <MSP430_EnergyTrace.h>
    #include <MSP430_Debug.h>
    
    typedef struct __attribute__((packed))  {
    	uint8_t id;
    	uint64_t timestamp:56;
    	uint32_t current;
    	uint16_t voltage;
    	uint32_t energy;
    } event_t;
    
    void push_cb(void* pContext, const uint8_t* pBuffer, uint32_t nBufferSize) {
    	assert(sizeof(event_t)==18);
    	assert(nBufferSize%sizeof(event_t)==0);
    	uint32_t n=nBufferSize/sizeof(event_t);
    	event_t *ev = (void*)pBuffer;
    	uint32_t i = 0;
    	while(i < n) {
    		printf("%d %" PRIu64 " %" PRIu32 " %" PRIu16 " %" PRIu32 "\n", ev->id, ev->timestamp, ev->current, ev->voltage, ev->energy);
    		
    		ev++;
    		i++;
    	}
    	//printf("pushed %d %d\n", nBufferSize, pBuffer[0]);
    }
    
    void error_cb(void* pContext, const char* pszErrorText) {
    	printf("error %s\n", pszErrorText);
    }
    
    int main()
    {
    	STATUS_T status, secure = STATUS_OK;
    	char* portNumber;
    	int  version;
    	long  vcc = 3300;
    	union DEVICE_T device;
    	portNumber = "TIUSB";
    	
    	printf("#Initializing the interface: ");
    	status = MSP430_Initialize(portNumber, &version);
    	printf("#MSP430_Initialize(portNumber=%s, version=%d) returns %d\n", portNumber, version, status);
    
    	//status = MSP430_Configure(ET_CURRENTDRIVE_FINE, 1);
    	//printf("#MSP430_Configure(ET_CURRENTDRIVE_FINE, 1) =%d\n", status);
    
    	// 2. Set the device Vcc.
    	printf("#Setting the device Vcc: ");
    	status = MSP430_VCC(vcc);
    	printf("#MSP430_VCC(%d) returns %d\n", vcc, status);
    
    	// 3. Open the device.
    	printf("#Opening the device: ");
    	status = MSP430_OpenDevice("DEVICE_UNKNOWN", "", 0, 0, DEVICE_UNKNOWN);
    	printf("#MSP430_OpenDevice() returns %d\n", status);
    	// 4. Get device information
    	status = MSP430_GetFoundDevice((char*)&device, sizeof(device.buffer));
    	printf("#MSP430_GetFoundDevice() returns %d\n", status);
    	printf("# device.id: %d\n", device.id);
    	printf("# device.string: %s\n", device.string);
    	printf("# device.mainStart: 0x%04x\n", device.mainStart);
    	printf("# device.infoStart: 0x%04x\n", device.infoStart);
    	printf("# device.ramEnd: 0x%04x\n", device.ramEnd);
    	printf("# device.nBreakpoints: %d\n", device.nBreakpoints);
    	printf("# device.emulation: %d\n", device.emulation);
    	printf("# device.clockControl: %d\n", device.clockControl);
    	printf("# device.lcdStart: 0x%04x\n", device.lcdStart);
    	printf("# device.lcdEnd: 0x%04x\n", device.lcdEnd);
    	printf("# device.vccMinOp: %d\n", device.vccMinOp);
    	printf("# device.vccMaxOp: %d\n", device.vccMaxOp);
    	printf("# device.hasTestVpp: %d\n", device.hasTestVpp);
    	
    	
    	EnergyTraceSetup ets = {  ET_PROFILING_ANALOG,                // Gives callbacks of with eventID 8
                          ET_PROFILING_1K,                   // N/A
                          ET_ALL,                             // N/A
                          ET_EVENT_WINDOW_100,                // N/A
                          ET_CALLBACKS_ONLY_DURING_RUN };           // Callbacks are continuously
    	EnergyTraceHandle ha;
    	EnergyTraceCallbacks cbs = {
    		.pContext = 0,
    		.pPushDataFn = push_cb,
    		.pErrorOccurredFn = error_cb
    	};
    	MSP430_Run(FREE_RUN, 1);
    	status = MSP430_EnableEnergyTrace(&ets, &cbs, &ha);
    	printf("#MSP430_EnableEnergyTrace=%d\n", status);
    	
    	status = MSP430_ResetEnergyTrace(ha);
    	printf("#MSP430_ResetEnergyTrace=%d\n", status);
    	
    	sleep(10);
    	
    	status = MSP430_DisableEnergyTrace(ha);
    	printf("#MSP430_DisableEnergyTrace=%d\n", status);
    	
    	printf("#Closing the interface: ");
    	status = MSP430_Close(0);
    	printf("#MSP430_Close(FALSE) returns %d\n", status);
    
    	return 0;
    }
    

    I'm receiving events of event ID 8 from the MSP430 library. The green trace is the '32 bits current' value scaled appropriately. The blue trace was obtained by differentiating the '32 bits energy' reading from the library.


    I haven't taken an image of the exact setup I got the traces from. Below is an image from a slightly different setup. (Disregard the vertical scaling, I connected the vertical output of the mainframe the 7A22 sits in to my DSO) For now, I'm not worrying about absolute readings, I was just wondering about the the totally different waveform

    I noticed another issue regarding the data from the library: the documentation (header file) states that energy is reported in units of 1uJ. My observations indicate that energy is reported in units of 100nJ. I compared the readings obtained directly from the library with the readings from EnergyTrace in CCS. Unfortunately there is no way to export EnergyTrace data in a way that it can be processed by external applications (like CSV).
    When setting MSP430_Configure(ET_CURRENTDRIVE_FINE, 1) (mislabeled as ENERGYTRACE_CURRENTDRIVE in the docs) the resolution is different, but the documentation doesn't say what it gets set to.

    Slightly offtopic: The documentation mentions a JSTATE register (seems to be related to EnergyTrace++) containing information about the power state of the CPU and peripherals, but there isn't any documentation about its contents. I really appreciate that TI open sourced the library for accessing debuggers, this makes many new applications possible. But there's more to open source than putting a tarball on your website: It would be nice if the MSPDS would be maintained on github or the like, so that issues can be tracked in a more structured way than in a forum like this and fixes and improvements are easier to contribute.

    Regards,

    Lukas

  • Lukas,

    The reason for your observation is that the transition from a rather high current to a rather small one. With the small current spike, only few ticks are counted by ET, a minimum of ticks is currently required though for the current value to be updated. Until that happens the old value is reported which would lead to what you are observing.

    Lukas K. said:
    When setting MSP430_Configure(ET_CURRENTDRIVE_FINE, 1) (mislabeled as ENERGYTRACE_CURRENTDRIVE in the docs) the resolution is different, but the documentation doesn't say what it gets set to.

    With the parameter configured to 1, the on phase of the PWM is reduced. This means less energy is put into the system with one tick, thus increasing the resolution of the measurement. With this set, you will most likely see an improvement for his issue. Due to the smaller amounts of energy put into the system, the minimum number of ticks will be reached faster and the value updated quicker.

    This also means that you won’t be able to drive higher currents with this setting.

    Lukas K. said:
    states that energy is reported in units of 1uJ. My observations indicate that energy is reported in units of 100nJ

    You are right. It is a bug and we've gone ahead and filed it.

    Lukas K. said:
    CCS. Unfortunately there is no way to export EnergyTrace data in a way that it can be processed by external applications (like CSV).

    This feature is coming into CCS.

    Regards,

    William