Delay question


Closed Thread
Results 1 to 22 of 22

Thread: Delay question

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi Paul,
    New day, fresh head...
    You said:
    at 4 MHz, 3 instructions on and 3 instruction off = 6 instructions per cycle, therefore f=1000000/6=166666.667 Hz (twice that noted above)
    That is of course correct. I based my calculation on a 20Mhz so 5000000/6 = 833kHz which is what I stated in my post which is also correct (but not half of 166kHz).

    Thanks for the 16F vs 18F explanation. I guess it would take up more code to check which bank we're in before each goto instead of just setting the correct one?

    Thanks!
    /Henrik Olsson.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Red face

    Henrik,

    My apologies - you are and were indeed correct (166.667 / 2 != 833.33).

    I am guessing the 16F PBP compiler code is not optimized to check to see if it is in the same page as the goto. I bet it sets the PCLATH every time it encounters a goto just to be safe. I do not think it would add PIC code - I think it would take more compiler code to do this check - MELABS must not have thought it was not worth it to potentially save one instruction (100% guess by me)?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I think it will use the CHK?RP macro simply for safety sake. sure the code is not optimized in any sort, but it's always solid as rock. When you need something tight, use ASM. Hence, for safety sake and for none 18Xxxxx your asm example could be...
    Code:
    ASM
        CHK?RP    ; make sure we are on the right BANK
    here
        bsf PORTB,1
        NOP
        NOP
        bcf PORTB, 1
        goto here
    ENDASM
    PORTB.1=0 call MOVE?CT macro. wich is
    Code:
    MOVE?CT macro Cin, Regout, Bitout
            CHK?RP  Regout
        if (((Cin) & 1) == 1)
            bsf     Regout, Bitout
        else
            bcf     Regout, Bitout
        endif
        endm
    there you discover the extra cycle
    Last edited by mister_e; - 6th March 2007 at 15:53.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jan 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    separate coil-capacitor Oscillator and use pic only to turn on and of this oscillation we will get Pulse Modulation

  5. #5
    Join Date
    Jan 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    it sound too simple to be true

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. RF Transmitter
    By et_Fong in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2005, 16:34
  4. Memory Space of the PIC16F84...
    By Tear in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 19:55
  5. Problem with saving to EEPROM...
    By Tear in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st July 2005, 00:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts