vincenzorochetta
vincenzorochetta

Reputation: 41

Use libpic30.h with PIC32

Now I'm developing my own port to PIC32 and I need to use libpic30.h library. I have been reading about it and looking for the same library to PIC32 (starter kit III PIC32MX450/470 MCU) and I think it doesn't exist. That's right? If it exist wonderful!

libpic30.h code: https://code.google.com/p/uavfirmware/source/browse/UAVFirmware/include/libpic30.h?r=1db3ec8e9015efb837b0d684c98204317ea2efd5

In this case, libpic30.h is not comptabible with PIC32 right? I don't know, very well, how is the best way to do this port in this case?... I'm very lost!

Thanks for you knowledge!! ;)

Upvotes: 2

Views: 2901

Answers (1)

blsmit5728
blsmit5728

Reputation: 444

Yeah first off you can't use libpic30.h. The compiler shouldn't let you use it easily. You'll want to use xc.h and follow that through for your appropriate PIC32 device. I'm not sure where the delay function lies but there is one somewhere down in there close to what you want. If you can't find it. Look in Tick.c for the TCP/IP legacy libraries there is a written delay in there for 32 bit devices.

void SSTDelay10us(U32 tenMicroSecondCounter)
{
    volatile S32 cyclesRequiredForEntireDelay;
    int clock;
    clock = 80000000;

    if (clock <= 500000) //for all FCY speeds under 500KHz (FOSC <= 1MHz)
    {
        //10 cycles burned through this path (includes return to caller).
        //For FOSC == 1MHZ, it takes 5us.
        //For FOSC == 4MHZ, it takes 0.5us
        //For FOSC == 8MHZ, it takes 0.25us.
        //For FOSC == 10MHZ, it takes 0.2us.
    }
    else
    {
        //7 cycles burned to this point.
        //We want to pre-calculate number of cycles required to delay 10us *  
        // tenMicroSecondCounter using a 1 cycle granule.
        cyclesRequiredForEntireDelay = (S32)(clock / 100000) * tenMicroSecondCounter;
        //We subtract all the cycles used up until we reach the 
        //while loop below, where each loop cycle count is subtracted.
        //Also we subtract the 5 cycle function return.
        cyclesRequiredForEntireDelay -= 24; //(19 + 5)
        if (cyclesRequiredForEntireDelay <= 0)
        {
            // If we have exceeded the cycle count already, bail!
        }
        else
        {
            while (cyclesRequiredForEntireDelay > 0) //19 cycles used to this point.
            {
                cyclesRequiredForEntireDelay -= 8; //Subtract cycles burned while doing each delay stage, 8 in this case.
            }
        }
    }

}

Upvotes: 1

Related Questions