发 帖  
原厂入驻New
发烧友10周年庆典,全网超值优惠来袭!千元现金券,下单抽奖赶紧参与》》
[问答] 背靠背bset命令存在已知问题
75 命令 LED
分享
我刚刚开始使用PPL24 Explorer 16 EVARE板,MPLAB X IDE V3.35和APIC24FJ256GB110处理器模块。我从以前的项目中导入了一组代码,基本上有一个“永远”的循环。在这个循环中,我添加了以下代码:查看“IF”子句内容的程序集代码,我看到(反汇编的简化版本):注意,对于同一个寄存器(PORTA),有两个背靠背的“BSET”指令。在Eval板上,我期望LEDD9和D10同时发光,并且发光速率相同(尽管由于连续的汇编代码“BSET”指令,间隙很小)。但是,当我在调试器中“运行”代码时,我只看到两个LED中的一个亮了。另一条指令短暂地打开(240ns),然后随着第二条指令的打开而关闭(显然,我有一个o范围来告诉它)。就好像第二条BSET指令在某种程度上同时对要设置的原始位执行BCLR一样。如果我在IF子句本身碰到断点,然后通过I/EL子句指令单步执行,它就完美地工作了。此外,我可以重写代码中的两种方法之一,并使它像预期的那样运行(当“运行”)。这两种方式是:或者:关于问题可能有什么想法?PIC24对同一个寄存器进行背对背“BSET”指令是否真的存在一个已知问题?这似乎不太可能,但这正是我所目睹的。谢谢。

以上来自于百度翻译


      以下为原文

    I'm just starting out with the PIC24 Explorer 16 Eval board with MPLAB X IDE v3.35 and a PIC24FJ256GB110 processor module.  I've imported a bunch of code from a previous project and have basically a "while forever" loop.  Inside this loop, I've added the following code:
if (toggle == 0) {
toggle = 1;
PORTAbits.RA7 = 1;
PORTAbits.RA6 = 1;
} else {
toggle = 0;
PORTAbits.RA7 = 0;
PORTAbits.RA6 = 0;
}Looking at the assembly code for the contents of the 'if' clause, I see (shortened version of disassembly):

toggle = 1; MOV #0x1, W0
MOV W0, [W14+2]
PORTAbits.RA7 = 1; BSET PORTA, #7
PORTAbits.RA6 = 1; BSET PORTA, #6

Note that there are two back-to-back "BSET" instructions to the same register (PORTA).  On the Eval board, I expect both LEDs D9 and D10 to illuminate at the same time and rate (though with a small gap due to consecutive assembly code "BSET" instructions).  However, when I "run" the code in the debugger, I see only one of the two LEDs lit.  The other one turns on briefly (240ns) and then turns off as the second one turns on (obviously I have an o-scope to tell this).

It is as though the second BSET instruction is somehow simultaneously doing a BCLR on the original bit I wanted to set.  If I hit a breakpoint at the if clause itself and then single-step through the if/else clause instructions, it works peRFectly.  Further, I can rewrite the code one of two ways and make it work as expected (when "running").  Those two ways are:
if (toggle == 0)
{
PORTAbits.RA7 = 1;
toggle = 1;
PORTAbits.RA6 = 1;
}
else
{
PORTAbits.RA7 = 0;
toggle = 0;
PORTAbits.RA6 = 0;
}Or:
if (toggle == 0)
{
toggle = 1;
PORTA = PORTA | 0x00C0;
}
else
{
toggle = 0;
PORTA = PORTA & ~0x00C0;
}
Any thoughts on what the problem could be?  Is there REALLY a known issue with the PIC24 doing back-to-back 'BSET' instructions to the same register?  This seems highly unlikely but is what I appear to be witnessing.

Thanks.
0
2019-7-17 07:36:31   评论 分享淘帖 邀请回答
6个回答
您正在经历RMW(读修改写)问题。这是由于试图在I/O端口中设置比特太快造成的。指令首先读取端口,然后修改数据,然后写入端口。如果输出具有任何能降低状态变化的负载。使用LATX寄存器代替,这些返回的输出值不是端口的输入值。IE:LATAbits.LATA7=1等。在访问单个位时,使用PORTx进行读取,使用LATx进行写入,整个端口写入不需要这样做,Portx或latx都可以工作。

以上来自于百度翻译


      以下为原文

    You are experiencing the RMW (Read Modify Write) issue. This is caused by trying to set bits in an I/O port too fast. The instruction first READs the port then modifies the data and then WRITES the port. If the outputs have ANY load that can sow down the state change. Use the LATX registers instead, these return the output value not the input value of the port. IE: LATAbits.LATA7 = 1, etc. Use PORTx to read and LATx to write when accessing individual bits, entire port writes do not need this, either portx or latx will work.
2019-7-17 07:46:57 评论

举报

别介意。我没注意到PIC24编程的第一条规则:总是读PORT,总是写LAT。把上面的代码改为:也解决了这个问题。

以上来自于百度翻译


      以下为原文

    Never mind all.  I failed to note the first rule of PIC24 programming:  Always read the PORT, always write the LAT.  Changing the above code to:

if (toggle == 0)
{
toggle = 1;
LATAbits.LATA7 = 1;
LATAbits.LATA6 = 1;
}
else
{
toggle = 0;
LATAbits.LATA7 = 0;
LATAbits.LATA6 = 0;
}

also fixes the problem.
2019-7-17 08:05:31 评论

举报

或者你可以全部替换

以上来自于百度翻译


      以下为原文

    or you can replace it all with
 
LATA ^= 0xc0;
 
 
2019-7-17 08:14:19 评论

举报

闩锁和三脚架。

以上来自于百度翻译


      以下为原文

    Latch and Tris.
2019-7-17 08:22:27 评论

举报

嗯?这是什么增加了谈话,这还没有被转换。

以上来自于百度翻译


      以下为原文

   
Huh?
What does that add to the conversation, that has not already been convered.?
 
2019-7-17 08:33:48 评论

举报

没有讽刺,也没有提到TrISX。

以上来自于百度翻译


      以下为原文

    Without the sarcasm quite a lot and no mention of TRISx.
2019-7-17 08:39:10 评论

举报

只有小组成员才能发言,加入小组>>

46个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /10 下一条

快速回复 返回顶部 返回列表