完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我尝试使用PIC24F16KA304中的输入捕获模块来测量一系列脉冲的频率。我也尝试使用输出比较模块作为“额外”定时器。我计划忽略实际的输出引脚,只是使用中断。我的问题是,这两个模块都拒绝从其他定时器时钟。他们只会从内部循环时钟计时。如果我正确地理解了数据表(和参考手册),您应该能够使用ICTSEL位(用于输入捕获)和Octhell位(用于输出比较),并选择您想要使用的时钟源。但是无论我选择什么,模块总是在62.5NS(内部循环时钟)上增加。我尝试过使用不同的定时器、不同的比较/捕获模块,但似乎没有什么不同。我还检查了这个芯片的勘误表,我看不到任何可以应用的东西。我已经附加了我的“宏.Inc”文件。我已经用我的McRoWork的监视窗口验证了,但是我想我会把它们包括进去,这样你就可以运行这个代码了。
以上来自于百度翻译 以下为原文 I am trying to use the Input Capture module in a pic24f16ka304 to measure the frequency of a series of pulses. I am also trying to use the Output Compare modules as "extra" timers. I plan to ignore the actual output pin, and just use the interrupt. The problem I'm having is that both of these modules refuse to clock from other timers. They will only clock from the internal cycle clock. If I understand the datasheet (and reference manuals) correctly, you should be able to use the ICTSEL bits (for the Input Capture) and the OCTSEL bits (for the Output Compare) and pick which clock source you want to use. But no matter what I select, the modules always increment at 62.5nS (the internal cycle clock). I've tried using different timers, different compare/capture modules, but nothing seems to make a difference. I have also checked the errata for this chip, and I don't see anything that would apply here. I've attached my "macros.inc" file. I've already verified with the watch window that my macros work, but I figured I'd include them so that you can run this code if you want. ;------------------------------------------------------------------------------ ; Processor Setup ;------------------------------------------------------------------------------ .include "p24F16KA304.inc" .include "macros.inc" .list config __FOSCSEL,FNOSC_FRCPLL config __FOSC,OSCIOFNC_OFF & FCKSM_CSDCMD config __FWDT,FWDTEN_OFF config __FICD,ICS_PGx2 .global __reset .bss placeholder: .space 2 .text ;RESET VECTOR ----------------------------------------------------------------------------- __reset: BTSS OSCCON, #LOCK ;wait for the PLL to lock BRA $-2 CLR CLKDIV ;set frc postscaler to make a 32Mhz Fosc, 16Mhz Fcy, 62.5nS Tcy ;Stack Pointer Init --- MOV #__SP_init,W15 ; Initalize the Stack Pointer MOV #__SPLIM_init,W0 ; Initialize the Stack Pointer Limit Register MOV W0,SPLIM ; (__SP_init & __SPLIM_init values are calculated by linker) NOP ; Add NOP to follow SPLIM initialization ;PORT INITIALIZE ------------------------------------------------------------------------------------- CLR ANSA ;make all PORTA analog inputs digital BCLR TRISC, #RC8 ;make the output compare pin an output ;------------------------------------------------------------------------------------------------------ ;OUTPUT COMPARE INITIALIZE ----------------------------------------------------------------------------------------- CLR T1CON MOV #16, W0 ;setup timer to interrupt every 1uS MOV W0, PR1 CLR OC2R ;set OC period to 100uS MOV #100, W0 MOV W0, OC2RS mOCTSEL OC2CON1, #0b100 ;use TMR1 for clock source mSYNCSEL OC2CON2, #0b11111 ;self sync mOCM OC2CON1, #0b101 ;turn module on BSET T1CON, #TON ;---------------------------------------------------------------------------------------------------------- ;INPUT CAPTURE AND TIMERS INITIALIZE ----------------------------------------------------------------------------- ;TIMER2 (IC1 time base) TMR2 rolls over every 50uS MOV #800, W0 MOV W0, PR2 ;IC1 MOV #0x0460, W0 ;run from Timer2, interrupt every 4th capture MOV W0, IC1CON1 MOV #0x0000, W0 ;free run MOV W0, IC1CON2 MOV #0x0003, W0 ;turn on module, capture every rising edge IOR IC1CON1 BSET T2CON, #TON ;turn on the time base ;------------------------------------------------------------------------------------------------------------------- main: BRA $ .end Attachment(s) macros.txt (2.41 KB) - downloaded 21 times |
|
相关推荐
3个回答
|
|
我想我明白了。我认为您可以使用定时器作为可编程的时基,通过将它的PRX寄存器设置为您想要的任何一个,并且当计时器命中PRX值时,IC/OC模块将增加。但是,IC和OC模块似乎没有从定时器中断/溢出时钟,它们从定时器的时钟。时钟源。如果我把定时器的预分频器设置为某个值,而不是1∶1,则I/OC模块在预定速率下增加。Hmmm.…这并不像我原先想象的那么灵活。
以上来自于百度翻译 以下为原文 I think I figured it out. I thought you could use the timer as a programmable time base by setting its PRx register to whatever you wanted and that the IC/OC modules would increment when the timer hit the PRx value. But it seems the IC and OC modules do not clock from the timer interrupt/overflow, they clock from the timer's clock source. If I set the timer's prescaler to some value other than 1:1, then the IC/OC modules increment at the prescaled rate. Hmmm... that's not nearly as flexible as I'd thought originally. |
|
|
|
我认为你误解了这些模块所做的事情。它们没有自己的计数器,它们锁存或比较定时器寄存器本身的当前值。
以上来自于百度翻译 以下为原文 I think you're misunderstanding what these modules do. They don't have their own counter, they latch or compare the current value of the timer register itself. |
|
|
|
该PIC系列使用“专用定时器输入捕获”外围设备,具有自己的定时器寄存器。当您查看数据表和/或硬件参考手册中的控制寄存器ICXCON1时,可以使用ICTSEL位来选择时钟源。选择是系统时钟,Time1,Time2,Time3等等。我想如果你选择了这些定时器之一,IC模块将增加每当定时器溢出/重置。有点像一个16位的预分频器。但是我发现它不是如何工作的。如果你试图从外部源时钟IC或OC模块,我可以看到这种行为是有用的。您可以通过一个定时器模块运行外部时钟源,然后设置IC/OC模块使用该定时器。但这对我的项目没有帮助,谢谢你花时间来回答。我会重新考虑我对这个项目的编码策略,看看我是否还能使用这个PIC家族。我有一个DSPIC33 FJ64 GP206,我也可以尝试,虽然它看起来像过度使用DSP只是为了捕获/比较模块。
以上来自于百度翻译 以下为原文 This pic family uses the "Input Capture with Dedicated Timer" peripheral which has its own timer register. When you look at the control register ICxCON1 in the datasheet and/or hardware reference manual, you can use the ICTSEL bits to select the clock source. The choices are system clock, timer1, timer2, timer3, etc. I thought if you picked one of those timers, the IC module would increment whenever that timer overflowed/reset. Sort of like having a 16bit prescaler. But I found out that's not how it works. I can see this behavior being useful if you were trying to clock the IC or OC modules from an external source. You could run the external clock source through one of the timer modules and then set the IC/OC module to use that timer. But that doesn't help me for this project. Thank you for taking the time to reply. I will reconsider my coding strategy for this project and see if I can still use this pic family. I have a dspic33FJ64GP206 that I may try as well, although it seems like overkill to use a dsp just for the capture/compare modules. |
|
|
|
只有小组成员才能发言,加入小组>>
5242 浏览 9 评论
2031 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3207 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2256 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
596浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
678浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 17:50 , Processed in 1.415845 second(s), Total 83, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号