完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我已经几年没有玩PICS了,有些事情已经改变了。现在我有PIC运行,我打算使用内部振荡器(非计时关键应用),但时钟似乎运行在1MHz,无论我尝试什么,我宁愿它运行在其MA。我已经设置了配置字1:我相信时钟只运行在1MHz,因为我只需要增加计数500次来创建大约1ms的延迟功能:是否有其他的设置需要被考虑来改变时钟频率?此外,无论我设置的“RSTOSC”值,它似乎没有效果,我已经尝试将其设置为低频振荡器,高频,并在两者之间。
以上来自于百度翻译 以下为原文 Hi, i have not played around with pics for several years, and some things have changed. Right now I have the PIC running, and I intended to use the internal oscillator (non timing-critical application) but the clock seems to be running at 1MHz no matter what I try, I would prefer it to run at its maximum 32MHz. I have set the configuration word 1 as follows: // CONFIG1 #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINTPLL // Power-up default value for COSC bits (HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2) #pragma config CSWEN = OFF // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled) I believe the clock is only running at 1MHz because i only have to increment count 500 times to create an approx 1ms delay function: void DELAY(int ms) //1ms delay { for(int r=ms; r>0; r--) //perform a 1ms delay ms number of times { int i = 0; while(i<500) { i++; } } } Are there any other settings that need to be considered to change the clock frequency? Also, no matter what I set the "RSTOSC" value to, it appears to have no effect, I have tried setting it to a low frequency oscillator, high frequency, and in-between. Regards, Stephen |
|
相关推荐
6个回答
|
|
设置配置位最简单的方法是:从主菜单中选择Microchip开发人员帮助解释的窗口PIC内存视图配置位。
以上来自于百度翻译 以下为原文 The easiest way to set your configuration bits is: From the main menu select Window ▶ PIC Memory Views ▶ Configuration Bits as explained in Microchip Developer Help. |
|
|
|
你是对的,我似乎已经用配置位菜单中的配置位来写代码中的配置位了。刚刚删除了我所有的内部代码配置位设置,现在似乎工作得很好。(虽然仍然不确定我的内部配置设置有什么问题,但我现在可以忍受了!)为我菜鸟的错误道歉-谢谢
以上来自于百度翻译 以下为原文 You are right, I seem to have been over-writing configuration bits in my code with the configuration bits in the configuration bits menu ! Just removed all my internal code configuration bit settings and now seems to be working well. (Although still not sure what was wrong with my internal config settings - but I can live with that for now!) Apologies for my rookie mistake - and thank you :) |
|
|
|
数据表告诉:92.2.1 HftToSCOM高频内部振荡器(HFIFOTSC)ISA精密数字控制内部时钟源,产生稳定的时钟至32 MHz。可以通过以下方法之一实现HIMToToC:将RSTOSC&LT;2:0&GT位配置字1到“110”(1 MHz)或“001”(32 MHz),以将振荡器设置在DeVePoPUP上或复位。可以通过设置HFFRQ&LT;2:0&GT位的OSCFRQ寄存器来选择HFIFOTSC频率。MeTimToSoc是一个内部时钟源,它提供两个(500千赫兹,32千赫)康斯坦钟输出。这些恒定的时钟输出可用于各种外围设备的选择,内部的NDIV & lt;3:0&Gt;OSCCON1寄存器的位允许从1:1和1:512之间的范围内划分HFIFOTSC输出,用于配置频率,您需要注册9:OSCFRQ:HFIFOTSC频率SEL。Office RealStfFrrq&lt;2:0&Gt;(1)位7- 3未实现:读取为“0”位2-0HFFRQ&LT;2:0&G::HFIFOTSC频率选择BITSNOMNIC FRQ(MHz):111=ReaveDe110=32101=16100=12011=8010=4001=2000=1注1:当RSTOSC=110(Hfimtoc 1 MHz)时,HFFRQ位将默认为“010”。复位时,当RSTOSC=001(HFIFTSC 32 MHz)时,HFFRQ位将在复位后默认为“101”。
以上来自于百度翻译 以下为原文 The datasheet tells: 9.2.2.1 HFINTOSC The High-Frequency Internal Oscillator (HFINTOSC) is a precision digitally-controlled internal clock source that produces a stable clock up to 32 MHz. The HFINTOSC can be enabled through one of the following methods: • Programming the RSTOSC<2:0> bits in Configuration Word 1 to ‘110’ (1 MHz) or ‘001’ (32 MHz) to set the oscillator upon device Power-up or Reset. • Write to the NOSC<2:0> bits of the OSCCON1 register during run-time. The HFINTOSC frequency can be selected by setting the HFFRQ<2:0> bits of the OSCFRQ register. The MFINTOSC is an internal clock source within the HFINTOSC that provides two (500 kHz, 32 kHz) constant clock outputs. These constant clock outputs are available for selection to various peripherals, internally. The NDIV<3:0> bits of the OSCCON1 register allow for division of the HFINTOSC output from a range between 1:1 and 1:512. For configurating the frequency, you need REGISTER 9-6. OSCFRQ: HFINTOSC FREQUENCY SELECTION REGISTER HFFRQ<2:0>(1) bit 7-3 Unimplemented: Read as ‘0’ bit 2-0 HFFRQ<2:0>: HFINTOSC Frequency Selection bits Nominal Freq (MHz): 111 = Reserved 110 = 32 101 = 16 100 = 12 011 = 8 010 = 4 001 = 2 000 = 1 Note 1: When RSTOSC=110 (HFINTOSC 1 MHz), the HFFRQ bits will default to ‘010’ upon Reset; when RSTOSC = 001 (HFINTOSC 32 MHz), the HFFRQ bits will default to ‘101’ upon Reset. OSCFRQbits.HFFRQ = 0b110; //32Mhz |
|
|
|
让我们来看看-while循环的500倍,每个循环大概有16个指令周期来增加,比较,和跳跃在自由模式-8MHz -所以你运行在32 MHz(8MHz×4)。延迟的一个更好的方法是使用内置宏XY-DelayuSU.()和μ-DelayyMs-(),它将基于X-TalthFRIQ定义精确的循环。一个更好的延迟方法是用定时器中断,但这可能是以后要做的。
以上来自于百度翻译 以下为原文 Let's see - 500 times around the while loop, with probably 16 instruction cycles per loop to increment, compare, and jump in free mode - 8MHz - so you are running at 32MHz (8MHz * 4). A much better way to make delays is to use the built-in macros __delay_us() and __delay_ms() which will make precise loops based on the _XTAL_FREQ define. A much much better way to make delays is with a timer interrupt, but maybe that's for later. |
|
|
|
谢谢你。我怀疑我犯了一个错误的假设:一个增量循环不是一个时钟周期——哎呀!我估计1MHz有点小,我想,我肯定比我想的要更接近32兆赫。关于配置位——我现在意识到我不喜欢使用微芯片中的配置位菜单——它们似乎一直拖欠到一些我不想要的值。在C代码定义区域中保留我的配置位语句。我认为使用配置位菜单修复了问题,因为我看到了LED昏暗(假设它现在以更快的速度闪烁),但事实是,在我第二次点击程序时,它已经默认回到外部时钟,我不想每次重新编程PI时设置那个菜单。有人已经提到过用1秒的时钟给我计时,这是我接下来要研究的问题。不管怎样,谢谢大家的帮助。史蒂芬,
以上来自于百度翻译 以下为原文 Thank you mbrowning. I suspected that I made an erroneous assumption that a increment loop is not a single clock cycle - whoops! My estimation of 1MHz was a little off I suppose ;) I definitely am/was always much closer to to 32MHz than I thought. About the configuration bits - I realize now that I do not like to use the configuration bits menu in microchip - they seem to keep defaulting to some value I do not want - I have decided to leave my configuration bit statements in the C code definitions area. I thought using the configuration bits menu fixed the problem because I saw the LED dim (assuming it was flashing at a much faster rate now) but the truth was it had defaulted back to the external clock the second time i clicked program, I don't want to set up that menu every time I reprogram my PIC. Someone had already previously mentioned using timer interrupts to me for a 1ms clock, that'll be the next thing I will look into. Regardless, thank you all for your helpful inputs. Regards, Stephen |
|
|
|
也不要让编译器优化器靠近那个延迟循环代码,否则它将删除整个苏珊。
以上来自于百度翻译 以下为原文 Also don't let the compiler optimiser get near that delay loop code or it will remove the whole lot. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5140 浏览 9 评论
1988 浏览 8 评论
1917 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3159 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2215 浏览 5 评论
708浏览 1评论
598浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
480浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
609浏览 0评论
505浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-8 18:30 , Processed in 1.350590 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号