Community
cancel
Showing results for 
Search instead for 
Did you mean: 
IIstv
New Contributor I
1,126 Views

MCU: unexpected delays in loops

I am writing a serial interface to a HX711 IC. It has a very simple serial protocol: a data and a clock line. Every positive clock pulse will put a data bit on the output of the HX711.

Data is 24 bits, but 1 to 3 extra pulses will have to follow to set some parameters of the HX711.

I wrote an MCU function, to send 24 bits in a for loop, and read every bit. Then the configure bits in another loop.

(The logical levels are inverted for the single transistor level-shifter.)

The efficient pulse status between the set and clear instractions is measured about 10us on the oscilloscope.

But once in a while a clock pulse will go wider in the data-reading for loop, randomly in H or L phase. Looks like something suspends the MCU. The lengthened pulse can be some 50-100us (hard to catch it).

The longer cycle is a standby instruction for the HX711, so it is not welcome.

What can be the reason of the timing disturbance in such simple loop?

bool hx711_read(char *buffer, int data_port, int clock_port, int pulses)

{

if (!gpio_read(data_port)) return false; // hx711 not ready

weight_t weight = 0;

int i;

for (i = 0; i < 24 ; ++i) {

gpio_write(clock_port, 0);

gpio_write(clock_port, 1);

weight <<= 1;

if(!gpio_read(data_port)) weight++;

}

// The 24 reading pulses were completed.

// The rest will adjust the HX711 for the next reading.

int j;

for (j = 0; j < pulses-24; ++j) {

gpio_write(clock_port, 0);

gpio_write(clock_port, 1);

}

// We have the result in binary, now convert it to string.

weight_to_hex((unsigned long) weight, buffer);

return true;

}

7 Replies
IIstv
New Contributor I
52 Views

I reduced the MCU program to one level: two infinit loops: one triggers the other in every 200ms, and the second creats a burs of 25 pulses 10us long.

Every once in about 2-3s there is a longer pulse - about 50-60 us.

What can be the reason? Is there a way to control the gpio directly (like in Yocto) mapped in Viper?

10us is long enough for a minimum length of a pulse.

idata
Community Manager
52 Views

Hi,

 

 

Have you tried to debug the code to try to find more information? There's a guide on how to debug here https://software.intel.com/en-us/node/557354# Getting_debug_messages_from_the_MCU https://software.intel.com/en-us/node/557354# Getting_debug_messages_from_the_MCU .

 

 

There's also helpful information in edison-mcusdk-win64-1.0.10/docs/api_doc/html/globals.htm . In this file you'll find all the functions that can be used in the MCU. If the debugging determines an issue at some point in the code you can see in this link if the function was properly configured.

 

 

Sergio

 

IIstv
New Contributor I
52 Views

Thanks, but I don't think debugging helps here, because that changes timing conditions, and that is the issue in question here. I think the reason of the phenomenon is not in user space here, but in the OS (Viper?).

I wrote the simplest program to reproduce the long pulses:

# include "mcu_api.h"

# include "mcu_errno.h"

void mcu_main()

{

gpio_setup(48, 1);

while (1)

{

gpio_write(48,1);

gpio_write(48,0);

}

}

(Sorry, but syntax highlight disappeared from the editor header :O )

Set the scope to catch pulses longer that 25us:

Then setting the trigger to falling edges:

So it can occure in any state of the loop.

The wider pulses uccure 2-3 times a second. Not a big issue, but I measure with 10Hz, and thus the interface quite frequently hits it.

It seems to me very much like an interrupt somewere in the deep layer of the OS, and it would be very nice to disable it. Could I find some info about the OS of the MCU?

idata
Community Manager
52 Views

There's no way to access any of the features on the MCU SDK beyond what's already on the Eclipse IDE.

 

The only resources available for the MCU are in the Eclipse IDE and in https://software.intel.com/en-us/creating-applications-with-mcu-sdk-for-intel-edison-board https://software.intel.com/en-us/creating-applications-with-mcu-sdk-for-intel-edison-board .

 

 

We'll run some additional tests and let you know our results.

 

 

Sergio

 

IIstv
New Contributor I
52 Views

Thank you, looking forward to hearing from you later.

Should we close this topic for now?

Istvan

idata
Community Manager
52 Views

We were able to reproduce this behavior using the latest release (3.0). We tested DIG7, DIG2 and DIG3 with similar results. The wider pulses you're observing on the MCU program is a known issue. There's no fix at the moment for this.

 

 

-Sergio

 

IIstv
New Contributor I
52 Views

Thank you.

Istvan

Reply