2

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!! ;)

  • 1
    Indeed. The "30" in there refers to the pic30 series, the first of the 16-bit ones. But this question is way to generic, since that header is a mix of all kinds of things. Some might have direct equivalents, some not. What do you exactly use from that header? – Marco van de Voort May 08 '15 at 15:36
  • __delay32 call the most important thing. – vincenzorochetta May 08 '15 at 15:52
  • @MarcovandeVoort I found your comment by searching about why the heck the library for the dsPIC33 I am using is called pic30--now it makes sense! After finding your comment, I tried searching the web for the pic30 and can't find almost anything, is this an ancient chip? –  Jul 15 '15 at 20:39
  • No, they are still available, as most of Microchip's offerings http://www.microchip.com/pagehandler/en-us/family/16bit/architecture/dspic30f.html?f=3 IIRC the ds- prefix was added later. – Marco van de Voort Jul 17 '15 at 06:58

1 Answers1

1

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.
            }
        }
    }

}

blsmit5728
  • 434
  • 3
  • 11