News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

PIC12F1572 at 32Mhz

Started by rick.curl, Today at 12:03 AM

Previous topic - Next topic

rick.curl

Hi folks- It's been a while since I've done much coding, so I seem to be starting out as a noob all over again. I'm trying to run a PIC12F1572 at 32Mhz using the internal oscillator, but I can't seem to get it to go beyond 8Mhz. The OSCSTAT bits tell me that the PLL is enabled, but none of the internal oscillators indicate that they are ready.

What am I doing wrong?

Snippet of the code:
Device  12F1572

    Xtal 32
    Reminders off
'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_ON, CLKOUTEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, BORV_LO, LPBOREN_OFF, LVP_OFF

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------
    Reminders On

    osccon = %11110010
    CM1CON0 = 01  'comparator off
    TRISa = %11000000
    ANSELa = 0           'all pins digital


   porta = 0   'set all pins to zero
   DelayMS 100  'wait a bit before starting

Mainloop:
    toggle porta.0
    delayms 1000
    goto mainloop

I have an LED attached to portA.0 and it is blinking 4 seconds on and 4 seconds off.

Any guidance would be greatly appreciated!!

-Rick

Pepe

#1
;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 12F1572

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, BOREN_OFF, CLKOUTEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, BORV_LO, LPBOREN_OFF, LVP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Declare Xtal = 32
Declare Optimiser_Level = 3
Declare Create_Coff On
Declare Watchdog off
Declare Dead_Code_Remove = 1        ' Remove dead code
Declare Reminders Off
Declare Hints Off

OSCCON = 0b11110000

While OSCSTAT.6 <> 0
Wend


TRISA = 0
PORTA = 0    'set all pins to zero

DelayMS 100  'wait a bit before starting

Do
    Toggle PORTA.0
    DelayMS 1000
Loop

rick.curl

Thanks, Pepe- But on the real hardware it's still running at 8 Mhz. The LED is blinking 4 seconds on and 4 seconds off. This is getting interesting.......

Pepe

#3
Put OSCCON = 0b11110000

The 4x PLL is not available for use with the internal
oscillator when the SCSx bits of the OSCCON register
are set to '1x'. The SCSx bits must be set to '00' to use
the 4x PLL with the internal oscillator.

rick.curl

Quote from: Pepe on Today at 01:54 AMPut OSCCON = 0b11110000

The 4x PLL is not available for use with the internal
oscillator when the SCSx bits of the OSCCON register
are set to '1x'. The SCSx bits must be set to '00' to use
the 4x PLL with the internal oscillator.
That did it!  I misread the spec sheet.
Thank you Pepe!

-Rick

top204

#5
Good to see you back Rick.

Below is a standard code template I have created to run a PIC12F1572 device at 32MHz using its internal oscillator. It has been tested on a real device, but make sure you are using a PIC12F1572 device, because the PIC12LF1572 device seems to be slightly different with some peripheral pins, according to the datasheet.

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A PIC12F1572 code listing template, for the device to operate at 32MHz using its internal oscillator.
' The code has been tested on a real PIC12F1572 device, however, a PIC12LF1572 device, has slight differences.
' So always read its datasheet.
'
' Written by Les Johnson for the Positron8 BASIC compiler.
' https://sites.google.com/view/rosetta-tech/positron-compilers-experimenters-notebook
'
    Device = 12F1572                                                ' Tell the compiler what device to compile for
    Declare Xtal = 32                                               ' Tell the compiler what frequency the device will be operating at (in MHz)
    Declare Auto_Heap_Arrays = On                                   ' Tell the compiler to create arrays above standard variables, so assembler code is more efficient
    Declare Auto_Heap_Strings = On                                  ' Tell the compiler to create Strings above standard variables, so assembler code is more efficient
    Declare Auto_Variable_Bank_Cross = On                           ' Tell the compiler to create any multi-byte variables in the same RAM bank. For more efficiency
'
' Setup the USART
'
    Declare Hserial1_Baud = 9600                                    ' Set the Baud rate for the USART
    Declare HSerout1_Pin  = PORTA.0                                 ' Set the USART TX pin for a PIC12F1572
    Declare HSerin1_Pin   = PORTA.1                                 ' Set the USART RX pin for a PIC12F1572
'
' Create any global variables and constants and aliases here
'

'-------------------------------------------------------------------------------------
' The main program starts here
' Transmit text to a serial terminal, to make sure the device is operating at the correct frequency.
'
Main:
    Setup()                                                         ' Setup the program and any peripherals

    Do                                                              ' Create a loop
        HRSOut1Ln "Hello World"                                     ' Transmit the text "Hello World"
        DelayMS 500                                                 ' Create a delay between transmissions, so they do not flood the serial terminal
    Loop                                                            ' Do it forever

'-------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_32MHz()                                                     ' Setup the internal oscillator to operate at 32MHz
'
' Extra setups here, when required...
'
EndProc

'-------------------------------------------------------------------------------------
' Setup the internal oscillator to operate at 32MHz on a PIC12F1572 device
' Input     : None
' Output    : None
' Notes     : None
'
Proc Osc_32MHz()
    OSCCON  = %01110000                                             ' SPLLEN disabled. IRCF is 8MHz
    OSCTUNE = %00000000
    BORCON  = %00000000                                             ' SBOREN and BORFS disabled
    DelayMS 100                                                     ' A small delay to wait for the PLL to stabilise
EndProc

'-------------------------------------------------------------------------------------
' Set the config fuses for internal oscillator on a PIC12F1572 device.
' The OSC pins are general purpose I/O
'
    Config1 FOSC_INTOSC,_                                           ' INTOSC oscillator. I/O function on CLKIN pin
            WDTE_OFF,_                                              ' Watchdog Timer disabled
            PWRTE_OFF,_                                             ' Power-up Timer disabled
            MCLRE_ON,_                                              ' MCLR/VPP pin function is MCLR
            CP_OFF,_                                                ' Program memory code protection is disabled
            BOREN_ON,_                                              ' Brown-out Reset enabled
            CLKOUTEN_OFF                                            ' CLKOUT function is disabled

    Config2 WRT_OFF,_                                               ' Flash Memory Self-Write protection off
            PLLEN_ON,_                                              ' 4xPLL enabled
            STVREN_ON,_                                             ' Stack Overflow or Underflow will cause a reset
            BORV_LO,_                                               ' Brown-out Reset Voltage, low trip point selected
            LPBOREN_OFF                                             ' Low Power Brown-Out reset is disabled

I will be adding some standard code templates in the compiler's "Samples" folder in future compiler updates.

Regards
Les

streborc

Thanks for this.  I find oscillator configurations one of the most complicated and inconsistent aspects of PICs.  Frequently, I have had to set CLKOUTEN to On and hang an o'scope on the output pin to see if I've set the frequency correctly.

John Lawton

Yes I've done that sometimes.

It'as worth mentioning that John B's Positron Studio has his brilliant Fuse Configurator built in, in my opinion it's worth installing his editor just for that feature, it's such a time saver.

John L
-----------------------------------------------------------------------------------------
Amicus 8 and 16A/16B dev boards
Especially created for Positron development
https://www.easy-driver.co.uk/Amicus

streborc

The fuse configurator is a terrific tool, as is JohnB's latest edition of Positron Studio which I installed just a couple weeks ago.  I especially like the addition of the brackets that mark the loop commands.