完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我不能理解所有的定时器设置……我试图将定时器2/3设置为32位脉冲计数系统,外部时钟从电压到频率转换器输入。我查阅的文件是GB210系列和PIC24系列的家庭数据表。F手册第14章(定时器)。现在几乎在手册中定时器章节的末尾,我发现:14.13.5启用定时器为了启用定时器,必须清除定时器模块禁用位(PMD1寄存器中的TxMD)以及设置模块启用位。设置TxMD位将禁用该模块的所有时钟源,将其功耗降低到绝对最小。在这种状态下,与外围设备关联的控制和状态寄存器也将被禁用,所以对这些寄存器的写入将没有效果,读取值将无效。因此,我开始寻找PMD1.TxMD位的使用的一些解释,但是在两个文档中都没有找到。在任何地方都没有找到“模块启用位”。它的名字和登记处在什么地方?这些位有什么用途以及我应该如何使用它们,假设我在一个由TMR2和TMR3组成的32位级联定时器上操作?两个文档中的示例代码片段无法显示这一点。
以上来自于百度翻译 以下为原文 I have trouble understanding all bits and pieces of the timer settings.... I am trying to set up Timers 2/3 as a 32 bit pulse counting system with external clock input from a Voltage To Frequency Converter. The documentation I have consulted is the family data sheet for the GB210 family and the PIC24F manual chapter 14 (Timers). Now almost at the end of the Timer chapter in the manual I found this:
So I started looking for some explanation of the use of the PMD1.TxMD bit, but found nothing in either document. Also I have not found a "module enable bit" anywhere. What is its name and in what register? What purpose does these bits serve and how am I supposed to use them given that I am operating on a 32 bit concatenated timer consisting of TMR2 and TMR3? The example code snippets in either document fail to show this... |
|
相关推荐
8个回答
|
|
|
PMDx SFR(即PMD1、PMD2、PMD3等)允许通过关闭所选外围设备的时钟源来禁用所选外围设备,以减少功耗。单个位被访问为PMD1位.T2MD、PMD1位.T3MD等-只需用所需的定时器号替换TxMD中的x。PMD1 SFR位于0x0770,并且默认情况下被清除,因此在重置之后启用所有模块,所以不需要手动清除它。
以上来自于百度翻译 以下为原文 The PMDx SFRs (namely PMD1, PMD2, PMD3 etc.) allow disabling the selected peripherals by turning off their clock sources to reduce the power consumption. The individual bits are accessed as PMD1bits.T2MD, PMD1bits.T3MD etc. - just replace the x in TxMD with the required timer number. The PMD1 SFR is located at 0x0770 and is cleared by default thus enabling all modules after the reset, so you do not need to clear it manually. |
|
|
|
|
|
谢谢,这解释了模块禁用位,但是我仍然在文档中提到的另一个位有问题:在文档中找不到模块使能位……有一个吨位,但我看不到十位。而且我找不到任何方法来重置定时器/计数器,如何?这样做了吗?我有点困惑……用法:我有一个32位OC模块对的输出,它产生一个精确定时的测量门脉冲。它驱动一个外部门,当它高时,将VFC脉冲馈送给T2/3对的定时器时钟输入。NG门被配置为一个起始和结束时间,在这段时间内,脉冲累积应该发生。为了完成这一点,我必须配置并启动计时器TIM2/3关闭(开始计数为零)。至少有一个将(我相信)将输入引脚传送到TIM2的时钟输入中。我目前还没有很多硬件调试的方法,只是一个使用PIC24FJ256GB206控制器的通用放大器,许多未使用的引脚连接到连接器上。
以上来自于百度翻译 以下为原文 Thanks, this explains the module disable bit but I still have problems with the other bit to set mentioned in the documentation: I cannot find a module enable bit in the docs.... There is a TON bit but no TEN bit as far as I can see. And I could not find any way to reset the timer/counter either, how is that done? I am a bit confused still... Usage: I have an output from a 32 bit OC module pair, which produces an accurately timed measurement gate pulse. This drives an external gate that feeds the VFC pulses into the timer clock input for the T2/3 pair when it is high. When measuring something the OC output driving the gate is configured for a start and end time between which pulse accumulation is supposed to happen. So to complete this I have to configure and start the timer TIM2/3 off (with a starting count of zero). I think I have figured it all out except for this business with the disable and enable bits. At least one of these will (I believe) channel the input pin into the clock input for TIM2. And I don't presently have much in the way of hardware to debug on, just a general purpose amplifier using a PIC24FJ256GB206 controller with a number of unused pins wired out to connectors. |
|
|
|
|
|
不是所有的外围模块都有它们的“模块启用”位-例如,UART有但是定时器没有。要重置定时器,只需要将0(或者如果需要的话,任何不同的值)写入它。建议在定时器停止时执行此操作,即Ton=0。
以上来自于百度翻译 以下为原文 Not all peripheral modules have their "Module Enable" bits - e.g. the UARTs do have but the timers don't. To reset the timer you just write the 0 (or any different value if necessary) to it. It's recommended to do this while the timer is stopped, i.e. TON = 0. |
|
|
|
|
|
谢谢,这是令人困惑的。因此,Ton可能是“模块使能位”的意思。在其他情况下,“启用”使模块控制指定的PIN(通过PPS),并在未启用时释放到其他I/O(如OC系统,我刚刚编程)。似乎不是这样的。我想,当我决定仔细阅读这些文档来确定然后发现这一点时,我就把它钉牢了……我将不得不尝试用我的测试板来进行某种模拟,看看会发生什么。
以上来自于百度翻译 以下为原文 Thanks, it is confusing. So TON is probably what they mean by "module enable bit". In other cases the "enable" makes the module take control of the assigned pin (via PPS) and release it to other I/O when not enabled (like the OC system I just programmed). Seems not to be the case here. I thought I had it nailed when I decided to read through the docs carefully to make sure and then discovered this... I will have to try and wire up some kind of simulation using the test board I have and see what happens. |
|
|
|
|
|
我试着用测试板来检查这一点:-设置OC以产生输出脉冲-准备32位操作的定时器/计数器-称为OC脉冲生成函数,它在主回路中短暂延迟后输出一个脉冲:如果没有CAL,结果会有点令人沮丧。我可以看到示波器上的时钟脉冲,但是当我这样做时,这条线永远保持低位,当然计数是零。我印象中,一个PPS PIN用作一个子系统的输入(类似于一个定时器的CLK),可以同时被其他系统使用(多个)。PLE系统可以使用它作为输入,一个可以作为输出。因此,使用这个引脚作为一个常规的数字输出是合法的,我想。但是现在看来,当我为计时器设置了一个吨位时,它开始计数CLK输入上的脉冲,PIN回复到高阻抗状态,无论我写什么。插销本身没有出现插销……这是怎么工作的?
以上来自于百度翻译 以下为原文 I tried to check this using the test board as follows: - Set up the OC to generate the output pulse - Prepare the timer/counter for 32 bit operation etc - Called the OC pulse generation function, which outputs a pulse after a short delay Then in the main loop: StartVFCGate(13,700); //Start pulse generation, 13 ms long after 700 us delay StartVFCCount(); //Activate the timer23 to count pulses while (!VFCGATE_RD); //Wait until VFCGATE switches ON //Create pulses on the VFCPULSE input pin via the latch do { LATFbits.LATF5 = !LATFbits.LATF5; //Toggle the output Delay_us(0); //My delay function cannot really make accurate us delays so use shortest possible } while (VFCGATE_RD); //This generates a pulse train with about 11 us period LATFbits.LATF5 = 0; //Reset to zero afterwards pulses = GetVFCCount(); //<= Reads back zero!! The result is a bit dismal, if I do not call StartVFCCount() I can see the clock pulses on the oscilloscope, but when I do then this line stays low forever and of course the count is zero. I was under the impression that a PPS pin used as an input to a subsystem (like the CLK of a timer) could be used by other systems at the same time (multiple systems could use it as input and one as output). So using this pin as a regular digital output would be legal, I thought. But it now seems like when I set the TON bit for the timer to start it counting pulses on the CLK input that pin reverts to a high impedance state and whatever I write to the latch does not appear on the pin itself... Is this how it is supposed to work? |
|
|
|
|
|
我进一步选择了另一个用于时钟输出的引脚(RD6),然后将其连接到用作时钟输入的引脚。因此现在我在我的范围上看到输出门脉冲和测试时钟都进入定时器CLK引脚。但是它不计数……这是我的全部代码:我可以看到m上的时钟脉冲。y示波器,但是,当我中断GetVFCCount函数调用并逐步执行时,我总是读回零……我错过了什么?编辑:1)我在代码中做了一个排版,所以没有设置T32位。但是解决这个问题并没有使定时器计数.2)我切换到FCY时钟,而不是引脚:T2CONbits.TCS=0;由于它运行得如此快,所以预期会有很多计数,但仍然无法进行。计时器报告零计数…计时器23真的可以用作计数器吗?我没有设置任何比较寄存器,因为我不运行它作为一个定时器……你总是必须设置PRX寄存器吗?
以上来自于百度翻译 以下为原文 I went further and selected another pin (RD6) for clock output, which I then wired to the pin used as clock input. So now I see on my scope both the output gate pulse and my test clocks into the timer CLK pin. And yet it does not count... Here is my entire code for this: //In the init() function I have this to assign the timer clock: iPPSInput(IN_FN_PPS_T2CK,IN_PIN_PPS_RP17); //Assign TMR2/3 CLK to #32 RP17 (RF5) //My timer functions are: void InitVFC_Counter(void) { T2CON = 0; //Clear old T2 configuration T3CON = 0; //Clear old T3 configuration T2CONbits.T32 = 1; //Set 32 bit operation, also means T3CON is ignored totally (Edited typo) T2CONbits.TCS = 1; //External pin clock source T2CONbits.TCKPS = 0; //Prescaler = 1:1 } void StartVFCCount(void) { T2CONbits.TON = 0; //Make sure the timer/counter is not running first! TMR3HLD = 0; //Reset timer registers, first write MSW to the TMR3HLD reg TMR2 = 0; //Then write LSW to the TMR2 reg, HLD will automatically be written too T2CONbits.TON = 0; //Start timer 23 in 32 bit counter mode } UINT32 GetVFCCount() { UINT32 tmp, pulses; pulses = TMR2; //Read LSW of accumulator first, this also transfers MSB to TMR3HLD reg tmp = TMR3HLD; //Then read the MSW from TMR3HLD pulses += (tmp << 16); //Combine LSB and MSB return(pulses); } //And in main() I do this: InitVFC_Counter(); //Prepare for pulse counting ... TRISDbits.TRISD6 = 0; //Test pulse output pin RD6 LATDbits.LATD6 = 0; //Set pin low while(1) //Main eternal loop { StartVFCCount(); while (!VFCGATE_RD); //Wait until VFCGATE switches ON //Create pulses and feed to the VFCPULSE pin do { LATDbits.LATD6 = !LATDbits.LATD6; Delay_us(0); } while (VFCGATE_RD); LATDbits.LATD6 = 0; pulses = GetVFCCount(); Delay(30); //Wait 30 ms } I can see the clock pulses on my oscilloscope and yet when I put a break on the GetVFCCount function call and step through it I get zero read back all the time.... What have I missed? EDIT: 1) I made a typo in the code so the T32 bit was not set. But fixing this did not make the timer count. 2) I switched to the FCY clock instead of the pin: T2CONbits.TCS = 0; Expected lots of counts since it runs so fast, but still no-go. Timer reports zero count.... Can timer 23 really be used as a counter? I have not set any compare register since I do not run it as a timer.... Do you always have to set the PRx registers? |
|
|
|
|
|
首先,我错过了完全阅读我自己的代码!那我也用复制粘贴太多了!这是我用来启动计数器的代码:最后一行是第一行的副本,然后我打算更改分配的值,但显然忘记了!所以计时器毕竟没有启用…抱歉浪费大家的时间!
以上来自于百度翻译 以下为原文 Well, firstly I have missed reading my own code fully! Then also I am using copy-paste too much! This is the code I used to start the counter: void StartVFCCount(void) { T2CONbits.TON = 0; TMR3HLD = 0; TMR2 = 0; T2CONbits.TON = 0; // <== AAARRRGGGHHHH! Should be 1 of course! } The last line is a copy of the first line and then I intended to change the assigned value, but obviously forgot it! So the timer was not enabled after all.... Sorry for wasting everyone's time! |
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1122浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 00:34 , Processed in 0.839772 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3804