GOTO statement causing jitter in output frequency, can be this fixed?


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: GOTO statement causing jitter in output frequency, can be this fixed?

    No it is not obvious, because it takes DIFFERENT times on each iteration of GOTO statement.

  2. #2
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: GOTO statement causing jitter in output frequency, can be this fixed?

    If you reduce the timebase of your analyzer so you can capture an entire set of the FOR-NEXT loop, you'll see that it's not jitter but the increased time when the FOR-NEXT loop exits and the GOTO loop occurs. You have a few extra cycles there to do the GOTO and the exit/initialization of the FOR-NEXT loop so every 16 iterations you get a small gap.

    The code I posted takes advantage of the fact that incrementing a byte from 255 just rolls over to 0, so it has the same effect as your FOR x=0 to 15 loop without the extra loop involved.

    Obviously, your pic can't do anything else but this, otherwise the timing will change. Your other option would be to setup a timer and do this in an interrupt routine but you won't be able to get exact timing with that since there can be a slight difference in the timing of when the ISR runs.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: GOTO statement causing jitter in output frequency, can be this fixed?

    And since the four pins are on the same port you could do away with the individual RMW-instructions for each pin and just do
    Code:
    x = 0
    masfrk:
      PortC = x
      x = x + 16
      pauseus 194
    goto masfrk
    Or even
    Code:
    PortC = 0
    masfrk:
      PortC = PortC + 16
      pauseus 194
    goto masfrk
    Obviously this will cause the bottom 4 bits of PortC to be 0 but it doesn't look like you're using those for anything.

Similar Threads

  1. Depending on value, SOUND statement leaves port output high
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th October 2023, 12:05
  2. Replies: 3
    Last Post: - 14th October 2016, 22:07
  3. frequency meter output
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th August 2015, 10:20
  4. Replies: 10
    Last Post: - 30th November 2009, 15:58
  5. Unwanted output signal jitter
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th January 2008, 02:31

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