• AVR Freaks

Hot!PIC24FJ256GA705 hangs on second attempt to switch to FRCPLL

Author
cea
Senior Member
  • Total Posts : 99
  • Reward points : 0
  • Joined: 2006/02/17 00:01:25
  • Location: 0
  • Status: offline
2020/07/25 22:23:17 (permalink)
0

PIC24FJ256GA705 hangs on second attempt to switch to FRCPLL

This post is for what I believe is a silicon bug in the PIC24FJ256GA705 and PIC24FJ256GA702 controllers.
 
I have only been able to confirm this using the revision A3 silicon.
 
A complete description of the fault is in the comments of this demo code:
/*
 * File:   main.c
 * Author: cea
 * Target: PIC24FJ256GA705
 * Compiler: XC16 v1.41
 * IDEP MPLABX v5.40
 *
 *                                                               PIC24FJ256GA705
 *                 +------------+                 +------------+                 +------------+                 +-------------+
 *     MISOB <>  1 : RB9/RP9    :      CSnB <> 13 : RA10/RP28  :      SDAA <> 25 : RB2/RP2    : 32.76K8Hz <> 37 : RA4/SOSCO   :
 *      SCKB <>  2 : RC6/RP22   :           <> 14 : RA7        :      SCLA <> 26 : RB3/RP3    :      LED2 <> 38 : RA9         :
 * LED_RBG_B <>  3 : RC7/RP23   :     MOSIA <> 15 : RB14/RP14  :       ANB <> 27 : RC0/RP16   :      PWMA <> 39 : RC3/RP19    :
 *      INTA <>  4 : RC8/RP24   :      SCKA <> 16 : RB15/RP15  :       ANA <> 28 : RC1/RP17   :      PWMB <> 40 : RC4/RP20    :
 *      CSnA <>  5 : RC9/RP25   :       GND -> 17 : AVSS       :     MOSIB <> 29 : RC2/RP18   :      INTB <> 41 : RC5/RP21    :
 *       GND ->  6 : VSS        :       3v3 -> 18 : AVDD       :       3v3 -> 30 : VDD        :       GND -> 42 : VSS         :
 *      10uF ->  7 : VCAP       :        S3 -> 19 : MCLR       :       GND -> 31 : VSS        :       3v2 -> 43 : VDD         :
 *        S1 <>  8 : RA11/RPI29 :        S2 <> 20 : RA12/RPI30 :      RSTA <> 32 : RA13/RPI31 :      RSTB <> 44 : RA14/RPI32  :
 *       PGD <>  9 : RB10/PGD2  : LED_RBG_R <> 21 : RA0/RP26   :           <> 33 : RA2/OSCI   :      SDAB <> 45 : RB5/PGD3    :
 *       PGC <> 10 : RB11/PGC2  : LED_RBG_G <> 22 : RA1/RP27   :           <> 34 : RA3/OSCO   :      SCLB <> 46 : RB6/PGC3    :
 *       POT <> 11 : RB12/RP12  :       TXA <> 23 : RB0/PGD1   :      LED1 <> 35 : RA8        :       TXB <> 47 : RB7/RB7/INT0:
 *     MISOA <> 12 : RB13/RP13  :       RXA <> 24 : RB1/PGC1   : 32.768KHz <> 36 : RB4/SOSCI  :       RXB <> 48 : RB8/RP8     :
 *                 +------------+                 +------------+                 +------------+                 +-------------+
 *                                                                 TQFP-48
 * 
 *
 * Created on July 25, 2020, 8:05 PM
 *
 * Code runs on DM240016 / PIC24FJ256GA7 Curiosity Development Board
 *
 * Description:
 *
 *      This application demonstrates a silicon bug in the
 *      PIC23FJ256GA705 controller. This bug is present in
 *      the PIC23FJ256GA702 controller as well.
 *
 * This is what the starter kit's PKOB thinks about my PIC23FJ256GA705:
 *
 *      *****************************************************
 *     
 *      Connecting to Starter Kit on Board...
 *     
 *      Currently loaded firmware on Starter Kit on Board
 *      Firmware Suite Version.....01.56.07
 *      Firmware type..............dsPIC33F/24F/24H
 *     
 *      Target voltage detected
 *      Target device PIC24FJ256GA705 found.
 *      Device Revision ID = 3
 *      DEVSN0 = 00000000
 *      DEVSN1 = 00000000
 *
 * Silicon bug:
 *  When the configuration words do not select the FRCPLL
 *  as the default primary system oscillator, a second
 *  attempt to select the FRCPLL after power on results
 *  in a lock up or oscillator fail trap.
 *
 * Clearing the fault:
 *  Asserting MCLR will not clear this fault. Only a
 *  power cycle or using the MCLR/PGC/PGD to exit ICSP
 *  mode will clear this fault.
 *
 * Workaround:
 *  Select FRCPLL as the default primary system oscillator,
 *  then switching to FRC and back to FRCPLL mode will work.
 *
 */
#define SHOW_SILICON_BUG
#if defined(SHOW_SILICON_BUG)
#pragma config FNOSC = FRC
#else
#pragma config FNOSC = FRCPLL
#endif
       
#pragma config BWRP = OFF, BSS = DISABLED, BSEN = OFF, GWRP = OFF
#pragma config GSS = DISABLED, CWRP = OFF, CSS = DISABLED, AIVTDIS = OFF
#pragma config BSLIM = 0x1FFF, PLLMODE = PLL4X, IESO = OFF
#pragma config POSCMD = NONE, OSCIOFCN = ON, SOSCSEL = ON
#pragma config PLLSS = PLL_PRI, IOL1WAY = OFF, FCKSM = CSECME
#pragma config WDTPS = PS2048, FWPSA = PR128, FWDTEN = ON, WINDIS = OFF
#pragma config WDTWIN = WIN25, WDTCMX = LPRC, WDTCLK = LPRC, BOREN = OFF
#pragma config LPCFG = OFF, DNVPEN = ENABLE, ICS = PGD2, JTAGEN = OFF
#pragma config ALTCMPI = DISABLE, TMPRPIN = OFF, SOSCHP = OFF, ALTI2C1 = ALTI2CEN
       
#include "xc.h"
#include <stdio.h>
       
#define FSYS        (32000000L)
#define FCY         (FSYS/2)    /* Instruction Cycle Frequency */
/*
 * WARNING: Not a portable function.
 *          Maximum 16MHz instruction cycle clock.
 *          Minimum  8Khz instruction cycle clock.
 */
void delay_ms( unsigned long delay )
{
    do
    {
        asm("repeat  %0\n nop\n":: "r" (FCY/1000L-7L));
    } while(delay--);
}
/* 
 * Trap Handler for oscillator fail
 */ 
void __attribute__((interrupt,no_auto_psv)) _OscillatorFail(void)
{
    for(;;)
    {
        /* Flash the RED RGB LED from the oscillator fail trap */
        INTCON1bits.OSCFAIL = 0;
        LATAbits.LATA0  = 1;     /* turn RED LED on */
        delay_ms(1);
        ClrWdt();
        LATAbits.LATA0  = 0;     /* turn RED LED off */
        delay_ms(199);
        ClrWdt();
    }
 }
/*
 * Initialize this PIC
 */
void PIC_Init(void)
{
    unsigned short ClockSwitchTimeout;
   
    /*
     * Disable all interrupt sources
     */
    __builtin_disi(0x3FFF); /* disable interrupts for 16383 cycles */
    IEC0 = 0;
    IEC1 = 0;
    IEC2 = 0;
    IEC3 = 0;
    IEC4 = 0;
    IEC5 = 0;
    IEC6 = 0;
    IEC7 = 0;
    __builtin_disi(0x0000); /* enable interrupts */
   
    ANSA   =  0x0000; /* Set for digital I/O */
    ANSB   =  0x1000; /* Set for digital I/O */
    ANSC   =  0x0000; /* Set for digital I/O */
   
    _NSTDIS = 1;    /* disable interrupt nesting */
       
    LATA = 0;
    LATB = 0;
    LATC = 0;
   
    TRISA   = 0xFCFC;
    TRISB   = 0xFFFF;
    TRISC   = 0xFF7F;
   
    /* enable pull-down on digital inputs */
    IOCPUA  = 0;
    IOCPDA  = TRISA & ~ANSA;
    IOCPUB  = 0;
    IOCPDB  = TRISB & ~ANSB;
    IOCPUC  = 0;
    IOCPDC  = TRISC & ~ANSC;
   
    CLKDIV  = 0x0000; /* set for FRC clock 8MHZ operations */
   
    /*
     * At Power On Reset the configuration words set the system clock
     * to use the FRC oscillator. At this point we need to enable the
     * PLL to get the system clock running at 32MHz.
     *
     * Clock switching on the 24FJ family with the PLL can be a bit tricky.
     *
     * First we need to check if the configuration words enabled clock
     * switching at all, then turn off the PLL, then setup the PLL and
     * finally enable it. Sounds simple, I know. Make sure you verify this
     * clock setup on the real hardware.
     */
       
    if(!OSCCONbits.CLKLOCK) /* if primary oscillator switching is unlocked */
    {
        LATAbits.LATA8 = 1;    /* turn on LED for debug, show we are switching to FRC */
        /* Spin wait so LED can be seen */
        for(ClockSwitchTimeout=60000; ClockSwitchTimeout;--ClockSwitchTimeout) Nop();
       
        /* Select primary oscillator as OSCFDIV */
        __builtin_write_OSCCONH(0b000);
       
        /* Request switch primary to new selection */
        __builtin_write_OSCCONL(OSCCON | (1 << _OSCCON_OSWEN_POSITION));
       
        /* wait, with timeout, for clock switch to complete */
        for(ClockSwitchTimeout=10000; ClockSwitchTimeout;--ClockSwitchTimeout) if (OSCCONbits.OSWEN != 1) break;
        if(ClockSwitchTimeout != 0) LATAbits.LATA8 = 0;    /* turn off LED for debug, show that switch to FRC worked */
       
        LATAbits.LATA9 = 1;    /* turn on LED for debug, show we are trying to switch to FRCPLL */
        /* Spin wait so LED can be seen */
        for(ClockSwitchTimeout=60000; ClockSwitchTimeout;--ClockSwitchTimeout) Nop();
       
        /* Select primary oscillator as FRCPLL */
        __builtin_write_OSCCONH(0b001);
       
        /* Request switch primary to new selection */
        __builtin_write_OSCCONL(OSCCON | (1 << _OSCCON_OSWEN_POSITION));
       
        /* wait, with timeout, for clock switch to complete */
        for(ClockSwitchTimeout=10000; ClockSwitchTimeout;--ClockSwitchTimeout) if (OSCCONbits.OSWEN != 1) break;
       
        /* wait, with timeout, for the PLL to lock */
        for(ClockSwitchTimeout=10000; ClockSwitchTimeout;--ClockSwitchTimeout) if (OSCCONbits.LOCK) break;
       
        if(ClockSwitchTimeout != 0) LATAbits.LATA9 = 0;    /* turn off LED for debug, show that switch to FRCPLL worked */
       
        /* at this point the system oscillator should be 32MHz */
    }
}
/*
 * Main Application
 */
int main(void)
{
    unsigned short count;
   
    PIC_Init();
   
    /* Main application loop */
    for(count = 0; count<10; count++)
    {
        /* Flash the GREEN RGB LED from the application loop */
        LATAbits.LATA1  = 1;     /* turn GREEN LED on */
        delay_ms(4);
        ClrWdt();
        LATAbits.LATA1  = 0;     /* turn GREEN LED off */
        delay_ms(796);
        ClrWdt();
    }
    __asm("reset");
    return 0;
}

I would really appreciate if any member can tell me I've done something stupid,  reproduce this fault or check the revision A4 silicon to see if it has been fixed.
 
Submitted as support case# 00533568 too.
post edited by cea - 2020/08/03 07:24:15
#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5