Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Configurare clock 32MHZ

Raccolta di codici sorgenti

Moderatore: Foto UtentePaolino

0
voti

[1] Configurare clock 32MHZ

Messaggioda Foto UtenteDavide90 » 7 mar 2015, 20:30

Salve ragazzi, ho nuovamente bisogno di voi,

Sto usando un PIC 16f1713 ed ho la necessità di configurarlo per avere il clock di 32 MHz con oscillatore interno, sapete aiutarmi?

riporto il datasheet;

Codice: Seleziona tutto
Internal Oscillator Frequency
Selection
The system clock speed can be selected via software
using the Internal Oscillator Frequency Select bits
IRCF<3:0> of the OSCCON register.
The postscaled output of the 16 MHz HFINTOSC,
500 kHz MFINTOSC, and 31 kHz LFINTOSC connect
to a multiplexer (see Figure 6-1). The Internal Oscillator
Frequency Select bits IRCF<3:0> of the OSCCON
register select the frequency output of the internal
oscillators. One of the following frequencies can be
selected via software:
- 32 MHz (requires 4x PLL)
- 16 MHz
- 8 MHz
- 4 MHz
- 2 MHz
- 1 MHz
- 500 kHz (default after Reset)
- 250 kHz
- 125 kHz
- 62.5 kHz
- 31.25 kHz
- 31 kHz (LFINTOSC)
The IRCF<3:0> bits of the OSCCON register allow
duplicate selections for some frequencies. These
duplicate choices can offer system design trade-offs.
Lower power consumption can be obtained when
changing oscillator sources for a given frequency.
Faster transition times can be obtained between
frequency changes that use the same oscillator source.
6.2.2.6 32 MHz Internal Oscillator

Frequency Selection

The Internal Oscillator Block can be used with the
4x PLL associated with the External Oscillator Block to
produce a 32 MHz internal system clock source. The
following settings are required to use the 32 MHz
internal clock source:
• The FOSC bits in Configuration Words must be
set to use the INTOSC source as the device
system clock (FOSC<2:0> = 100).
• The SCS bits in the OSCCON register must be
cleared to use the clock determined by
FOSC<2:0> in Configuration Words
(SCS<1:0> = 00).
• The IRCF bits in the OSCCON register must be
set to the 8 MHz HFINTOSC set to use
(IRCF<3:0> = 1110).
• The SPLLEN bit in the OSCCON register must be
set to enable the 4x PLL, or the PLLEN bit of the
Configuration Words must be programmed to a
‘1’.
The 4x PLL is not available for use with the internal
oscillator when the SCS bits of the OSCCON register
are set to ‘1x’. The SCS bits must be set to ‘00’ to use
the 4x PLL with the internal oscillator.


Codice: Seleziona tutto
Note: When using the PLLEN bit of the
Configuration Words, the 4x PLL cannot
be disabled by software and the SPLLEN
option will not be available.


Questa la mia configurazione:
Codice: Seleziona tutto
#pragma config FOSC=INTOSC
#pragma config CP=0
#pragma config CLKOUTEN=1
#pragma config PWRTE=0
#pragma config WDTE=0
#pragma config MCLRE=1
#pragma config FCMEN = 0
#pragma config IESO = 0
#pragma config BOREN=0
#pragma config LVP=0;


OSCCON  = 0b11110000;


Sapete dirmi se la configurazione che sto usando è corretta?
Avatar utente
Foto UtenteDavide90
29 6
Frequentatore
Frequentatore
 
Messaggi: 130
Iscritto il: 5 lug 2012, 11:34

0
voti

[2] Re: Configurare clock 32MHZ

Messaggioda Foto Utentebobina » 8 mar 2015, 12:12

Sembrerebbe di si, anche guardando la figura 6-1. Non funziona oppure è un semplice dubbio?
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22

0
voti

[3] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteDavide90 » 8 mar 2015, 12:16

Ho dei problemi con l'interrupt del timer1, come posso provare se effettivamente sta "girando" a 32 MHz? Magari abilitando il CLock out e misurando con l' oscilloscopio?
Avatar utente
Foto UtenteDavide90
29 6
Frequentatore
Frequentatore
 
Messaggi: 130
Iscritto il: 5 lug 2012, 11:34

0
voti

[4] Re: Configurare clock 32MHZ

Messaggioda Foto Utentebobina » 8 mar 2015, 12:27

Se imposti la configurazione CLKOUTEN a 0 e non 1 dovrestri avere FOSC/4 sul pin OSC2 e con l'oscilloscopio guardi la frequenza del PIC.
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22

1
voti

[5] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteTardoFreak » 8 mar 2015, 13:12

Si può fare anche in modo indiretto:
- Si scrive un programmino delle balle che manda ad 1 e a 0 un' uscita in un loop infinito.
- Si seleziona il clock interno senza nessun PLL, clock interno pulito.
- Misuri il periodo dell' onda rettangolare che hai in uscita dal pin che fai muovere
- Fai tutto il setup della nuova frequenza di clock.
- Misuri il perido dell' onda. Così riesci a vedere a che frequenza funziona il PIC visto che la prima misura l' hai fatta con una frequenza di clock nota e sicura.
"La follia sta nel fare sempre la stessa cosa aspettandosi risultati diversi".
"Parla soltanto quando sei sicuro che quello che dirai è più bello del silenzio".
Rispondere è cortesia, ma lasciare l'ultima parola ai cretini è arte.
Avatar utente
Foto UtenteTardoFreak
73,9k 8 12 13
-EY Legend-
-EY Legend-
 
Messaggi: 15754
Iscritto il: 16 dic 2009, 11:10
Località: Torino - 3° pianeta del Sistema Solare

0
voti

[6] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteDavide90 » 8 mar 2015, 13:56

Ho misurato la frequenza sul pin CLKOUTEN (RA6 nel mio caso) con l'oscilloscopio, ottengo 4 MHz

:cry:
Avatar utente
Foto UtenteDavide90
29 6
Frequentatore
Frequentatore
 
Messaggi: 130
Iscritto il: 5 lug 2012, 11:34

0
voti

[7] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteDavide90 » 8 mar 2015, 14:20

Foto UtenteTardoFreak, nel pomeriggio provo a fare questa prova!
Avatar utente
Foto UtenteDavide90
29 6
Frequentatore
Frequentatore
 
Messaggi: 130
Iscritto il: 5 lug 2012, 11:34

0
voti

[8] Re: Configurare clock 32MHZ

Messaggioda Foto Utentebobina » 8 mar 2015, 14:30

Davide90 ha scritto:Ho misurato la frequenza sul pin CLKOUTEN (RA6 nel mio caso) con l'oscilloscopio, ottengo 4 MHz
Quindi dovrebbe essere a 16MHz. Dovresti postare anche l'altra parte di codice per capire cosa succede.
Comunque nel registro T1CON del Timer1 per TMR1CS ci sono queste 2 possibilità:

01 = Timer1 clock source is system clock (F OSC )
00 = Timer1 clock source is instruction clock (F OSC /4)
Avatar utente
Foto Utentebobina
212 6
Frequentatore
Frequentatore
 
Messaggi: 177
Iscritto il: 27 dic 2009, 14:22

0
voti

[9] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteDavide90 » 8 mar 2015, 15:29

Ragazzi ho trovato il problema, è alquanto strano però.

Al momento, sul pin CLOKOUT ottengo FOSC/4 = 8 MHz, quindi è corretto

L' unica modifica da me apportata è stata definire
Codice: Seleziona tutto
#pragma config PLLEN=1

che prima invece non definivo mai.
Sul datasheet c' è scritto:

Codice: Seleziona tutto
The SPLLEN bit in the OSCCON register must be
set to enable the 4x PLL, or the PLLEN bit of the
Configuration Words must be programmed to a
‘1’.


e nelle note:
Codice: Seleziona tutto
When using the PLLEN bit of the
Configuration Words, the 4x PLL cannot
be disabled by software and the SPLLEN
option will not be available.


e riguardo il bit SPLLEN

Codice: Seleziona tutto
SPLLEN: Software PLL Enable bit
If PLLEN in Configuration Words = 1:
SPLLEN bit is ignored. 4x PLL is always enabled (subject to oscillator requirements)
If PLLEN in Configuration Words = 0:
1 = 4x PLL Is enabled
0 = 4x PLL is disabled

nel mio caso, PLLEN non veniva mai configurato da me, ma il bit SPLLEN è sempre stato settato ad 1, teoricamente , anche non avendo mai impostato il bit PPLEN , 4x PLL doveva essere sempre abilitato, ma ciò non è avvenuto. Come ve lo spiegate?

Foto UtenteEcoTan, avevo dimenticato una "S",
Codice: Seleziona tutto
ma il bit SPLLEN è sempre stato settato ad 1
Ultima modifica di Foto UtenteDavide90 il 8 mar 2015, 15:48, modificato 1 volta in totale.
Avatar utente
Foto UtenteDavide90
29 6
Frequentatore
Frequentatore
 
Messaggi: 130
Iscritto il: 5 lug 2012, 11:34

0
voti

[10] Re: Configurare clock 32MHZ

Messaggioda Foto UtenteEcoTan » 8 mar 2015, 15:43

Davide90 ha scritto:il bit PLLEN è sempre stato settato ad 1, teoricamente , anche non avendo mai impostato il bit PPLEN

questo chi lo dice? Comunque tutto è bene quel che finisce bene, prendiamo nota e tu non cancellare il programma!
Avatar utente
Foto UtenteEcoTan
7.720 4 12 13
Expert EY
Expert EY
 
Messaggi: 5421
Iscritto il: 29 gen 2014, 8:54

Prossimo

Torna a Firmware e programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 5 ospiti