PIC 捕捉模式不触发中断

发布于 2024-10-26 19:10:27 字数 2595 浏览 2 评论 0原文

我尝试在 PIC 16LF1827 上使用捕获模块,但从未输入 ISR。我从基本的下降沿中断(有效)开始,然后添加到定时器 1 配置中(仍在工作),然后禁用 IOC 中断并配置/启用相关的 CCP 中断(从未进入 ISR)。代码如下:注释部分是原始的基本IOC设置。

我已经使用 MPLab 调试器验证了 ISR 未输入,并通过将其连接到逻辑分析仪并观察 RB1 来确认这一点。

#include "htc.h"

//config1
//internal osc, no wdt, use power-up timer, enable reset
//  no code protection, brown-out-reset enabled, clkout is gpio, 
//  internal-external switchover off, failsafe clock monitor off
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON 
  & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON 
  & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);

//config2 (following MPLab's complaints when running debugger)
//low-voltage programming off, debug on, brown-out reset at 2.7 v
//  stack over/under flow triggers reset, no 4x pll, 
//  no flash write protection
__CONFIG(LVP_OFF & DEBUG_ON & BORV_27 
  & STVREN_ON & PLLEN_OFF & WRT_OFF);

void interrupt isr(void){
    //bounce pin 1
    LATB ^= 0b10;
    LATB ^= 0b10;
    if(IOCIF && IOCBF0){
        IOCBF0 = 0;
        IOCIF = 0; 
    }
    if (CCP1IF){
        CCP1IF = 0;
    }
}

void main(void){
    //configure internal oscillator: 
    //PLL = 0, source = from config 1, frequency = 4 mhz 
    //0b0: SPLLEN_OFF
    OSCCONbits.SPLLEN = 0b0;
    //0b00: use config word 1
    OSCCONbits.SCS = 0b00;
    //0b1101: 4 mhz frequency
    OSCCONbits.IRCF = 0b1101;

    //configure peripherals
    //PORT A: LEDs (output), digital
    TRISA = 0x00;
    ANSELA = 0;
    //PORT B: digital, 0 = input, 1 = output, rest don't care
    TRISB = 0b11111101;
    ANSELB = 0;

    //configure timer 1 (not needed for basic IOC)
    //source = instruction clock, prescale = 1:1, disable LP osc, do synchronize (DC)
    //0b00: instruction clock
    T1CONbits.TMR1CS = 0b00;
    //0b00: 1:1
    T1CONbits.T1CKPS = 0b00;
    //0b0: lp osc off
    T1OSCEN = 0b0;
    //0b0: synch (ignored)
    nT1SYNC = 0b0;

    //interrupts
    /*
    //IOC enabled on falling edge for port B 0
    IOCBN0 = 0b00000001;
    IOCIE = 1;
    */

    //Capture on falling edge for port B 0
    //notes in 23.1 of DS: disable interrupt, set operating mode, clear flag, enable interrupt
    CCP1IE = 0b0;
    //0b100: every falling edge
    CCP1CONbits.CCP1M = 0b100;
    CCP1IF = 0b0;
    CCP1IE = 0b1;
    //enable peripheral interrupts, global interrupts
    PEIE = 1;
    GIE = 1;

    //start timer 1
    TMR1ON = 1;
    while(1){
        //Toggle led 0
        LATA ^= 0b1;
    }
}

我正在使用 HI-TECH C 编译器(lite),在 MPLab 中运行。

任何建议将不胜感激。如果我滥用术语,我很抱歉,这是我的第一个 PIC 项目。

I'm trying to use the capture module on a PIC 16LF1827, but the ISR is never entered. I started with a basic falling-edge interrupt (worked), then added in the timer 1 configuration (still working), then disabled the IOC interrupt and configured/enabled the relevant CCP interrupt (ISR is never entered). The code is below: the commented section is the original basic IOC setup.

I've verified with the MPLab debugger that the ISR is not entered, and confirmed this by hooking it up to a logic analyzer and watching RB1.

#include "htc.h"

//config1
//internal osc, no wdt, use power-up timer, enable reset
//  no code protection, brown-out-reset enabled, clkout is gpio, 
//  internal-external switchover off, failsafe clock monitor off
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON 
  & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON 
  & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);

//config2 (following MPLab's complaints when running debugger)
//low-voltage programming off, debug on, brown-out reset at 2.7 v
//  stack over/under flow triggers reset, no 4x pll, 
//  no flash write protection
__CONFIG(LVP_OFF & DEBUG_ON & BORV_27 
  & STVREN_ON & PLLEN_OFF & WRT_OFF);

void interrupt isr(void){
    //bounce pin 1
    LATB ^= 0b10;
    LATB ^= 0b10;
    if(IOCIF && IOCBF0){
        IOCBF0 = 0;
        IOCIF = 0; 
    }
    if (CCP1IF){
        CCP1IF = 0;
    }
}

void main(void){
    //configure internal oscillator: 
    //PLL = 0, source = from config 1, frequency = 4 mhz 
    //0b0: SPLLEN_OFF
    OSCCONbits.SPLLEN = 0b0;
    //0b00: use config word 1
    OSCCONbits.SCS = 0b00;
    //0b1101: 4 mhz frequency
    OSCCONbits.IRCF = 0b1101;

    //configure peripherals
    //PORT A: LEDs (output), digital
    TRISA = 0x00;
    ANSELA = 0;
    //PORT B: digital, 0 = input, 1 = output, rest don't care
    TRISB = 0b11111101;
    ANSELB = 0;

    //configure timer 1 (not needed for basic IOC)
    //source = instruction clock, prescale = 1:1, disable LP osc, do synchronize (DC)
    //0b00: instruction clock
    T1CONbits.TMR1CS = 0b00;
    //0b00: 1:1
    T1CONbits.T1CKPS = 0b00;
    //0b0: lp osc off
    T1OSCEN = 0b0;
    //0b0: synch (ignored)
    nT1SYNC = 0b0;

    //interrupts
    /*
    //IOC enabled on falling edge for port B 0
    IOCBN0 = 0b00000001;
    IOCIE = 1;
    */

    //Capture on falling edge for port B 0
    //notes in 23.1 of DS: disable interrupt, set operating mode, clear flag, enable interrupt
    CCP1IE = 0b0;
    //0b100: every falling edge
    CCP1CONbits.CCP1M = 0b100;
    CCP1IF = 0b0;
    CCP1IE = 0b1;
    //enable peripheral interrupts, global interrupts
    PEIE = 1;
    GIE = 1;

    //start timer 1
    TMR1ON = 1;
    while(1){
        //Toggle led 0
        LATA ^= 0b1;
    }
}

I'm using the HI-TECH C compiler (lite), running in MPLab.

Any suggestions would be greatly appreciated. My apologies if I butcher terminology, this is my first project on a PIC.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2024-11-02 19:10:27

<罢工>
您对 TRISB1 的设置是作为输出。根据数据表,捕获引脚需要配置为输入。对于 GPIO 引脚,将 TRIS 位设置为 0 表示输出,设置 1 表示输入。

编辑:请原谅最初的愚蠢答案,因为我没有意识到您正在使用 PORTB1 作为示波器的 GPIO 指示器。

那么最初您使用 PORTB0 作为捕获引脚是否正确(使用 IOC)?捕获模块使用不同的 GPIO 端口作为输入(CCP1 为 PORTB3)。您是否将捕获源的连接移至 PORTB3?

编辑:在仔细查看 PIC 数据表后,我注意到 CCP1 的 GPIO 引脚可以从 PORTB3 移动到 PORTB0,但我没有看到任何关于如何设置 APFCON0.CCP1SEL 位的参考。那将是其他需要检查的事情。


Your setting for TRISB1 is as an output. According to the datasheet, the capture pin needs to be configured as an input. For the GPIO pins, setting the TRIS bit a 0 is an output, 1 is for an input.

EDIT: Forgive the initial stupid answer as I didn't realize you were using PORTB1 as a GPIO indicator for your scope.

So initially you used PORTB0 as your capture pin correct (using IOC)? The capture module uses a different GPIO port for its input (PORTB3 for CCP1). Did you move the connection to PORTB3 for your capture source?

EDIT: After some more looking through the PIC datasheet I noticed that CCP1's GPIO pin can be moved from PORTB3 to PORTB0 but I don't see any reference to how you set the APFCON0.CCP1SEL bit. That would be something else to check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文