PIC24F Timer interrupt mit 4xPLL

OP #5452499
Lesenswert?

Hallo,

ich verwende einen PIC24FV32KA301

alle 250ms soll ein Timer interrupt ausgelöst werden.

interner Oscilator
(8Mhz mit 4xppl = 32Mhz
32/2 = 16Mhz
mit einem Presc von 64 => alle 250ms => Period value =0xF424

nun ist es so das es ca alle 16 ms auftritt.


Woran kann das liegen. Werden für den Timer4 16 Mhz auch akzeptiert oder 
wird der interne 8Mhz genommen
Gast #5453326
Lesenswert?

0xF424 ist mal falsch, aber nicht die Ursache. 0xF423 wäre korrekt.

Ich denke da hats was mit dem prescaler. der ist wohl nicht auf 64 
sondern auf 8.

Ansonst müsste der PIC mit dem 8x Takt laufen und das ist eher 
unwahrscheinlich.
OP #5453521
Lesenswert?

Folgende Einstellungen habe ich vorgenommen hier jetzt mit einem 
Interrupt von 1s.:
Wenn ich nun messe kommt der Interrupt alle 4s. Leider finde ich einfach 
nicht heraus warum dies der Fall ist.

1
// FBS
2
#pragma config BWRP = OFF    // Boot Segment Write Protect->Disabled
3
#pragma config BSS = OFF    // Boot segment Protect->No boot program flash segment
4

5
// FGS
6
#pragma config GWRP = OFF    // General Segment Write Protect->General segment may be written
7
#pragma config GSS0 = OFF    // General Segment Code Protect->No Protection
8

9
// FOSCSEL
10
#pragma config FNOSC = FRC    // Oscillator Select->FRC
11
#pragma config SOSCSRC = ANA    // SOSC Source Type->Analog Mode for use with crystal
12
#pragma config LPRCSEL = HP    // LPRC Oscillator Power and Accuracy->High Power, High Accuracy Mode
13
#pragma config IESO = ON    // Internal External Switch Over bit->Internal External Switchover mode enabled (Two-speed Start-up enabled)
14

15
// FOSC
16
#pragma config POSCMOD = NONE    // Primary Oscillator Configuration bits->Primary oscillator disabled
17
#pragma config OSCIOFNC = OFF    // CLKO Enable Configuration bit->CLKO output disabled
18
#pragma config POSCFREQ = HS    // Primary Oscillator Frequency Range Configuration bits->Primary oscillator/external clock input frequency greater than 8MHz
19
#pragma config SOSCSEL = SOSCHP    // SOSC Power Selection Configuration bits->Secondary Oscillator configured for high-power operation
20
#pragma config FCKSM = CSDCMD    // Clock Switching and Monitor Selection->Both Clock Switching and Fail-safe Clock Monitor are disabled
21

22
// FWDT
23
#pragma config WDTPS = PS32768    // Watchdog Timer Postscale Select bits->1:32768
24
#pragma config FWPSA = PR128    // WDT Prescaler bit->WDT prescaler ratio of 1:128
25
#pragma config FWDTEN = OFF    // Watchdog Timer Enable bits->WDT disabled in hardware; SWDTEN bit disabled
26
#pragma config WINDIS = OFF    // Windowed Watchdog Timer Disable bit->Standard WDT selected(windowed WDT disabled)
27

28
// FPOR
29
#pragma config BOREN = BOR3    // Brown-out Reset Enable bits->Brown-out Reset enabled in hardware, SBOREN bit disabled
30
#pragma config LVRCFG = OFF    // Low Voltage Regulator Configuration bit->Low Voltage regulator is not available
31
#pragma config PWRTEN = ON    // Power-up Timer Enable bit->PWRT enabled
32
#pragma config I2C1SEL = PRI    // Alternate I2C1 Pin Mapping bit->Use Default SCL1/SDA1 Pins For I2C1
33
#pragma config BORV = V20    // Brown-out Reset Voltage bits->Brown-out Reset set to lowest voltage (2.0V)
34
#pragma config MCLRE = ON    // MCLR Pin Enable bit->RA5 input pin disabled,MCLR pin enabled
35

36
// FICD
37
#pragma config ICS = PGx2    // ICD Pin Placement Select bits->EMUC/EMUD share PGC2/PGD2
38

39
// FDS
40
#pragma config DSWDTPS = DSWDTPSF    // Deep Sleep Watchdog Timer Postscale Select bits->1:2,147,483,648 (25.7 Days)
41
#pragma config DSWDTOSC = LPRC    // DSWDT Reference Clock Select bit->DSWDT uses Low Power RC Oscillator (LPRC)
42
#pragma config DSBOREN = ON    // Deep Sleep Zero-Power BOR Enable bit->Deep Sleep BOR enabled in Deep Sleep
43
#pragma config DSWDTEN = ON    // Deep Sleep Watchdog Timer Enable bit->DSWDT enabled
44

45

46

47
#define _XTAL_FREQ  32000000UL
48

49
// RCDIV FRC/1; DOZE 1:8; DOZEN disabled; ROI disabled; 
50
CLKDIV = 0x3000;
51
// TUN Center frequency; 
52
OSCTUN = 0x0000;
53
// CF no clock failure; NOSC FRCPLL; SOSCEN disabled; CLKLOCK unlocked; OSWEN Switch is Complete; 
54
__builtin_write_OSCCONH((uint8_t) ((0x0100 >> _OSCCON_NOSC_POSITION) & 0x00FF));
55
__builtin_write_OSCCONL((uint8_t) ((0x0100 | _OSCCON_OSWEN_MASK) & 0xFF));
56
// Wait for Clock switch to occur
57
while (OSCCONbits.OSWEN != 0);
58

59
IPC6bits.T4IP = 1;
60

61
//TMR4 0; 
62
TMR4 = 0x0000;
63
//Period = 1 s; Frequency = 16000000 Hz; PR4 62500; 
64
PR4 = 0xF424;
65
//TCKPS 1:256; T32 16 Bit; TON enabled; TSIDL disabled; TCS FOSC/2; TGATE disabled; 
66
T4CON = 0x8030;
67

68

69
IFS1bits.T4IF = false;
70
IEC1bits.T4IE = true;
71

72

73
/*Enable the interrupt*/
74
IEC1bits.T4IE = true;
75

76
/* Start the Timer */
77
T4CONbits.TON = 1;
Gast #5453672
Lesenswert?

Hate M. schrieb:
> __builtin_write_OSCCONH((uint8_t) ((0x0100 >> _OSCCON_NOSC_POSITION) &
> 0x00FF));
> __builtin_write_OSCCONL((uint8_t) ((0x0100 | _OSCCON_OSWEN_MASK) &
> 0xFF));

Ich bin jetzt zu faul, die Bitfummeleien und casts nachzuvollziehen, bei 
mir heists schlicht
1
 _RCDIV = 0; // Postscaler 1/1
2
 __builtin_write_OSCCONH(0x01); // 8 MHz FRC with Postscaler and PLL (FRCPLL)
3
 __builtin_write_OSCCONL(0x01); // Start switch

MfG Klaus
Gast #5454108
Lesenswert?

#pragma config POSCFREQ = HS    // Primary Oscillator Frequency Range 
Configuration bits->Primary oscillator/external clock input frequency 
greater than 8MHz
#pragma config FCKSM = CSDCMD    // Clock Switching and Monitor 
Selection->Both Clock Switching and Fail-safe Clock Monitor are disabled

der fehler liegt genau hier :)

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren