完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我刚刚开始使用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. |
|
相关推荐
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. |
|
|
|
别介意。我没注意到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. |
|
|
|
|
|
|
|
|
|
|
|
嗯?这是什么增加了谈话,这还没有被转换。
以上来自于百度翻译 以下为原文 Huh? What does that add to the conversation, that has not already been convered.? |
|
|
|
没有讽刺,也没有提到TrISX。
以上来自于百度翻译 以下为原文 Without the sarcasm quite a lot and no mention of TRISx. |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
727浏览 1评论
612浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
501浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
626浏览 0评论
524浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 00:50 , Processed in 1.690602 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号