Not to muddy the waters because it sounds like you have decided on another route, but for completeness ...
at 4 MHz, 3 instructions on and 3 instruction off = 6 instructions per cycle, therefore f=1000000/6=166666.667 Hz (twice that noted above)Code:Start: PortB.1 = 1 'Set pin high @ NOP 'Wait....Two NOP's are neede if we want 50% dutycycle @ NOP 'since the GOTO takes two instruction cylcles. PortB.1 = 0 'Set pin low Goto Start 'Do it again. The GOTO takes the same time as two NOP's
Interestingly enough the above code does 3 instructions on and 4 instructions off on 16F devices and 3 on 3 off on 18F (at least on an 18F877A and 18F452, respectively). To combat this on the 16F's, you could do something like this in ASM
Good LuckCode:ASM here bsf PORTB,1 NOP NOP bcf PORTB, 1 goto here ENDASM




Bookmarks