Forum: Mikrocontroller und Digitale Elektronik PIC teilt Frequenz!


von Franz (Gast)


Angehängte Dateien:

Lesenswert?

Ja hallo ich habe da eine kurze Frage, meinem PIC betreibe ich mit einem 
8 MHz Quarz und wenn ich jetzt eine Zeitschleife laufen lasse dauert sie 
nur halb so lang, kann mir vielleicht jemand sage was ich übersehe.


1
#include <xc.h>
2
#define XTAL_FREQ 8000000
3
4
// CONFIG1L
5
#pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
6
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
7
8
// CONFIG1H
9
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
10
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
11
#pragma config IESO = OFF      // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

z.B. mit dieser Funktion
1
 __delay_ms(100);

MFG

von chris (Gast)


Lesenswert?

guck dir mal die vorteiler an dann weißt du auch warum links im bild

von Franz (Gast)


Lesenswert?

Meinst du die Einstellung
1
CPUDIV
!!!

von chris (Gast)


Lesenswert?

wenn du den in BLAU gekennzeichneten meinst denn ja

i denke das prog müsste um

#pragma config CPUDIV = XX

erweitert werden aber das sollte eigentlich im DB stehen in welcher 
grundconfig der PIC die OSCFrequenz teilt wenn diese ANGABE im prog 
fehlt.

von Franz (Gast)


Lesenswert?

so habe die config mit reingemacht immer noch das gleiche!!!
1
 #include <xc.h>
2
#define XTAL_FREQ 8000000
3
4
// CONFIG1L
5
#pragma config PLLDIV = 1
6
#pragma config CPUDIV = OSC1_PLL2// PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
7
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
8
9
// CONFIG1H
10
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
11
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
12
#pragma config IESO = OFF      // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

von Stefan (Gast)


Lesenswert?

Welcher PIC ?

von Franz (Gast)


Lesenswert?

PIC18F2550!!!

von Patrick B. (p51d)


Lesenswert?

Übermässige Ausruffezeichen führen hier auch nicht zum Ziel!
Zeig doch mal den ganzen Code.
Hast du die Zeit mit dem Oszilloskop gemessen oder hast du den Simulator 
genutzt (falls ja, welche Einstellungen?)?

von Franz (Gast)


Lesenswert?

1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <pic18f2550.h>
4
#include <delays.h>
5
6
7
8
// PIC18F2550 Configuration Bit Settings
9
10
#include <xc.h>
11
12
#define _XTAL_FREQ 8000000
13
14
// CONFIG1L
15
#pragma config PLLDIV = 1
16
#pragma config CPUDIV = OSC1_PLL2// PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
17
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
18
19
// CONFIG1H
20
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
21
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
22
#pragma config IESO = OFF      // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
23
24
// CONFIG2L
25
#pragma config PWRT = ON        // Power-up Timer Enable bit (PWRT enabled)
26
#pragma config BOR = OFF        // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
27
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
28
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
29
30
// CONFIG2H
31
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
32
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)
33
34
// CONFIG3H
35
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
36
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
37
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
38
#pragma config MCLRE = ON// MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
39
40
// CONFIG4L
41
#pragma config STVREN = OFF     // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
42
#pragma config LVP = OFF      // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
43
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
44
45
// CONFIG5L
46
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
47
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
48
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
49
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
50
51
// CONFIG5H
52
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
53
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
54
55
// CONFIG6L
56
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
57
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
58
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
59
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
60
61
// CONFIG6H
62
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
63
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
64
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
65
66
// CONFIG7L
67
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
68
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
69
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
70
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
71
72
// CONFIG7H
73
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
74
75
76
int main(void) {
77
78
    PORTC = 0x00;
79
    LATC = 0x00;
80
    TRISC = 0x00;
81
82
        
83
        while(1){
84
85
            PORTC = 0xFF;
86
            __delay_ms(50);
87
            PORTC = 0x00;
88
            __delay_ms(50);
89
        }
90
    
91
}

von Klaus (Gast)


Lesenswert?

Franz schrieb:
> #include <stdio.h>
> #include <stdlib.h>
> #include <pic18f2550.h>
> #include <delays.h>
>
> // PIC18F2550 Configuration Bit Settings
>
> #include <xc.h>
>
> #define _XTAL_FREQ 8000000

ich würde die includes so setzen:
1
#define _XTAL_FREQ 8000000
2
#include <xc.h>
3
#include <stdio.h> 
4
#include <stdlib.h> 
5
#include <delays.h>

Den pic18f2550.h braucht man IMHO nicht, das erledigt xc.h schon mit den 
Projekteinstellungen

MfG Klaus

von Franz (Gast)


Lesenswert?

OK Danke

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.