Invisible delay in program loop

28 Dec 2010 . Edited: 28 Dec 2010

In the simple loop below, the microsecond delays are working fine, however, between execution cycles of the main loop, there appears to be an invisible 100mS delay, which makes it too slow for my requirements. I can't see where it is coming from, any suggestions?

while (1) {
myleds = Channel;
wait_us( 880 );
myleds = 0;

wait_us( 10 );
Channel = Channel << 1;
if ( Channel > 8 ) Channel = 1;
wait_us( 10 );
}

28 Dec 2010

Do you make use of the interrupts?

Try disable interrupts.

29 Dec 2010

Ah, good idea. I'm not using them, but I haven't disabled them. Thanks.

29 Dec 2010

Hi Alex,

Unless you are explicitly using interrupts (such as InterruptIn, Ticker, Timeout objects), there won't be any interrupts firing. So you will not need to disable/do anything.

I'd therefore suspect the code is actually running normally, but it perhaps just isn't what you intended, or what you are measuring is giving you a false sense of what is going on.

If you continue to have problems, one good way to get help is to publish a (minimal) program that exibits the behavior, then posta link to it in the forum with your question/observations; just right click a program in your workspace and click publish. This means anyone can easily reproduce your problem and can likely track it down. The thing to remember is if you can't see the problem in the snippit you post, it may well be somewhere else! Publishing a complete program helps someone quickly reproduce it and lets them see the whole context, so you'll more likely get more brains helping you out!

Hope we can help track down these problems,

Simon

30 Dec 2010

It seems this delay was caused by the test of my faulty input, referred to in my thread "Digital input not configured?". My while(Trig == 1){}; was at fault.

Comment it out and the delay is gone, my code is now fully operational using an alternative input pin. Happy endings!

30 Dec 2010

Ok, here's where I discover that I'm an idiot. I'd a misconnection, the connection to my ground reference for input signals was instead going to +V. Why some inputs worked and others didn't I don't know, I'm surprised it worked at all. As usual, something very simple was screwing things up. Thanks to everyone especially Simon for their help.