Timing Error with 12F629


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default Timing Error with 12F629

    I am trying to create a continuous pwm waveform by setting an output pin high then low for specific time periods. Yes, I know there is a PIC12F683 that would do this for me using onboard hardware pwm. However, my p.c. boards are designed for the 12F629 which is absent this feature.

    I want a 5000 hz pwm frequency, and to run for 40 seconds. This should equate to 200,000 cycles. My code is designed to count this many cycles and then stop. However, when testing the actual hardware the run time is about 93 seconds. This is an huge error so something is seriously wrong.

    I will post the code when I figure out how to do that (It's very short). In the meantime looking for troubleshooting ideas.

  2. #2


    Did you find this post helpful? Yes | No

    Default 12F629 Timing Problem

    Code as follows:

    i var byte
    time var byte
    counter var word

    time = 40 '(40 second run time)

    for i = 1 to 10
    counter = 0
    while counter < time*500 '(40*500*10 = 200,000)
    GPIO.4 = 1 '(75% duty cyle)
    pauseus 150 '(pwm = 5000 hz (.000200 sec. period))
    GPIO.4 = 0
    pauseus 50
    counter = counter+1
    wend
    next

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    HI Dick,
    Have you checked the oscillator DEFINES, etc?

    Arch

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi Arch,

    I forgot to mention that the 12F629 is running with the internal 4 mhz oscillator. Set by configuration: @device intrc_osc_noclkout.

    Dick

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Dick,

    94 seconds is about right. If you run this through MPLAB with a breakpoint
    set on NEXT, you'll see it takes 9.4 seconds total just to reach NEXT.

    Run through 10-times, and you end up with around 94 seconds to complete
    your 10 pass loop.

    You're forgetting to add-in the over-head for PBP commands.

    Code:
    for i = 1 to 10
    counter = 0
    while counter < time*500 '(40*500*10 = 200,000)
    GPIO.4 = 1 '(75% duty cyle) 
    pauseus 150 '(pwm = 5000 hz (.000200 sec. period))
    GPIO.4 = 0
    pauseus 50
    counter = counter+1
    wend
    next ' <-- Takes 9.4 seconds to get here the first time
    Try it with these changes for around 40.0366 S.

    Time = 29
    while counter < time*493
    Last edited by Bruce; - 2nd March 2005 at 01:18.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Dear Bruce,

    Thanks for your response and your astute trouble-shoot of the problem. The suggested fix does work.

    I had a suspicion that code execution time was the culprit, but had no way of checking for the overhead time. I am surprised that it adds to so much error. I gotta get some tools to do that kind of debugging. Isn't MPLAB an assembly language code development suite?

    Thanks,

    Dick

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


    Did you find this post helpful? Yes | No

    Default

    Under MPLAB, you can include language suite. See Melabs website to get the patch and procedure for that

    click here
    Steve

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

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Dick,

    Thanks for your response and your astute trouble-shoot of the problem. The suggested fix does work.

    I had a suspicion that code execution time was the culprit, but had no way of checking for the overhead time. I am surprised that it adds to so much error. I gotta get some tools to do that kind of debugging.
    You're very welcome.
    Isn't MPLAB an assembly language code development suite?
    Not at all. MPLAB works with most C compilers, PBP & PBC. It's a de-bugging/learning tool for the PIC. It's also free. My favorite price..;o]

    I highly recommend anyone using the PIC get familiar with MPLAB. It can save you countless hours of head-banging.

    FYI: PBP uses a library. Even simple BASIC commands like serin, pulsout, count, while/wend, for next, etc, will generate many lines of code in assembly language. Some will generate "pages" of asembly code depending on the complexity of the command/library routine.

    With MPLAB you can see all of this, and get a better idea of the over-head & time it takes for certain BASIC library routines (BASIC commands) to execute.

    Here's how to install & set MPLAB up with PBP:
    http://www.microengineeringlabs.com/support/mplab.htm

    TIP: Get familiar with setting breakpoints & using the stopwatch to see how long PBP commands take to execute. Very handy stuff, and definitely worth the effort.

    This particular problem/scenario is a prime example of why it's handy to learn to use MPLAB.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. 12F683 serout timing
    By Hobie Cat in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st December 2009, 16:57
  2. Basic help for 12F629
    By Gene Choin in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd September 2009, 04:06
  3. sleep on 12f629
    By sirvo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th February 2007, 14:08
  4. Servo control with 12F629
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd June 2005, 23:34
  5. 12F629 I2C problems
    By AIW128ProGuy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th November 2004, 23:41

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