• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to translate a frequency in PIC

Status
Not open for further replies.

jenniferkpj

New Member
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?

Thanks!
 

ericgibbs

Well-Known Member
Most Helpful Member
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?

Thanks!
hi J,
The PIC divides the crystal freq by 4, so the 'internal' clock is 2.5MHz.!

Cant say about the '136KHz' freq you havnt posted your code.:)
 

UTMonkey

New Member
The PIC divides the crystal freq by 4, so the 'internal' clock is 2.5MHz.!
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)

Feel free to correct my maths.

All the best.

Mark
 
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
If the OP han an 18f Pic with HSPLL, than you are back to 2.5Mhz (4x.625Mhz = 2.5Mhz).

Code:
MAIN
	bsf	PORTB,5,ACCESS
	bcf	PORTB,5,ACCESS
	goto	MAIN
 

UTMonkey

New Member
Never mucked around with HSPLL (he says not having the faintest idea).

You still need the NOP though in your code.
 

monkeybiter

Member
If I remember rightly chips such 18f4550 can generate a clock of 48MHz from a 4MHz input [neccessary for usb operation]
 

Sceadwian

Banned
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.
 
Last edited:
Never mucked around with HSPLL (he says not having the faintest idea).

You still need the NOP though in your code.
High Speed Phase Lock Loop, not that I understand it completely either, 4x clock multiplier. Agreed, the duty cycle not symmetric with my example.

The 18fxxkxx has a HSPLL of 64Mhz for 16 Mips.
 

Sceadwian

Banned
I'd rather run an AVR at 20mhz and get 20MIPS =)
 
I'd rather run an AVR at 20mhz and get 20MIPS =)
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?
 

Sceadwian

Banned
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.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top