gpt4 book ai didi

c - PIC18F45K22内部振荡器频率问题

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:29 25 4
gpt4 key购买 nike

今天我开始了一个项目,尝试使用 PIC18F45K22 做一些事情。我以前为其他 Controller 编写的代码有一些时间问题。原来是 Controller 的时钟频率有问题。

正如数据表告诉我的那样,在使用内部振荡器时,我应该有一个默认的 1MHz 时钟频率。根据我的示波器,我在 OSC2 (RA6) 引脚上测量了一个 250kHz 的时钟频率。所以我开始在数据表中四处寻找,并从数据表中找到了表 2-3。此表显示当 Controller 处于 sleep 模式时 OSC2 引脚将为“时钟/4”,这可能是我的问题的根源,因为 1MHz/4 = 250kHz。根据第 3.0 章, Controller 将在设备复位时以 PRI_RUN 模式启动,除非启用双速启动。所以为了确保我通过使用以下配置行禁用了此模式:

#pragma config IESO = OFF

此行将禁用内部/外部振荡器切换位,这将根据段落 2.12.1 禁用双速启动。

现在我尝试了 OSCCON、OSCCON2、OSCTUNE 寄存器的多种设置,但都失败了。在这一点上,我想不出是什么导致了这个“问题”。我希望有人会发现我的错误,以便我可以在指定的时钟频率上运行设备。

目前我设置了这些配置位:

#pragma config WDTEN = OFF
#pragma config FOSC = INTIO7 // Make clock visible on OSC2 pin
#pragma config LVP = OFF
#pragma config DEBUG = OFF
#pragma config IESO = OFF // Disable Two-speed Start-up

// Entry of application
int main(int argc, char** argv)
{
OSCCONbits.IRCF = 0b011; // default frequency
// Tried different OSCCON; OSCCON2; OSCTUNE settings, without succes
}

数据表(1):http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf

最佳答案

Roger Rowland 回答了我的问题:

As it says in section 2.6.1 of the datasheet, CLKOUT will be Fosc/4 when used with the internal oscillator. If you've configured a 1MHz oscillator then you should expect to see 250KHz on CLKOUT, which represents the rate at which instructions are executed (4 clock cycles per instruction on these PICs). Everything is working as expected.

关于c - PIC18F45K22内部振荡器频率问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33681909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com