• MPLAB XC16
  • dsPIC33CH valid slave PLL setting solved!
2020/11/18 13:06:56
oliverb
TLDR: I hadn't enabled the slave PLL mode in the master project, since all the other PLL settings were located in the slave project and it wasn't obvious that I needed to. Having updated it things work as expected.
 
OK so I improvised something that should flash a LED once per second. Running from the oscillator it is actually taking twice as long though, but the problem is that if I try to use a PLL setting it doesn't run at all.
 
I tried adding master settings to boost the frequency to 40MHz and I get the same period, so I think that is working out.
I try adding slave settings and I get nothing on that side at all. Right now I'm using MCC, though I'm thinking about lifting the "board support package" files from the demo and seeing how they work instead.
 
#include "mcc_generated_files/mcc.h"
#define FCY _XTAL_FREQ
#include <libpic30.h>

I added that to allow me to use software delays. Thinking about it FCY is the instruction speed which should be XTAL/2 so that explains delays being off but not why the program doesn't start at all.
/**
  Section: Included Files
*/
#include "mcc_generated_files/mcc.h"
#define FCY _XTAL_FREQ
#include <libpic30.h>

/*
                         Main application
 */
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    while (1)
    {
        LED_SLAVE_SetHigh();
        __delay_ms(500);
        LED_SLAVE_SetLow();
        __delay_ms(500);
        // Add your application code
    }
    return 1;
}
/**
 End of File
*/


Attached Image(s)

2020/11/18 15:49:46
davea
#define _XTAL_FREQ 32000000 this is in the device_config.h make sure something is there
thats what sets the delay function
why is feed back at 200 = 1600mhz 
 
2020/11/18 23:57:54
oliverb
_XTAL_FREQ is set by MCC already.
I lifted the feedback value from some other code I think it was the demo. I've also tried 150.
 
Here's the code from the demo:
 
    //Switch to FRC (no divider, no PLL), assuming we aren't already running from that.
    if(OSCCONbits.COSC != 0b000)
    {
        __builtin_write_OSCCONH(0x00); //NOSC = 0b000 = FRC without divider or PLL
        __builtin_write_OSCCONL((OSCCON & 0x7E) | 0x01); //Clear CLKLOCK and assert OSWEN = 1 to initiate switchover
        //Wait for switch over to complete.
        while(OSCCONbits.COSC != OSCCONbits.NOSC);
    }
    
    //Clock switch to 200MHz CPU freq (100MIPs) from FRC+PLL (ex: ((8MHz * 200) / 4) / 2 = 200MHz)
    // Configure PLL prescaler, both PLL postscalers, and PLL feedback divider
    CLKDIVbits.PLLPRE = 1; // N1=1
    PLLFBDbits.PLLFBDIV = 200; // M = 200 (ex: FVCO = 1600MHz = 8MHz * 200)
    PLLDIVbits.POST1DIV = 4; // N2=4 (1600MHz / 4, followed by fixed / 2 = 200MHz)
    PLLDIVbits.POST2DIV = 1; // N3=1
    // Initiate Clock Switch to FRC with PLL (NOSC = 0b001)
    __builtin_write_OSCCONH(0x01);
    if(OSCCONbits.COSC != OSCCONbits.NOSC)
    {
        __builtin_write_OSCCONL((OSCCON & 0x7F) | 0x01); //Assert OSWEN and make sure CLKLOCK is clear, to initiate the switching operation
        // Wait for clock switch to finish
        while(OSCCONbits.COSC != OSCCONbits.NOSC);
    }

 
Unfortunately I'm not even 100% sure the demo works as the slave side of the demo appears to be entirely devoted to the DC-DC converter, all the LED activity is managed by the master, so apart from the output going to 3.3V I don't know if it is functional. I'm only assuming 3.3V is its intended output and not "float".
 
OK pulling the "Vfb gain" link caused the voltage to rise, so I assume that means it is in closed loop, and therefore that the "dsp" part must be running.
 
2020/11/19 04:28:22
Mysil
Hi,
A PLL circuit is only able to function within a limited frequency range.
According to the datasheet, that is between minimum 400 MHz and 1600 MHz maximum.
Since there seem to be a problem,
try to aim for somewhere in the middle of the range:  PLLFBDIV = 100;   /* Try 8 MHz * 100 = 800 MHz VCO frequency. */
That means try selecting   1:100 FeedBack in MCC GUI
You may try keeping the dividers as they are, or try with some other  selection for Postscaler2
 
    Mysil
 
2020/11/19 07:14:43
oliverb
When I get back onto it I think I'll try copying the master side settings, I think the settings give 80MHz "XTAL" so it won't be running the core flat out but it'll be something.
 
I'd like to copy the demo but it is "bsp" not "mcc" so I can't just clone the settings. I've tried pasting in the code that appears to set the PLL and the code doesn't run. I'm currently assuming it gets stuck on the "while" loop at the end but I don't know that.
 
OK so I'm using the same settings as the master now, and as an experiment I commented out the two "while" loops that wait for completion. It now flashes on a 10s cycle meaning it is still running on FRC, it never switched over to PLL.
 
 
 
 
2020/11/20 09:07:05
oliverb
OK I found it, turns out the important slave PLL enable bits are in the master project (who knew). BTW enable "clock switching" too.
 
Maybe there was a warning message, if so I didn't see it because some messages come up every time and nothing will clear them.
 

Attached Image(s)

© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account