请教下这个定时配置是否正确?
一开发板上的例程,PIC24FJ48GA002单片机,配置如下:_CONFIG1( JTAGEN_OFF & GCP_ON & GWRP_ON & BKBUG_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx1 &
WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768)
_CONFIG2( IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_NONE & FNOSC_FRCPLL & I2C1SEL_PRI
& IOL1WAY_OFF)
void T1Init(void)
{
/* 定时器*/
T1CON=0x8020; /* 定时 1ms*/
PR1 = 124;
_T1IE=1;
}
是1ms定时,还是0.5ms定时? 64分频,1/16 * 64 * 124得出500ms定时周期 本帖最后由 yklstudent 于 2014-11-23 12:00 编辑
编辑原因:编辑回复。
仿真了下是500US yklstudent 发表于 2014-11-23 09:32
POSCMOD_NONE
这个会导致实际应该是1ms
POSCMOD_XT应该就是0.5ms了
24F32KA301 Example LED Flash using Microchip C
Example program for the Microchip PIC 24F32KA301 using Microchip C compiler
Using Timer1 and interrupts, flashes LED on A0 once per second
/*
* Microchip C Compiler Demo Program for PIC24F32KA301
* PIC24F32KA301 flash LED on A0 using Timer1 and interrupts
* Copyright (C)2011 HobbyTronics.co.uk
* Freely distributable.
*/
//include basic header definition
#include <p24f32ka301.h>
//config
_FOSCSEL(FNOSC_FRCPLL & IESO_OFF); // FRC Oscillator with PLL (32MHz)
_FOSC (FCKSM_CSDCMD & SOSCSEL1_SOSCLP & POSCFREQ_MS
& OSCIOFNC_OFF & POSCMOD_NONE);
/*Clock switching and Fail-Safe Clock monitor DISABLED
Secondary Oscillator Select
Primary Oscillator Frequency Range
OSCO Pin Configuration OFF
Oscillator Selection
*/
//prototypes
void timer1_init(void);
//main loop
int main(void)
{
//Set up Clock
OSCCON = 0x11C0; // select INTERNAL FRC (32MHz), Post Scale & PLL
CLKDIV = 0x0000; // No clock Divide
//Set Ports to Digital
ANSELA=0x0000;
ANSELB=0x0000;
ANSELC=0x0000;
TRISA=0x0000;
LATAbits.LATA0 = 0;
timer1_init();
SRbits.IPL = 0 ; // turn on all interrupt priorities
//Loop forever
while(1)
{
}
}
//Set up Timer, target 2Hz interrupts
void timer1_init(void)
{
//Setup Timer1
PR1 = 0x7A12; // set for 2Hz (Clock is 32KHz/2 = 16MHz)
IPC0bits.T1IP = 5; //set interrupt priority
T1CON = 0b1000000000110000; //turn on the timer
IFS0bits.T1IF = 0; //reset interrupt flag
IEC0bits.T1IE = 1; //turn on the timer1 interrupt
}
//_T1Interrupt() is the T1 interrupt service routine (ISR).
void __attribute__((__interrupt__, auto_psv)) _T1Interrupt(void)
{
LATAbits.LATA0 = ~LATAbits.LATA0; //Toggle output to LED
IFS0bits.T1IF = 0;
}
这个是某网站找到的例程,用的是FNOSC_FRCPLL,8M内部,PLL后32m,Fcy取得是16m。LZ位例程用的也是FNOSC_FRCPLL ,按道理Fcy也是16m,这样算下来500ms才对。 yklstudent 发表于 2014-11-23 09:32
编辑原因:编辑回复。
仿真了下是500US
能帮忙看下这个帖子的问题么?http://www.amobbs.com/thread-5605970-1-1.html yklstudent 发表于 2014-11-23 09:32
编辑原因:编辑回复。
仿真了下是500US
你用什么仿真的?仔细看手册之后,发现开发例程标注的1ms是正确。使用FRC,默认有分频。 fengyunyu 发表于 2014-11-26 22:30
你用什么仿真的?仔细看手册之后,发现开发例程标注的1ms是正确。使用FRC,默认有分频。 ...
ISIS啊。。。。。。。。。。
页:
[1]