Hi all. I am using an external crystal 10MHz and would like to somehow output a 5.6MHz using software codes. For some reason, the output of my PIC has a frequency ~ 136kHz (too slow). Any ideas?
Hi all. I am using an external crystal 10MHz and would like to somehow output a 5.6MHz using software codes. For some reason, the output of my PIC has a frequency ~ 136kHz (too slow). Any ideas?
How true, thats 2.5 million "single cycle" instructions per second.
If you are using software that would be:-
Bring output pin High = 1 Cycle
Bring output pin low = 1 Cycle
Repeat = 1 cycle (I think)
So in 3 cycles a pin has been brought high and then low, so in reality you have 2.5 million cycles / 3 = .833Mhz output.
But thats not all, if you wanted a 50% duty cycle and based on the above process you would need to insert a NOP after the HIGH to compensate for the repeat instruction - so thats 4 cycles or .625Mhz.
But thats if you do it in software. If your PIC has hardware PWM the best you could do with a 10Mhz crystal would be 2.5Mhz (without all the above kerfuffle)
But thats not all, if you wanted a 50% duty cycle and based on the above process you would need to insert a NOP after the HIGH to compensate for the repeat instruction - so thats 4 cycles or .625Mhz.
Mark
I gave the PDF a quick once over, it does say you can run the system clock off of the 48mhz pll. The only thing I didn't find was what the max main system clock allowance is, just because you have a 48mhz clock doesn't mean you can use it to clock the system. You may though.
Perhaps on Pic 18f? For sure on the 12f, 16f Pics. From a strictly bit toggle case as presented, it appears to me that the same (or more?) instruction cycles are required for the AVR as the PIC. The sbi, sbc, and rjmp are all 2 cycle instructions?
Code:
START:
sbi PORTB,0
cbi PORTB,0
rjmp START
Looking at an m168 with 8Mhz intosc and its saying 1.358Mhz with my cheapo Radio Shack DVM. And for the 18f4620 Pic with an 8Mhz intosc and PLLEN enabled, measured 2Mhz.
Granted this is not likely a real world case, don't want to start a PIC-AVR throw-down either. Total newb at AVR. Perhaps there is another instruction for the AVR that improves the bit toggle code?
Once you get into the 18F series PIC vs AVR even out pretty well. That loop is a poor judgement of performance half of the instruction time is spent in rjmp's. rjmps on AVR's are 4 cycles, their jumps are their weakest point, the strongest point is the single cycle math, there is a way to simply toggle the I/O line without reading it and setting it like that but it doesn't offer more performance, just prevents you from having to read or know the state of an I/O line to toggle it. ALL AVR's have these features, where with the PIC line you have to get up into the 18F series before things start evening out.