DsPIC33CK256MP508 Clock settings with external oscillator - Curiosity board -

Started by Wimax, Dec 30, 2024, 04:25 PM

Previous topic - Next topic

Wimax

Hello everyone and all the best for the New Year!

I finally have a Curiosity board in my hands with a DsPic33CK256MP508. I hope to be able to set aside some time to familiarise myself with this little monster.
Starting with the clock settings, the Curiosity board integrates an 8 MHz oscillator connected to the OSCI/CLKI pin of the micro. I searched the site, but only found correct settings to achieve an internal 200 MHz clock using the internal oscillator, but not with an external 8 MHz oscillator...my year-end dream is to try to get off to a good start  ;D


trastikata

Hello Wimax,

here's how I set-up the 33EP devices with a small Excel spreadsheet I've prepared:

Device = 33EP...
Declare Xtal = 140
...
Config FOSC = FCKSM_CSECMD, IOL1WAY_OFF, OSCIOFNC_OFF, POSCMD_HS
Config FOSCSEL = FNOSC_PRIPLL, IESO_ON, PWMLOCK_OFF
...
Main:
    Clear
    SetCrystal()

'Set Fosc   
Proc SetCrystal()
    'Crystal = 16 MHz --> PLLDIV = 68 for 140MHz / PLLDIV = 73 For 150MHz
    CLKDIV = %0000000000000010 'PLLPRE ; PLLPOST
    PLLFBD.Byte0 = 68 '--> 140MHz Fp
    'Wait for oscillator PLL lock
    While OSCCON.5 = 0 : Wend
    DelayMS 100
EndProc   
....

Wimax

Hello Trastikata,

Thank you very much for your suggestion, after several trials...I finally got a stable configuration for the Curiosity board.
The code below sets the DSPIC33CK256MP508 @ 200 MHz using the external oscillator integrated on the board, performs a simple infinite cycle toggling 3 leds every 500 ms and transmits two simple words via the serial port.
The differences from the PIC24HJ, which I know quite a bit about, began to show up right away, not so much in performance because I haven't had a chance to try it yet, but just in understanding the internal clock architecture...definitely more advanced.


'****************************************************************
'*  Name    : Test_DSPIC33CK256MP508.BAS                        *
'*  Author  : [Max]                                             *
'*  Notice  : Copyright (c) 2024 [2022 by MAX]                  *
'*          : All Rights Reserved                               *
'*  Date    : 30/12/2024                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
 
Device = 33CK256MP508
Declare Xtal = 200

Declare Hserial_Baud = 9600 ' USART1 Baud rate @ 9.6 Kbps


PPS_Output(cOut_Pin_RP68, cOut_Fn_U1TX) ' Map UART1 TX pin to RD4
PPS_Input(cIn_Pin_RP67, cIn_Fn_U1RX)    ' Map UART1 RX pin to RD3

Config FSEC        = BWRP_OFF, BSS_DISABLED, BSEN_OFF, GWRP_OFF, GSS_DISABLED, CWRP_OFF, CSS_DISABLED, AIVTDIS_OFF
Config FOSCSEL     = FNOSC_FRC, IESO_OFF
Config FOSC        = POSCMD_EC, OSCIOFNC_ON, FCKSM_CSECMD, PLLKEN_OFF, XTCFG_G0, XTBST_ENABLE
Config FWDT        = SWDTPS_PS2147483648, RCLKSEL_LPRC
Config FPOR        = BISTDIS_DISABLED
Config FICD        = ICS_PGD3, JTAGEN_OFF, NOBTSWP_DISABLED
Config FDMT        = DMTDIS_OFF
Config FDEVOPT     = ALTI2C1_OFF,ALTI2C2_OFF,ALTI2C3_ON, SMBEN_SMBUS, SPI2PIN_PPS 
Config FALTREG     = CTXT1_OFF, CTXT2_OFF, CTXT3_OFF, CTXT4_OFF
Config FBOOT       = BTMODE_SINGLE
 
 


Main:

IntOsc_200MHz() ' Set the device to operate at 200 MHz with external oscillator
   

Inizio:       
 
   PinLow  PORTE.5
   PinHigh PORTE.6
   PinHigh PORTE.13
   DelayMS 500
   HRSOutLn "Hello 1!"
   PinLow  PORTE.6
   PinHigh PORTE.5
   PinLow  PORTE.13                                             
   DelayMS 500
   HRSOutLn "Hello 2!"

GoTo Inizio

Proc IntOsc_200MHz()


CLKDIV = $3001          ' FRCDIV FRC/1, PLLPRE 1, DOZE 1:8
PLLFBD = 100
OSCTUN = $00
PLLDIV = $21            ' POST1DIV 1:2, VCODIV FVCO/4, POST2DIV 1:1
ACLKCON1 = $0101        ' FRCSEL FRC, APLLPRE 1:1
APLLFBD1 = $C8
APLLDIV1 = $42          ' APOST1DIV 1:4, APOST2DIV 1:2, AVCODIV FVCO/4*)

Write_OSCCON($0301)
While OSCCONbits_OSWEN <> 0 : Wend      ' Wait for the clock switch to occur
While OSCCONbits_LOCK <> 1 : Wend       ' Wait for the oscillator to lock

EndProc