12F1840 HPWM HS crystal (32 MHz) vs internal oscillator (8MHz + PLL)

Started by palamont, Feb 06, 2022, 11:53 AM

Previous topic - Next topic

palamont

Hi guys, I encounter a strange problem with a 12F1840 : I've written two very small programs to drive, by radio (XBEE), a LED ribbon. One transmitter programm, and one receiver program.

All is running perfectly with crystals 32 MHz, TX side and RX side, (Config1 FOSC_HS, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF, LVP_OFF)

BUT, when I modify the fuses for using Internal oscillator & PLL (to avoid the use of a crystal), (Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, LVP_OFF), I've no more signal at the output of the 12F1840 !

I think that I'm making a mistake, but where ?

My RX program :

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

Device = 12F1840

Config1 FOSC_HS, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF, LVP_OFF

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

Declare Xtal 32 '(: OSCCON2 = $F0 : OSCTUNE = $40       ;horloge interne 64MHz)
Declare CCP1_Pin PORTA.2

ADCON0 = $01 : ADCON1 = $F0
 
TRISA = $09

Dim taux As Byte

;-----------------------------------------------------------------------------------------------------------------
       
bouclePWM:

        SerIn PORTA.3,84,[taux]     

        HPWM 1,taux,10000   
       
        GoTo bouclePWM

If you could help me, it would be with a great pleasure.

Thanks, and sorry for my bad english ;-) !


trastikata

HI,

I think you are mixed up with the settings. Not sure why you are touching the OSCTUNE register. As per datasheet, all you need for 32 MHz internal oscillator is this:

Device = 12F1840

Config1 FOSC_INTOSC ...
Config2 PLLEN_ON ...

Declare Xtal 32

OSCCON = %11110000 

palamont

Hi, the commented indication of the OSCTUNE was about an other program.

I've inserted the OSCCON value ($F0), and all is running well. But why ? The documentation of the 12F1840 indicates : (file enclosed).

Unless I'm mistaken, the indications of this register are already in the fuses configuration : FOSC_INTOSC and PLLEN_ON


Thanks for your help. Best regards




trastikata

Please refer to the same datasheet, Page 54, section 5.2.2.6 - 32 MHz Internal Oscillator Frequency Selection.

palamont

I've introduced the same modification (OSCCON) TX side, and all is OK, but with the same remark as for the RX side (OSCCON register vs fuses configuration).

In any case thanks a

tumbleweed

QuoteI've inserted the OSCCON value ($F0), and all is running well. But why ?
The int osc configuration can be confusing.

You can set the CONFIG bits to enable the INTOSC and PLLEN, but what you find if you read through the datasheet closely is that the default setting for the OSCCON.IRCF bits is 0111, which gives a freq of 500khz at any reset.

You have to change the freq setting using the OSCCON reg to get the desired INTOSC freq.


okmn

The problem is fixed?

Can you try considering the following lines


oscilator selct ...INTOSC
systemclock ...FOSC
internal clock ...8mhz
pll enable ..yes
32mhz (4xPLL)

OSCCON = 0x70
OSCTUNE = 0x00
BORCON = 0x00
PLLR == 0
WDTCON = 0x16


FOSC = INTOSC    // Oscillator Selection->INTOSC oscillator: I/O function on CLKIN pin
WDTE = OFF       // Watchdog Timer Enable->WDT disabled
PWRTE = OFF      // Power-up Timer Enable->PWRT disabled
MCLRE = OFF      // MCLR Pin Function Select->MCLR/VPP pin function is digital input
CP = OFF         // Flash Program Memory Code Protection->Program memory code protection is disabled
CPD = OFF        // Data Memory Code Protection->Data memory code protection is disabled
BOREN = OFF      // Brown-out Reset Enable->Brown-out Reset disabled
CLKOUTEN = OFF   // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
IESO = ON        // Internal/External Switchover->Internal/External Switchover mode is enabled
FCMEN = ON       // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled

CONFIG2
WRT = OFF        // Flash Memory Self-Write Protection->Write protection off
PLLEN = ON       // PLL Enable->4x PLL enabled
STVREN = ON      // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
BORV = LO        // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.
LVP = OFF        // Low-Voltage Programming Enable->High-voltage on MCLR/VPP must be used for

palamont

Hi, thank you for your help. YES !!! my problem is resolved. The PROTON community is amazing  :)