Hi,
As have been said, and to add a bit: HIGH/LOW are commands which not only set the pin HIGH and LOW, it also makes the pin an output even if it already IS an output. Your code, compiled for a 12F683 (yes, it's different when compiled for other targets) results in the following ASM output:All instructions takes one cycle except the GOTO which takes two and if you count the number of cycles you'll get 10. With the PIC running at 4MHz each instruction cycles takes 1us so the loop takes 10us to complete which matches your 100kHz measurement exactly.Code:_Cycle bsf GPIO, 000h bsf STATUS, RP0 bcf ((GPIO) + 80h), 000h bcf STATUS, RP0 bcf GPIO, 000h bsf STATUS, RP0 bcf ((GPIO) + 80h), 000h bcf STATUS, RP0 goto _Cycle
Now, if you'd do something like this instead:The resulting ASM code looks like this:Code:TRISIO.0 = 0 Cycle: GPIO.0 = 1 GPIO.0 = 0 Goto CycleNow the actual loop is only 4 cycles instead of 10 so you'd get 250kHz instead of 100kHz when operating the PIC at 4MHz - quite a difference.Code:. bsf STATUS, RP0 bcf TRISIO, 000h bcf STATUS, RP0 _Cycle bsf GPIO, 000h bcf GPIO, 000h goto _Cycle
/Henrik.




Bookmarks