完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
亲爱的所有人,也许你可以对PIC24FJ64 GA102提出建议。该设备有2个LED连接到PATA。0和PORTA。1。PATA.0是从主程序驱动(在一段时间内(真)循环)驱动的,1是由time5中断驱动的。我希望两个LED独立闪烁大约50%开/关时间。由于某种原因,这些相互冲突,例如PORTA。0似乎被Time5中断,反之亦然。这里是我的(简化)代码:int(){(1){//LoopFrimePurababITIs.Ra0=LababITS.LATA0;//Twitter PosiPoT 0Delphi(500);}//West-ReleTurn -1;这是(简化的)中断例程:ValuyAyAtthiTyx((中断,NoAuto Apple PSV))Tr5Obj.CalbBuffe(;TMR5OOB.Cuff++);TMR5Obj.TimeRelpAsHe=真;IFS1BIT.T5IF=false;} TMR5A回调(),{PATABABIT.RA1= LATABIT.LATA1;/Twitter PosiBIT 1 },这似乎是微不足道的。问题,但我忽略了一些东西。一旦我从任何一个例程(主或中断)中删除了PUABABITE语句,另一个LED就如预期的一样闪烁。有什么提示吗?提前感谢!
以上来自于百度翻译 以下为原文 Dear all, Perhaps you can advise regarding PIC24FJ64GA102. The device has 2 LED's connected to PORTA.0 and PORTA.1. PORTA.0 is driven from main routine (in a while(true) loop), PORTA.1 is driven by an interrupt from Timer5. I expected both LED's to blink independently with about 50% on/off time. For some reason, these conflict with each other, e.g. PORTA.0 seems to be swiched low by the interrupt from Timer5 and vice versa. Here is my (simplified) code: int main() { while (1) { // Loop forever PORTAbits.RA0 = ~LATAbits.LATA0; // Toggle portbit 0 delay(500); } // End while return -1; } // End main() This is the (simplified) interrupt routine: void __attribute__ ( ( interrupt, no_auto_psv ) ) _T5Interrupt ( ) { TMR5_CallBack(); tmr5_obj.count++; tmr5_obj.timerElapsed = true; IFS1bits.T5IF = false; } void TMR5_CallBack() { PORTAbits.RA1 = ~LATAbits.LATA1; // Toggle portbit 1 } It seems to be a trivial problem, but I'm overlooking something. As soon as I remove the PORTAbits statements from either routine (main or interrupt), the other LED starts blinking as expected. Any hints? Thanks in advance! |
|
相关推荐
14个回答
|
|
事实上,原子性和RMW UsLATABIT.LATA1^=1用于切换。
以上来自于百度翻译 以下为原文 Indeed, atomicity and RMW Use LATAbits.LATA1 ^= 1 for toggling |
|
|
|
如果用限流电阻正确地驱动LED,则端口I/O电压将始终在规范内,并且不会出现RMW问题。RMW问题只在外部电路过载I/O电流规范并导致电压从它应该在的位置被拉出时发生。是。
以上来自于百度翻译 以下为原文 If the LEDs are being driven correctly with a current limit resistor then the port I/O voltages will always be within spec and there will be no RMW issue. RMW issues only occur when external circuitry is overloading the I/O current spec and causing the voltage to be pulled away from where it should be. |
|
|
|
谢谢你,Cinzia,这是个骗局。Atomicity才是问题所在。
以上来自于百度翻译 以下为原文 Thank you Cinzia, that did the trick. Atomicity was the issue. |
|
|
|
另外那些引脚设置为数字模式?还是在模拟模式下留下?
以上来自于百度翻译 以下为原文 Additional are those pin set to digital mode? Or left in analog mode? |
|
|
|
嗨,Crosland,谢谢你的回答。LED有一个270欧姆串联电阻(当然)。答案来自Cinzia,原子性是我的问题。问候,Willem
以上来自于百度翻译 以下为原文 Hi Crosland, Thank you for replying. The LED's have a 270 ohm resistor in series (of course). The solution came from Cinzia, atomicity was my problem. Regards, Willem |
|
|
|
这是一个经典的读修改写案例(RMW)。写入LAT而不是端口。这是因为写入端口将在内部首先读取实际的PIN逻辑电平,改变要更改的PIN,然后回写端口中的所有位。当设置LED输出时,在实际设置到端口引脚电压达到逻辑1或0电平时需要一些时间。因此,在设置一个端口引脚高之后,它将被读取为低的时间,之后如果端口内的另一个比特被写入,那么端口引脚将返回低电平。这不会发生在LAT位上,这就是它存在的原因。
以上来自于百度翻译 以下为原文 This is a classical Read-Modify-Write case (RMW). Write to LAT instead of PORT. This happens because writing to port will internally first read the actual pin logical levels, change the pin you intend to change and then write back all of the bits in the port. When setting the LED output it will take some time between the actual setting to when the port pin voltage has reach logical 1 or 0 level. So after setting a port pin high, it will be read as low some time after which will bring the port pin back low if another bit in the port is written within this time. This will not happen for the LAT bits and is why it exists. /Ruben |
|
|
|
嗨,一种解决办法是,分别在主和中断处理程序中将每个LED的所需状态保持在单独的私有变量中,并在单向操作中将所需值分配给位,而在具有单独变量的中断例程中类似的。t个SFR地址来反转一个单位似乎有些麻烦。PIC24指令集有切换寄存器中的单位的指令,但是如果涉及两个不同的寄存器地址,则不能使用这个指令,编译器也不可能理解硬件将映射不同的加法器。可以尝试:LATAbits.LATA1^=1;LATAbits.LATA0^=1;看看编译器是否能够将此理解为同一寄存器中的位切换。
以上来自于百度翻译 以下为原文 Hi, One way to get around, could be to keep the wanted state of each LED in separate private variables in main and in the interrupt handler respectively, and assign the wanted value to the bit in a one-way operation. static bool onoff; LATAbits.LATA0 = onoff; onoff = ! onoff; and similar in the interrupt routine with a separate variable. Accessing two different SFR addresses to invert a single bit seem somewhat cumbersome. The PIC24 instruction set have instruction to Toggle a single bit in a register, but this cannot be used if there are 2 different register addresses involved, and compiler is not likely to understand that hardware will map different addresses to the same register. You may try: LATAbits.LATA1 ^= 1; and LATAbits.LATA0 ^= 1; to see if compiler may be able to understand this as a bit toggle in the same register. Regards, Mysil |
|
|
|
不,它总是需要一些时间来升高或降低引脚上的电压。如果输出电流高和/或负载电容高但仍在电流输出规格内,则需要更多的时间。
以上来自于百度翻译 以下为原文 No, it always takes some time to rise or lower the voltage on a pin. More time if the output current is high and/or the load capacitance is high but still within the current output specs. /Ruben |
|
|
|
这不应该是必要的。只需在原始文章中将PORT更改为LAT。问题不在于原子性,因为主代码不查看中断在LAT中更改的位,反之亦然。为PIC24写入单个位是一个原子操作。/ Ruben
以上来自于百度翻译 以下为原文 That should not be necessary. Just change PORT to LAT in the original post. The problem is not atomicity since main code doesn't look at the bit that the interrupt changes in LAT and vice versa. Writing to a single bit for PIC24 is an atomic operation. /Ruben |
|
|
|
不,它总是需要一些时间来升高或降低引脚上的电压。如果输出电流高和/或负载电容高但仍然在电流输出规格内,则需要更多的时间。
以上来自于百度翻译 以下为原文 No, it always takes some time to rise or lower the voltage on a pin. More time if the output current is high and/or the load capacitance is high but still within the current output specs. /Ruben That's the WRMW problem :) |
|
|
|
谢谢Ruben,这是我的第二个错误,写信给端口而不是锁存器。问题固定了,学到了一些东西;-W)
以上来自于百度翻译 以下为原文 Thanks Ruben, That was my second mistake, writing to the port instead of the latch. Problem fixed and something learned ;-) /W |
|
|
|
在ASM中,有一个指令。BTG LATB,γ0。
以上来自于百度翻译 以下为原文 In asm, there is an instruction for that. btg latb,#0 ;sensor active? mov M_Sensor_Port,w0 mov M_Sensor_Pin,w1 btst.c [w0],w1 btsc M_Flag,#MFLAG_SENSOR_LOW btg SR,#C bra c,hot ;active |
|
|
|
如果C代码是单位XORing,那么我希望它使用BTG指令。在任何一种语言中,它仍然无法寻址PORTx寄存器,并且无法寻址LATx寄存器。
以上来自于百度翻译 以下为原文 If the C code was XORing with a single bit, then I would expect it to use the BTG instruction. In either language, it would still fail addressing the PORTx register, and work addressing the LATx register. |
|
|
|
M_Sensor_Port包含一个到portx加法器的ptr,并且不会失败,因为trisx是输入的,并且它没有读取锁存器。如果设备是活动的低电平,则使用该代码将马达对中到霍尔效应传感器。,无符号int PIN,BOL ActuvLoW;
以上来自于百度翻译 以下为原文 btw. M_Sensor_Port contains a ptr to a portx addr and will not fail since trisx is input and it is not reading a latch. I use that code to center a motor to a hall effect sensor. btg is used if the device is active low. Using the zero flag to invert the carry flag. addsensor (unsigned int volatile *Port, unsigned int Pin, bool ActiveLow); |
|
|
|
只有小组成员才能发言,加入小组>>
5163 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
733浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 01:25 , Processed in 1.447827 second(s), Total 105, Slave 88 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号