Gudday
Can someone tell me, if I have a PIC running at 20 MHz and do this:-
high pin nop low pin nop high pin nop low pin
What sort of pulse width I can get ?
What is the relationship between clock freq and operations ?
Andrew
Gudday
Can someone tell me, if I have a PIC running at 20 MHz and do this:-
high pin nop low pin nop high pin nop low pin
What sort of pulse width I can get ?
What is the relationship between clock freq and operations ?
Andrew
The relationship between clock and pulse width is in the datasheet for every PIC. One instruction cycle is 4 clock cycles on every PIC I've used. You will find this reference in the section of the datasheet under "Instruction set".
You can do the calculations from there.
Glenn
Andrew Rich wrote:
dunno, but you can probably go faster if you use the hardware counters.
well documented. so RTFM.
-- Bye. Jasen
As Glenn said. For the absolute fastest speed possible, you would leave out the NOP instructions. For a normal architecture PIC at 20MHz that's 200ns per instruction. So you could achieve a theoretical maximum 2.5MHz 50/50 square wave with continuous instructions, less if your code has to loop.
Dave :)
Why not try it and see ?
How long is a no op ? and does the assembler/compiler actually insert them ?
look at using interrupts,counters or timers to get an accurate time period or use hardware pwm module(if the pic you are using has one)
For 16f877 pg 63 of the datasheet pg 210 - 213 mid range family reference manual make sure to look at the diagrams
using hardware pwm unit
pwm period = [(PR2) + 1] * 4 *Tosc * (TMR2 prescale value) pwm freq = 1/ pwm period pwm duty cycle = (CCPR1L:CCPR1 * Tosc * TMR2 prescale value) resolution = (log(Fosc/Fpwm) / (log(2) ) bits
software it depends on what you set/how you are doing it.
again depends on the pic
Had a read of the data sheet/s yet ? also the family reference manual.
assuming a 12f/16f see page 73 of mid range family reference manual
internal clock = osc1/4 or fosc = tosc/4
Alex
Glenn is right, If it takes (say) 4 clock cycles to make a output pin go high or low and 4 clock cycles for the NOP then that is 8 clock cycles per half cycle and 16 clock cycles per squarewave output,
A clock cycles is 1/20 MHz = 0.05 microseconds. So then the square wave output is 0.05*16 = .8µS or 1.25MHz
You can do the calculations from there.
Glenn
Andrew Rich wrote:
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.