• AVR Freaks

LockedHot!Using legacy files for PIC32MM V2.30

Author
btremaine
Junior Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2013/08/17 14:46:34
  • Location: San Jose, CA
  • Status: offline
2019/12/08 11:54:28 (permalink)
0

Using legacy files for PIC32MM V2.30

I am writing some test code for a PIC32MM Curiosity board in which I want to see if I can access the Core Timer in the MIPS Core. I found some legacy code for a PIC32 that uses a function OpenCoreTimer() that is in compiler V1.40. I did an install of PLIB Legacy after my install of V2.30 compiler.
 
In my main() program I added the include, #include <c:/Program Files (x86)/Microchip/xc32/v1.40/pic32mx/include/plib.h> and the code does find OpenCoreTimer() but I get another error,
   In file included from timer_interrupt.c:53:0:
   c:/Program Files (x86)/Microchip/xc32/v1.40/pic32mx/include/plib.h:49:30: fatal error: peripheral/adc10.h: No such file or directory #include <peripheral/adc10.h>
 
The plib.h has the following line: #include <peripheral/adc10.h>, and in folder peripheral there is a file adc10.h. Any ideas why adc10.h is not found? I'm not using that file but it's part of the legacy V1.40 code.
 
Is there another way to access the Core Timer without going to legacy code? 
 
Thanks for any pointers ! Much appreciated.
 
 
 
 
#1

6 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6428
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Using legacy files for PIC32MM V2.30 2019/12/08 12:44:14 (permalink)
    0
    maybe

    #include <xc.h>

    volatile uint32_t coretimer = 0;
    void main(void)
    {
        Nop();
        asm volatile("mfc0 %0,$9" : "=r" (coretimer));
        while(1)
        {
            asm volatile("mfc0 %0,$9" : "=r" (coretimer));
            Nop();
        }
    }


    #2
    btremaine
    Junior Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2013/08/17 14:46:34
    • Location: San Jose, CA
    • Status: offline
    Re: Using legacy files for PIC32MM V2.30 2019/12/08 13:00:19 (permalink)
    0
    Thanks!! I'm not in a position to try this for a few hours, but I will let you know as soon as I do.
     
    #3
    andersm
    Super Member
    • Total Posts : 2696
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: Using legacy files for PIC32MM V2.30 2019/12/08 15:10:43 (permalink)
    0
    bptsjThe plib.h has the following line: #include <peripheral/adc10.h>, and in folder peripheral there is a file adc10.h. Any ideas why adc10.h is not found?

    Because your header search paths aren't set up. IIRC development of PLIB was stopped before the launch of the PIC32MM series, so it is probably not going to work anyway.
    #4
    btremaine
    Junior Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2013/08/17 14:46:34
    • Location: San Jose, CA
    • Status: offline
    Re: Using legacy files for PIC32MM V2.30 2019/12/09 08:41:01 (permalink)
    0
    Jim,
     Where can I read the documentation about the following syntax   asm volatile("mfc0 %0,$9" : "=r" (coretimer));  ??
    I have the PIC32 Ref manual and am reading through that. I interpret the above as doing something with the Count register but don't understand the %0, $9 and : "=r" syntax
     
    How would I set the Compare register to define C_VALUE? would it be asm volatile("mfc0 %0,$11" : "=r" (C_VALUE)); ?
     
    Besides modifying the compare value I will need to set the interrupt priority and enable interrupts, is that C0 register 12?
     
    Thanks,
    Brian
     
     
     
     
     
     
     
     
     
    #5
    Jim Nickerson
    User 452
    • Total Posts : 6428
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: Using legacy files for PIC32MM V2.30 2019/12/09 08:50:06 (permalink)
    0
    You might start with this post from simong123 https://www.microchip.com/forums/FindPost/1044095
    #6
    btremaine
    Junior Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2013/08/17 14:46:34
    • Location: San Jose, CA
    • Status: offline
    Re: Using legacy files for PIC32MM V2.30 2019/12/12 06:38:14 (permalink)
    0
    I finally got the code working on a Curiosity Board for PIC32MM with helpful input from simong. I'm using XC32 V2.30 and no plib.h references.
     
    Here is the code:
     

    // Necessary include files
    #include <xc.h> // automatically includes <cp0defs.h>
    #include <sys/attribs.h>
    #include <stdbool.h>
    #include <math.h>

    // #pragma config included in system.c()

    // Let compile time pre-processor calculate the CORE_TICK_PERIOD
    #define SYS_FREQ (8000000L)
    #define TOGGLES_PER_SEC 2
    #define CORE_TICK_VALUE (SYS_FREQ/1/TOGGLES_PER_SEC)

    #define LED1_PORT PORTAbits.RA0
    #define LED2_PORT PORTCbits.RC9
    //
    #define LED1_LAT LATAbits.LATA0
    #define LED2_LAT LATCbits.LATC9
    //
    #define LED1_TRIS TRISAbits.TRISA0
    #define LED2_TRIS TRISCbits.TRISC9

    volatile uint32_t coretimer = 0;
    volatile uint32_t core_tick_value = CORE_TICK_VALUE;
    volatile uint32_t reg_32bit;

    // timer_interrupt application
    int main(void)
    {
        SYSTEM_Initialize();
        
        // enable LED1 & LED2
        LED1_TRIS = 0;
        LED2_TRIS = 0;
        LED1_PORT = 0;
        LED2_PORT = 0;
        
        // configure the core timer value (100ms)
        // compare register, 'select'0
        _mtc0(11,0,core_tick_value);
        
        // set up the core timer interrupt with a priority of 2, zero sub-priority,
        // and enable
        
        IPC0bits.CTIP=2; //Core Timer Priority 2
        IPC0bits.CTIS=0; //Core Timer Sub Priority 0
        IEC0bits.CTIE=1; // Core Timer Interrupt Enable

        // enable device multi-vector interrupts
        INTCONbits.MVEC=1;

     // configure LED1 and LED2 as outputs
        LED1_TRIS = 0;
        LED2_TRIS = 0;
        LED2_LAT = 1; // turn on LED2
       
        __builtin_enable_interrupts();

        while(1){
           uint32_t timer_value= _mfc0(9,0);
           LED2_LAT ^= 1; // (5us))
            
        }

    }

    // needs <sys/attribs.h>
    void __ISR(_CORE_TIMER_VECTOR, IPL2SOFT) CoreTimerHandler(void)
    {
        // do your thing ...
     // .. Toggle the LED
        LED1_LAT ^= 1;
        
        uint32_t coretimer = _mfc0(9,0);
        uint32_t timer_compare = coretimer + core_tick_value;
        // reset core timer
        _mtc0(11,0,timer_compare);

        // clear the interrupt flag
        IFS0CLR = _IFS0_CTIF_MASK; /* Clear the interrupt flag */
    }

    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5