Connect with us

PIC and pulse generation

Discussion in 'Hobby Electronics' started by Andrew Rich, Jan 1, 2007.

Scroll to continue with content
  1. Andrew Rich

    Andrew Rich Guest

    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
     
  2. Glenn

    Glenn Guest

    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
     
  3. jasen

    jasen Guest

    dunno, but you can probably go faster if you use the hardware counters.
    well documented. so RTFM.
     
  4. 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 :)
     
  5. Alex Gibson

    Alex Gibson Guest

    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.
    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
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-