大家好,我正在使用一个PIC24EP256GP206,我想使用OC MODUL来产生一个输出脉冲内径比较单输出脉冲模式,每次从TMR2接收IRQ。如果我选择FCY作为OC1的输入时钟,它工作,但是当我选择TMR3作为输入时钟时,它只产生一个输出脉冲。我不理解原因。这是代码:这是IRQS代码:我也尝试了StunGoC1CON2BITS SysCSEL=0x0D(
time3同步或触发器),但没有变化。它为什么只工作iFiC1CONBITE?OCTSEL=7?有人能帮我吗?谢谢
以上来自于百度翻译
以下为原文
Hi All,
i'm working with a PIC24EP256GP206, I want to use OC modul to generate an output pulse in DUAL COMPARE SINGLE OUTPUT PULSE MODE, every time I receive an irq from TMR2.
If I select Fcy as input clock for OC1 it works, but when I choose TMR3 as input clock, it generates only one output pulse and I don't understand the cause.
This is the code:
// INITIALIZATION *******************************
// TMR2
TMR2 = 0;
T2CONbits.TSIDL = 0;
T2CONbits.TGATE = 0;
T2CONbits.TCKPS = 3; // Prescaler = 256
T2CONbits.TCS = 0;
IPC1bits.T2IP = 4;
IFS0bits.T2IF = 0;
IEC0bits.T2IE = 1;
PR2 = 7725; //25 ms/40Hz
//***********************************************
// TMR3 (input clock for OC1)
TMR3 = 0;
T3CONbits.TSIDL = 0;
T3CONbits.TGATE = 0;
T3CONbits.TCKPS = 1;
T3CONbits.TCS = 0;
T3CONbits.TON = 0;
//***********************************************
// OC1 (Output compare)
OC1CON1 = 0;
OC1CON2 = 0;
RPOR1bits.RP37R = 0x10;
OC1CON1bits.OCTSEL = 1; // Source = Timer3
OC1R = 2000;
OC1RS = 2500;
OC1CON2bits.SYNCSEL = 0;
OC1CON2bits.OCTRIG = 0;
OC1CON2bits.TRIGSTAT = 0;
IPC0bits.OC1IP = 1;
IFS0bits.OC1IF = 0;
IEC0bits.OC1IE = 1;
PR3=OC1RS+2;
T2CONbits.TON = 1;
This is the IRQs code:
void __attribute__((interrupt, no_auto_psv)) _T2Interrupt(void){
TMR2 = 0;
TMR3 = 0;
OC1TMR = 0;
OC1CON1bits.OCM = 4; // Re
ARM a new output pulse
T3CONbits.TON = 1;
IFS0bits.T2IF = 0;
}
void __attribute__((interrupt, no_auto_psv)) _OC1Interrupt(void){
T3CONbits.TON = FALSE;
IFS0bits.OC1IF = 0;
}
I tried also setting OC1CON2bits.SYNCSEL = 0x0D (Timer3 synchronizes or triggers) but nothing change.
Why does it work only if OC1CON1bits.OCTSEL=7 ?
Can anyone help me?
Thanks
0