2.Nov.2022 UPDATED
Hello to Every One,
I have another problem to set clock by microC or whit microC code.
I'm building one stereo Vu-Meter project (after try it on my breadboard using another pic model), so i decide to draw and print my pcb using one 16F18346 mcu.
My questions is:
1) can i have microC code (or setting it by compiler) to set only external xtal 32 mhz ?
2) can i have microC code (or setting it by compiler) to set only internal clock whit pll x 4 ?
PS:Actually i have only xtal 20mhz components.
I attached all information for you.
Thank you in advance.
Leonardo.
Difficoult set clock using 16F18346 mcu, How can i do? SOLVED
Difficoult set clock using 16F18346 mcu, How can i do? SOLVED
- Attachments
-
- 2.NOV.2022 UPDATED SCHEME
- VU-MaterSpectrumAnalyzer16F18346.jpg (699.67 KiB) Viewed 622 times
-
- VuMeter-pcb1.jpg (3.26 MiB) Viewed 675 times
-
- VuMeter-AudioSpectrum16F18346-V1.0.zip
- (102.15 KiB) Downloaded 25 times
Last edited by leo73 on 02 Nov 2022 15:07, edited 4 times in total.
Re: Difficoult set clock using 16F18346 mcu, How can i do?
Wow!
so many things wrong....
so many things confused....
1) The only way to obtain 32MHz clock from a 2-pin crystal is to use an 8MHz crystal with 4x PLL
20MHz 2-pin crystal can only give 20MHz clock
2) I will give you project settings of 16MHz internal oscillator and 2x PLL once you answer question 3
3) Which PIC device does your board have - PIC16F18346 or PIC16LF18346?
Your schematic and your post mention the "F" version, but the project in your zip file is for the "LF" version
so many things wrong....
so many things confused....
1) The only way to obtain 32MHz clock from a 2-pin crystal is to use an 8MHz crystal with 4x PLL
20MHz 2-pin crystal can only give 20MHz clock
2) I will give you project settings of 16MHz internal oscillator and 2x PLL once you answer question 3
3) Which PIC device does your board have - PIC16F18346 or PIC16LF18346?
Your schematic and your post mention the "F" version, but the project in your zip file is for the "LF" version
Start every day with a smile...... (get it over with)
Re: Difficoult set clock using 16(L)F18346 mcu, How can i do? SOLVED
Hello Hexreader,
Thank you to your reply !!!
I'm using16(L)F18346
Tomorrow I'll open another questions because this pic family not recognise, in to timer0 interrupt, the instruction OPTION_REG= ....
I Asked to PicKit plus company they reply me, so I solve this obstacle. There's code to set internal and external 32mhz clock and for use 20mhz too.
Internal 32mHz
// CONFIG1 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits->Oscillator not enabled
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits->HFINTOSC (1MHz)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; I/O or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
// CONFIG2 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR/VPP pin function is MCLR; Weak pull-up enabled
#pragma config PWRTE = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config WDTE = OFF // Watchdog Timer Enable bits->WDT disabled; SWDTEN is ignored
#pragma config LPBOREN = OFF // Low-power BOR enable bit->ULPBOR disabled
#pragma config BOREN = ON // Brown-out Reset Enable bits->Brown-out Reset enabled, SBOREN bit ignored
#pragma config BORV = LOW // Brown-out Reset Voltage selection bit->Brown-out voltage (Vbor) set to 2.45V
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit->The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a Reset
#pragma config DEBUG = OFF // Debugger enable bit->Background debugger disabled
// CONFIG3 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config WRT = OFF // User NVM self-write protection bits->Write protection off
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.
// CONFIG4
#pragma config CP = OFF // User NVM Program Memory Code Protection bit->User NVM code protection disabled
#pragma config CPD = OFF // Data NVM Memory Code Protection bit->Data NVM code protection disabled
External 20mHz
OSC on Porta.4 and porta.5
You need to set TRIS and ANSEL for external
TRISx registers
ANSELx registers
// CONFIG1
#pragma config FEXTOSC = HS // FEXTOSC External Oscillator mode Selection bits->HS (crystal oscillator) above 4 MHz
#pragma config RSTOSC = EXT1X // Power-up default value for COSC bits->EXTOSC operating per FEXTOSC bits
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; I/O or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
Thank you to your reply !!!
I'm using16(L)F18346
Tomorrow I'll open another questions because this pic family not recognise, in to timer0 interrupt, the instruction OPTION_REG= ....
I Asked to PicKit plus company they reply me, so I solve this obstacle. There's code to set internal and external 32mhz clock and for use 20mhz too.
Internal 32mHz
// CONFIG1 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits->Oscillator not enabled
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits->HFINTOSC (1MHz)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; I/O or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
// CONFIG2 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR/VPP pin function is MCLR; Weak pull-up enabled
#pragma config PWRTE = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config WDTE = OFF // Watchdog Timer Enable bits->WDT disabled; SWDTEN is ignored
#pragma config LPBOREN = OFF // Low-power BOR enable bit->ULPBOR disabled
#pragma config BOREN = ON // Brown-out Reset Enable bits->Brown-out Reset enabled, SBOREN bit ignored
#pragma config BORV = LOW // Brown-out Reset Voltage selection bit->Brown-out voltage (Vbor) set to 2.45V
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit->The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a Reset
#pragma config DEBUG = OFF // Debugger enable bit->Background debugger disabled
// CONFIG3 TO PROPRIETY OF PROJECT ON COMPILER
#pragma config WRT = OFF // User NVM self-write protection bits->Write protection off
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.
// CONFIG4
#pragma config CP = OFF // User NVM Program Memory Code Protection bit->User NVM code protection disabled
#pragma config CPD = OFF // Data NVM Memory Code Protection bit->Data NVM code protection disabled
Code: Select all
//OSCILLATOR_Initialize
// NOSC HFINTOSC; NDIV 4;
OSCCON1 = 0x62;
// CSWHOLD may proceed; SOSCPWR Low power; SOSCBE crystal oscillator;
OSCCON3 = 0x00;
// LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
OSCEN = 0x00;
// HFFRQ 32_MHz;
OSCFRQ = 0x07;
// HFTUN 0;
OSCTUNE = 0x00;
External 20mHz
OSC on Porta.4 and porta.5
You need to set TRIS and ANSEL for external
TRISx registers
;TRISA = 0x37;
TRISB = 0xF0;
TRISC = 0xFF
ANSELx registers
ANSELC = 0xFF;
ANSELB = 0xF0;
ANSELA = 0x37;
// CONFIG1
#pragma config FEXTOSC = HS // FEXTOSC External Oscillator mode Selection bits->HS (crystal oscillator) above 4 MHz
#pragma config RSTOSC = EXT1X // Power-up default value for COSC bits->EXTOSC operating per FEXTOSC bits
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; I/O or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
Code: Select all
//OSCILLATOR_Initialize
// NOSC EXTOSC; NDIV 4;
OSCCON1 = 0x72;
// CSWHOLD may proceed; SOSCPWR Low power; SOSCBE crystal oscillator;
OSCCON3 = 0x00;
// LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
OSCEN = 0x00;
// HFFRQ 32_MHz;
OSCFRQ = 0x07;
// HFTUN 0;
OSCTUNE = 0x00;