完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
这是来自DS61120E页12-3(IO端口部分)的引用。我在PIC32 MX170上有一些代码,看起来像这样:意图是翻转PIN,然后如果PIN被设置为逻辑1,那么做一些事情。但是,当我很慢地调用这个函数(比如每隔几秒钟),并且用范围监视PIN时,我发现当PIN已经变低时,条件会被评估为真。然而,工作如预期。从同一手册中的图中,我期望在端口中写入的值在端口寄存器中大约2个时钟周期之后被反转PIN(即在两个触发器用于防止亚稳状态并同步输入已经计时)之后。这是正确的吗?
以上来自于百度翻译 以下为原文 This is a quote from DS61120E-page 12-3 (the IO port section). I have some code on my PIC32MX170 that looks like this: LATBINV = 0x8000; if ( PORTB & 0x8000 ){ // do something } the intention being to flip the pin and then do something if the pin is set to logic 1. However, when I call this function very slowly (say every few seconds) and monitor the pin with the scope, I see that the condition evaluates true when the pin has gone low. However: LATBINV = 0x8000; if ( LATB & 0x8000 ){ // do something } works as expected. From the diagram in the same manual, I would expect the value that has been written in the port to be in the PORT register about 2 clock cycles after inverting the pin (i.e. after the two flip flops used to guard against metastable states and sync the input have clocked). Is this correct? |
|
相关推荐
3个回答
|
|
|
在这个引脚上有多少负载和电容?第一种形式是读取实际的引脚电压,因此如果需要多个时钟周期从高到低或者反之亦然,那么您可以在它完全转换之前进行测试。
以上来自于百度翻译 以下为原文 How much load & capacitance do you have on that pin? The first form is reading the actual pin voltage, so if it takes multiple clock cycles to change from high to low or vice-versa, then you could be testing before it has fully transitioned. Testing the LAT register avoids that problem. |
|
|
|
|
|
释义QYB,端口是上次GPIO同步时真正存在的地方,而LAT则是你打算放在那里的。如果有一个大的RC时间常数,端口可能不等于LAT.优化时,你可能要查看程序集,以确保端口在L之前没有被采样。正在写!如果有一个外部驱动器与PIC(除了警告,这将损害部分),端口可能永远不等于LAT.
以上来自于百度翻译 以下为原文 paraphrasing qyb, PORT is what was really there the last time the GPIO synchronized, etc., while LAT is what you intended to put there. If there is a large RC time constant, PORT may not yet equal LAT. With optimization, you might want to look at the assembly to make sure PORT wasn't sampled before LAT was written! If there is an external driver fighting the PIC (aside from the caveat that this will damage the part), PORT may never equal LAT. |
|
|
|
|
|
该引脚通过2K4电阻驱动光耦合器。在管脚处测量的上升时间约为5Ns。我认为没有硬件问题。芯片的时钟恰好超过21MHz,这也应该是SysCLCK查看每个用例的解体,我只能看到数据表中所示的“同步”占用了两个以上的SysCLK周期来读取引脚(3计数一个值)。到别针)我的MIPS汇编程序不是很好(不存在!)-这些指令每次需要两个时钟周期吗?这不是一个真正的问题,阅读LATB是好的-只是一个有趣的“陷阱”,我认为它是值得记录。
以上来自于百度翻译 以下为原文 The pin is driving an optocoupler via a 2k4 resistor. The rise time measured at the pin is about 5ns. There are no hardware issues I think. The chip is clocking at just over 21MHz, which should also be SYSCLK Looking at the disassembly of each case 369: LATBINV = 0x4000; 9D008FFC 3C02BF88 LUI V0, -16504 9D009000 24034000 ADDIU V1, ZERO, 16384 9D009004 AC43613C SW V1, 24892(V0) 370: if ( LATB & 0x4000 ) { // inc or dec the pulse count 9D009008 3C02BF88 LUI V0, -16504 9D00900C 8C426130 LW V0, 24880(V0) 9D009010 30424000 ANDI V0, V0, 16384 9D009014 10400015 BEQ V0, ZERO, 0x9D00906C 9D009018 00000000 NOP and 369: LATBINV = 0x4000; 9D008FFC 3C02BF88 LUI V0, -16504 9D009000 24034000 ADDIU V1, ZERO, 16384 9D009004 AC43613C SW V1, 24892(V0) 370: if ( PORTB & 0x4000 ) { // inc or dec the pulse count 9D009008 3C02BF88 LUI V0, -16504 9D00900C 8C426120 LW V0, 24864(V0) 9D009010 30424000 ANDI V0, V0, 16384 9D009014 10400015 BEQ V0, ZERO, 0x9D00906C 9D009018 00000000 NOP The only explanation I can see is that the "synchronisation" as shown in the data sheet is taking a bit more than two cycles of SYSCLK to read back the pin (3 counting one towrite the value to the pin). My MIPS assembler is not that great (non-existent!) - do these instructions take two clock cycles each? It's not really an issue,reading the LATB is fine - just an interesting "gotcha" I thought it was worth documenting. |
|
|
|
|
只有小组成员才能发言,加入小组>>
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:27 , Processed in 0.783194 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2462