Microchip
直播中

邹先莹

7年用户 222经验值
私信 关注
[问答]

请问有人可以发布一些实际工作的C代码来设置主时钟速度吗?

嗨,伙计们,我在设置主CPU的时钟速度时遇到了很大的问题。我在MPLAB配置寄存器中生成了语用设置,并将代码粘贴到myC文件中。我有一个C文件和一个汇编文件。C文件使用EXTERN调用汇编器文件。我有一个LED闪烁使用我的汇编程序。我改变乘法和除法时钟设置语用,然后编译和下载代码,我的LED仍然闪烁在同一速度。显然,主CPU时钟没有随着新的设置而改变。有人可以发布一些实际工作的C代码来设置主时钟速度吗?不管代码将CPU设置为什么速度,我只想要一些实际工作的C代码。谢谢:)Pete

以上来自于百度翻译


      以下为原文

    Hi Guys, I'm having major problems trying to set any clock speed of the main CPU.
I've generated the pragma settings in MPLAB config registers and pasted the code to my
C file. I have a C file and an Assembler file. The C file calls the assembler file using EXTERN.

I have a LED blinking away using my asssembly program.
I change the multiply and divide clock settings in pragma and then compile and download the code
and my LED still flashes at the same speed. Obviously the main CPU clock isn't being changed with the
new settings.
Can someone please post some C code that actually works to set up the main clock speed.
It doesn't matter what speed the code sets the cpu at, I just would like some C code that actually works.
Thanks guys :)
Pete

回帖(3)

罗玉婧

2019-6-13 11:23:48
FRM是一个很好的起点。第42部分:具有增强PLL的振荡器:HTTP:/WW1.MICCHIP.COM/DIXBOSS/En/DeVICEDCO/6000 1250B.PDF

以上来自于百度翻译


      以下为原文

    The FRM is a good place to start. Section 42 - Oscillators with Enhanced PLL.
 
http://ww1.microchip.com/downloads/en/DeviceDoc/60001250B.pdf
 
 
举报

朱佳婧

2019-6-13 11:35:48
AcLink 2,请共享您的代码。同时,像拉里建议的那样阅读FRM。你应该检查振荡器控制/状态寄存器,以确保事情按需要启用和配置。此外,我非常确信,您应该设置配置词来默认系统的时钟配置。我相信你提到过这一点(通过PrimaMet来设置)。无论哪种方式,你都应该确认这些配置词是通过调试和设置一个断点在你的“主”入口点停在那里,并检查振荡器寄存器(OSCCon等)。这将让你知道你的设置是否已被采纳。

以上来自于百度翻译


      以下为原文

    Acelink2, please share your code.  As well, read up the FRM as Larry suggested.  You should be checking the oscillator control/status registers to make sure things are enabled and configured as desired.  Also, I am pretty sure that you should be setting up the configuration words to default the system's clocking configuration.  I believe you mentioned this (set via pragma's).  Either way, you should confirm that these configuration words are being programmed by debugging and setting a breakpoint at your 'main' entry point to halt there and inspect oscillator registers (OSCCON, etc.).  This will let you know if your settings have been taken. 
举报

李天竹

2019-6-13 11:49:56
以上来自于百度翻译


      以下为原文

    285:                 int switch_clock_lprc() {
9D0006C4  27BDFFF8   ADDIU SP, SP, -8
9D0006C8  AFBE0004   SW S8, 4(SP)
9D0006CC  03A0F021   ADDU S8, SP, ZERO
286:                     SYSKEY = 0xaa996655;
9D0006D0  3C02BF80   LUI V0, -16512
9D0006D4  3C03AA99   LUI V1, -21863
9D0006D8  34636655   ORI V1, V1, 26197
9D0006DC  AC430030   SW V1, 48(V0)
287:                     SYSKEY = 0x556699aa;
9D0006E0  3C02BF80   LUI V0, -16512
9D0006E4  3C035566   LUI V1, 21862
9D0006E8  346399AA   ORI V1, V1, -26198
9D0006EC  AC430030   SW V1, 48(V0)
288:                     OSCCONbits.NOSC = 5;
9D0006F0  3C03BF80   LUI V1, -16512
9D0006F4  8C621200   LW V0, 4608(V1)
9D0006F8  24040005   ADDIU A0, ZERO, 5
9D0006FC  7C825204   INS V0, A0, 8, 3
9D000700  AC621200   SW V0, 4608(V1)
289:                     OSCCONbits.OSWEN = 1;
9D000704  3C03BF80   LUI V1, -16512
9D000708  8C621200   LW V0, 4608(V1)
9D00070C  24040001   ADDIU A0, ZERO, 1
9D000710  7C820004   INS V0, A0, 0, 1
9D000714  AC621200   SW V0, 4608(V1)
290:                     while (OSCCONbits.OSWEN);
9D000718  00000000   NOP
9D00071C  3C02BF80   LUI V0, -16512
9D000720  8C421200   LW V0, 4608(V0)
9D000724  30420001   ANDI V0, V0, 1
9D000728  1440FFFC   BNE V0, ZERO, 0x9D00071C
9D00072C  00000000   NOP
291:                     return 0;
9D000730  00001021   ADDU V0, ZERO, ZERO
292:                 }
9D000734  03C0E821   ADDU SP, S8, ZERO
9D000738  8FBE0004   LW S8, 4(SP)
9D00073C  27BD0008   ADDIU SP, SP, 8
9D000740  03E00008   JR RA
9D000744  00000000   NOP
举报

更多回帖

发帖
×
20
完善资料,
赚取积分