Maximum frequency output from a PIC


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Henrik,

    I don't have the definitive answer either, but I think that what Art is suggesting makes sense to me. I have tried moving to the beginning of the program subroutines that I use a lot in the program and the used programming code space is reduced by a good number of bytes. So, I assume that the program is also executing faster. I believe that this has something to do with the way the program memory is organized in pages in many PICs.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi,
    On the 12F683 and 16F819 there is only one page of program memory so it doesn't (or shouldn't if my reasoning is correct) matter where you put anything because there will never be a need to switch pages.

    If I understand what Art wrote correctly he's basically claiming that the "further" the GOTO jump is, the longer it takes and the further "down the list" your subroutines are placed the longer it takes to GOSUB them because the program counter starts "searching for them" from the beginning of the program. I don't think that is correct - neither on PICs with a single memory page nor on those with multiple pages.

    If using a PIC with the program memory spanning several pages and it has to jump (GOTO or GOSUB) from ona page to another then the compiler will insert code to make sure the correct page is selected before executing the GOTO but it either does that or it doesn't and that piece of code (to select the correct page) will be always take the same amount of time (a couple of cycles I imagine), it doesn't matter where or "how far" it is going to jump.

    /Henrik.

    EDIT: Robert, which PIC did you use in the project where you moved the subroutines?
    Last edited by HenrikOlsson; - 21st September 2013 at 11:56.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    That is right sorry, I have my interpreted and compiled BASICs mixed up.

    It's probably not bad practice anyway, so that your fast code is not kicked
    out of the first page when you add picbasic's macro type commands such
    as serin/out, DTMF, SOUND, pauseus, etc.
    It also matters with C later on, to to avoid forward declarations.

    It makes me wonder now, if every goto command also has the PCLATH
    command with it, or if picbasic waits till the program extends past the 2K page (probably does).

    You also turned off the watchdog, but didn't tell PBP not to insert clrwdt commands.
    You would only need a single asm "@ clrwdt" inside the whole Main loop,
    and calculate that into your subtract from the delay time,
    but they are likely in the PAUSE commands, and factored into timing I think.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Nope, not bad practice at all, I just don't see it making any difference in this application. But again, do try it - I might be wrong!

    As for tweaking the delay time, it's a good thing to keep in mind for when timing is REALLY criticial but for this application, I don't know.... IMHO it's making things WAY more complicated than it is....

    We're talking 20ms total period time here (ideal), 15ms 'carrier on', 5ms 'carrier off'. The PIC is running at 8MHz so each instruction is 500ns, it takes two instruction cycles to GOTO Main, add another couple of instructions for the rest, lets call it 20 in total - the actual period would be 20.01ms, an error in timing of 0.05%, I think that miniscule error will be swamped by the inacuracy of the internal oscillator. Of course, it MIGHT matter but then you need something better than the internal oscillator to run it.

    /Henrik.

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Henrik,

    I think used a PIC16F727 when I did that. I think I got that idea of moving the most used subroutines to the beginning of the program when reading a post by Melanie. It had something to do with saving programming space in a PIC. I will try to find that thread later.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Henrik was right there, I was selling PBP short.
    It shouldn't matter with PBP programs under 2K anyway,
    but you'll appreciate the practice if you use another language.

    You remember the old interpreted BASIC with line numbers?
    Code:
    10 CLRSCREEN
    20 PRINT "HELLO WORLD"
    30 GOTO 20
    It's the goto in that one that searches a list to find the line/label it's after.
    In this case (30 GOTO 20), it searches from the beginning, but if the destination
    line is after the GOTO command, it searches from the GOTO command onward.
    Some interpreted Pic BASIC language (not PBP) probably does the same thing
    even if you don't need to use the line numbers anymore.

    If you just want to check a byte variable is in BANK0 to access it without switching,
    you can increment it with inline assembler.
    Code:
    @ incf _B1;
    should be the same as
    Code:
    B1 = B1 + 1;
    If byte B1 was not in BANK0, a different variable or some unassigned RAM will be incremented.

Similar Threads

  1. internal TMR for frequency output
    By Samoele in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th January 2009, 10:38
  2. How to calculate PIC sampling frequency
    By minmin in forum General
    Replies: 1
    Last Post: - 26th September 2006, 19:02
  3. Replies: 2
    Last Post: - 20th January 2006, 22:09
  4. Maximum frequency count on 16F628/4MHz
    By solara in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 23rd May 2005, 11:38
  5. Low frequency output
    By barkerben in forum General
    Replies: 5
    Last Post: - 16th November 2004, 16:25

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