PIC18F6520 delay error

Thread Starter

Stackington21

Joined Oct 16, 2015
11
Hi all

I am doing my coding subject for uni and i am struggling as to why one of my delay routines works correctly but the other does not. My first sub routine simply holds a high logic for 400ms and turns it off like so
C:
void blank()                        //SUBROUTINE PART 7

    {
        {
            Blankrelease = 1;
            Delay10KTCYx(40);
            Blankrelease = 0;
        }
}
My second subroutine is about giving an integer and sending a 6 bit logic to the machine. Basically my pulses all work and everything is fine but the delay does not seem to be the required 200ms that I need:
C:
int wind(int n)                  //SUBROUTINE PART 10
{
    int i;

    i = n/100;
    if(i > 63) return -1;
    if (i <= 0) return -1;
    {
    WindInputPulse = 1;
    Delay10KTCYx(20);
    WindInputPulse = 0;
    }
    if(LATD = i)
        BUSY = 1;

        BUSY = 0;

    return 0;
}
What i am trying to understand is how are these delays acting differently even though they are the exact same? The highest value i can put in the delay for the second subroutine is 11 which gives a 110ms delay, why is that though?

These codes are both called from the main the same way

Thanks

Mod edit: added code tags
 
Last edited by a moderator:

GopherT

Joined Nov 23, 2012
8,009
I'm not completely sure if what is happening in your program but
Look at

if(LATD = i)

Don't you think it should be,
if(LATD == i)
 

Thread Starter

Stackington21

Joined Oct 16, 2015
11
Because the send delay i do gets stuck in a constant loop. If i take one of these subroutines out of my main code, they work fine, just when both are called through the main code that the loop occurs
 

dannyf

Joined Sep 13, 2015
2,197
Because the send delay i do gets stuck in a constant loop.
What does that mean?

If i take one of these subroutines out of my main code, they work fine, just when both are called through the main code that the loop occurs
How do you know if one or more of "these subroutines" isn't working?

It doesn't seem to me that you have done substantive work to establish that the issues are what you said they are.
 

NorthGuy

Joined Jun 28, 2014
611
Nothing in these routines that could cause a constant loop. Look elsewhere.

C:
if(LATD == i) // changed to "==" from original
BUSY = 1;

BUSY = 0;
What are you trying to accomplish with these lines?
 

Thread Starter

Stackington21

Joined Oct 16, 2015
11
apologies, ive been leaving out info i shouldnt

the BUSY is a define for a different port that is required to show a logic 1 when the 6 bits is on the machine and it is winding.

Regardless of the actual subroutines, they both work when only 1 of them is called in the main function, once they are both called one after another the second one has a continuous loop for the delay
 

GopherT

Joined Nov 23, 2012
8,009
You do realize that, without curly brackets, only the first line after the IF statement is executed (or ignored). The second line after the "IF", where you have, BUSY = 0; is executed every time.
 

Thread Starter

Stackington21

Joined Oct 16, 2015
11
Not to be rude, but it is a uni assignment and has no practical applications. For what i have it does everything required for the task at hand.
My original question is about the delays, not the sub routine itself.
 

NorthGuy

Joined Jun 28, 2014
611
Regardless of the actual subroutines, they both work when only 1 of them is called in the main function, once they are both called one after another the second one has a continuous loop for the delay
Let's see if I understand this correctly. You have a program with no interrupts and the main loop which somehow call the subroutines 7 and 10. If you remove calls to sub7, then you see 200ms pulses on WindInputPulse. If you remove calls to sub10, you see 400ms pulses on BlankRelease, but with both routines on, you see BlankRelease constantly low and WindInputPulse constantly high. Correct?
 

dannyf

Joined Sep 13, 2015
2,197
My original question is about the delays,
What about the delays? You never demonstrated how the code behaved contrary to their documented behaviors.

In those kind of cases, it is best that YOU produce a minimum piece of code that demonstrates your issues.

And I can tell you with 100% confidence that the delay routines behaved as they should.
 
Top