Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to divide oscillator frequency?

Status
Not open for further replies.

hiren_dave

Member level 1
Member level 1
Joined
Jul 3, 2012
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
AHMEDABAD,INDIA
Activity points
1,535
hi,

i am using pic 18f46j11 microcontroller. my controller gives 5 times delay. i used 20mhz crystal. now if i delay particular port to 1 instruction than it gives 1us instead of 200ns. (20mhz/4=5 mhz=200ns).

i want to give delay of 200ns. how can i do that?
 

hi,

i am using pic 18f46j11 microcontroller. my controller gives 5 times delay. i used 20mhz crystal. now if i delay particular port to 1 instruction than it gives 1us instead of 200ns. (20mhz/4=5 mhz=200ns).

i want to give delay of 200ns. how can i do that?

Because 20mhz = 50 nanoseconds and each instruction execution takes 4 cycles, each instruction will take close to 200 nanoseconds to execute as you described. If you want to delay 200 ns, then simply call a NOP cycle which will cause the processor to skip on instruction (do nothing) once, delaying execution of the program by 200 ns.

in assembly the function is "NOP" and in C the function is Delay1TCY(); (void function)

Interestingly however if you try to put oscilloscope to the ports and test if you get 200 ns, you will never get it! Because many more instructions take place to blink an LED:

1. Move data to cache (200 ns)
2. move cache to port (200 ns) (LED turns on)
3. delay (NOP) (200ns)
4. move new data to cache (200 ns)
5. move cache to port (200ns) (LED turns off)

So you will get close to 1 microsecond blinks.

If you want your PIC to do things faster, get a 8 Mhz crystal and turn on Phase Locked Loop which will give you effective 48 Mhz on your particular PIC. With 48 Mhz, LED will blink at 100 ns (or at 20 ns instructions) Remember that this will consume 3 times more power and you with Phase Locked Loop you can use only UP to 8 mhz crystal.


Hope that helps!
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top