PIC and pulse generation

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


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



Re: PIC and pulse generation


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:
Quoted text here. Click to load it


Re: PIC and pulse generation


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 = .8S    or 1.25MHz




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:
Quoted text here. Click to load it



Re: PIC and pulse generation


Quoted text here. Click to load it

dunno, but you can probably go faster if you use the hardware counters.

Quoted text here. Click to load it

well documented. so RTFM.



--

Bye.
   Jasen

Re: PIC and pulse generation


Quoted text here. Click to load it

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 :)


Re: PIC and pulse generation



Quoted text here. Click to load it

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<5:4> * Tosc * TMR2 prescale value)
resolution = (log(Fosc/Fpwm) / (log(2)  )  bits

software it depends on  what you set/how you are doing it.

Quoted text here. Click to load 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



Site Timeline