Timing inaccuracy - any ideas?


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanks for the info I didn't realise the instruction times were for assembly not pbp.

    I set up the program as suggested and got a 6.2 KHz frequency readout +/-0.1 Khz.
    The duty cycle is 50% +/-2%. (suggests about 27 us per command?)

    The trace on the scope is not square; doen't even acheive the full amplitude - almost as though there is a stray capacitance somewhere.

    I then tried the same program with the internal RC oscillator with similar results. I've checked and rechecked the circuitboard and all is as it should be.

    I returned to the external resonator, and added a 'pause 5' to each half of the main loop and got the following readout on the scope:

    Frequency 100.0 Hz
    High pulse width 5000 us
    Low pulse width 5000 us
    Cycle time 10000 us
    Duty cycle 50.00%

    Not a flicker. Perfect squarewave form. Totally mystified.
    Reprogrammed original program (cut down version as above). Same result of flickering up and down +/- 0.1% and being out by 4 ms.

    I can't progress this any further due to other commitments for now so I'll wait until I can try another resonator on Monday. Any further suggestions welcome of course.

    Many thanks

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Optech View Post
    I set up the program as suggested and got a 6.2 KHz frequency readout +/-0.1 Khz.
    The duty cycle is 50% +/-2%. (suggests about 27 us per command?)
    Well, if you would've used that program EXACTLY as I wrote it, you would've seen nothing, since there were no port assignments, no TRISIO statements, no nothing.
    So, let's see what you actually did write.
    And while you're at it, open up your program's .lst file and look thru the actual PIC assembly code. There you'll see all the instructions that the PIC is actually executing. Take a look at the datasheet, and you'll see that most ASSEMBLY instructions take one cycle, gotos/branches/calls take 2 cycles, and conditional instructions can either take one or two cycles depending on results. That's one way to figure out how fast a loop should be.

    The trace on the scope is not square; doen't even acheive the full amplitude - almost as though there is a stray capacitance somewhere.
    Then that would tell me that maybe your 'scope's probes and/or the 'scope itself isn't capable of reading higher frequencies, or maybe they need to be cal'd.

    Also, are you SURE that your CONFIG bits are being set correctly? You may think you're running 8Mhz external when you're actually running 125Khz on the internal clock, or worse, running on the 37Khz internal R/C clock.

  3. #3
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Thumbs up

    Replacement of the crystal has eliminated the instability, and with a minor adjustment of the pause values I have a sufficiently accurate cycle time for the application, so it looks like a dodgy oscillator was the cause of the problem.

    Many thanks for all the advice - it's been an education.

Similar Threads

  1. Any Ideas for a cheap touch sensor??????
    By rsocor01 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 19th October 2013, 01:33
  2. 12F683 serout timing
    By Hobie Cat in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st December 2009, 17:57
  3. 18F2550 timing
    By sstt1976 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 22nd August 2008, 01:30
  4. A category for Project Ideas
    By Pic_User in forum Forum Requests
    Replies: 2
    Last Post: - 23rd June 2006, 08:29
  5. HSEROUT buffering and timing - 16F88
    By picster in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th March 2006, 18:52

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