Em 17/1/2012 15:17, Oli Glaser escreveu: > On 13/01/2012 17:29, Isaac Marino Bavaresco wrote: >> Em 13/1/2012 15:08, Andre Abelian escreveu: >>> Hi all, >>> >>> I am testing pic32 and something simple I am having hard time to unders= tand. >>> I have 2 leds connected to G12 and G14 when I use test1 code LED1 never= tuns on. >>> test2 and test3 is ok. my question is why test1 is not working. G12 and= G13 are digital I/O. >>> if i use debugger step over it works. >>> >>> test1: >>> LED1 =3D 1; >>> LED2 =3D 0; >>> delay; >>> LED1 =3D0; >>> LED2=3D1; >>> delay >>> >>> >>> >>> test2: >>> if I use& and | logic it works >>> >>> LED1 | =3D 1; >>> LED2& =3D 0; >>> delay; >>> LED1&=3D0; >>> LED2 |=3D1; >>> delay >>> >>> test3: >>> if I use LATGSET and LATGCLR it works >>> >>> Since G12 and G14 are not analog pins and I do not have external capaci= tor I do not think this is Read modify write issue. >>> my question is do you know why test1 LED1 stays off when running. >>> >>> here is the code. >>> >>> while(1) >>> { >>> int short_delay; >>> uint8_t returnStatus1,returnStatus2; // to test >>> >>> // led_d7_green&=3D 0; >>> // led_d8_green |=3D 1; >>> >>> // led_d7_green =3D 0; >>> // led_d8_green =3D 1; >>> >>> LATGCLR =3D 0x5000; // 0b0101000000000000; >>> LATGSET =3D 0x1000; // 0b0001000000000000; >>> >>> short_delay =3D 1000*1000; // create short delay >>> while(short_delay--){}; >>> >>> // led_d7_green |=3D 1; >>> // led_d8_green&=3D 0; >>> >>> // led_d7_green =3D 1; >>> // led_d8_green =3D 0; >>> >>> LATGCLR =3D 0x5000; // 0b0101000000000000; >>> LATGSET =3D 0x4000; // 0b0100000000000000; >>> >>> short_delay =3D 1000*1000; // create short delay >>> while(short_delay--){}; >>> >>> } >>> >>> thanks >>> >>> Andre >> Probably related to RMW (read-modify-write). When stepping-over or >> running the code that takes more instructions, there is time for the pin >> to settle before changing the other pin. >> >> When running the faster code at full speed the first pin is read with >> its previous value and written back with the older value. >> You are writing to register PORTG, right? Try writing to register LATG >> instead. >> >> >> Best regards, >> >> Isaac >> > Sounds like RMW to me too, given that it's the first LED (in the code)=20 > that doesn't turn on. For any fast port manipulations use the dedicated=20 > atomic registers (as you have done with LATGSET, etc in the other test) When not in sleep, there is a synchronization circuit that makes the signal present at the I/O pins take two SYSCLK to reach the internal bus ( Figure 12-1, page 12-3 of "PIC32 Family Reference Manual, Sect. 12 IO Ports.pdf" ). So, the PIC32 devices are subject to RMW issues irrespectively of external or internal capacitance. Always wait at least 2 SYSCLK between RMW operations. Manipulation of the LATx registers are not subject to RMW, even when not using the LATxSET, LATxCLR, etc. Isaac --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .