cycle length to do various tasks


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21

    Default cycle length to do various tasks

    Below is an extract from a piece of code, it is an interrupt routine triggered by TMR2 to produce a single pulse of a set length controlled by the PR2length byte sized variable. This uses Darrel Taylor's interrupt code.

    Currently the pulse length is longer than I intend it to be due to the lines of code prior to the T2CON line (turning the pulse on) and also the interrupt triggering routine. I know I need to change the PR2length variable so that it triggers earlier to produce a pulse of the correct length.

    I could do this by trial and error, though I was wondering if anybody had any experience or detail how many cycles it takes to do various tasks in PIC BASIC PRO. e.g. how many cycles it would take to copy the PR2Length variable to the PR2 register, and how long it would take to run Darrel's code to allow it to jump to the interrupt routine.

    Any information or guidance on how to find this out would be appreciated.

    Code:
    PulseRestart:
    TMR2 = 0
    PR2 = PR2length
    T2CON = %01001111 'Restart pulse length timer
    TMR1H = Tmr1LENGTH.highbyte 'Transfer the timer variables to the timer1 register
    TMR1L = tmr1LENGTH.lowbyte
    T1CON = %00010101 'Start Pulse High Timer
    pulseout = 1
    @ INT_RETURN ;RETURN
    This is using a PIC12F683

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: cycle length to do various tasks

    So you are using 2 timers to make 1 pulse?

    Well, I can say that interrupt latency can be accounted for by ADDING a reload value to the accumulated timer value.
    And nothing in your ISR is using PBP's system variables, so the handler "Type" can be ASM, which will reduce the latency to be accounted for.

    I won't go into too much detail because I think you're probably doing it the wrong way.

    What are the minimum and maximum pulse widths?
    And what is the interval between them?
    Last edited by Darrel Taylor; - 1st August 2012 at 05:09.
    DT

  3. #3
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: cycle length to do various tasks

    Darrel

    I am effectivly trying to produce a PWM signal to control a servo, I know there is lots of examples out there already, but I want to use the timers to control the time the pulse is high using tmr1 and tmr2 tells the PIC when to restart the high pulse, allows me to learn how the timers work and how to accurately control timer lengths.

    As this is a PWM signal for a servo, TMR1 produces a high pulse between 1 and 2ms and tmr2 restarts tmr1 every 20ms.

    I am still new to the whole world of programming and PIC Basic, but what variables are PBP system variables?

    Thank you for the interrupt code, it really has made setting up interrupts without using oninterrupt a dream.

    What I am interested in how many cycles it takes to set up the timer registers and also how long it takes for an interrupt to trigger? or alternatively a method to find out how long it takes to run the various bits of code?

    Many thanks for your help.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: cycle length to do various tasks

    I thought it might be for a servo.

    First, take a look at this program I did many years ago ...
    http://www.pbpgroup.com/modules/wfse...hp?articleid=2

    It uses a single timer for both the on and off times.

    As for the execution times for various statements, there is no one answer.
    It depends on what size the variables are, what bank the registers are in, and where in the code the statement is located.
    A statement like A = B can take anywhere from 2 to 8 assembly language instructions. Which at 4mhz would be 2 to 8uS.

    For getting in and out of the interrupt, the differences are even greater depending on the type of handler used.

    The PWPS program accounts for those times by adding the reload values to the accumulated timer values.
    It's ISR is strickly assembly language, but the same thing can be done with DT_INTS.
    DT

  5. #5
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: cycle length to do various tasks

    That program was an interesting read thank you. It certainly makes me think I should consider learning some assembly code, to allow me to control the number of cycles of time critical programs and also ensure that variables are saved in certain banks so the PIC does not need to spend time jumping from one bank to the other when running a critical task.

    For the time being I will stick with DT-INTS as I believe writing my own assembly level interrupt is seriously beyond me. Maybe something to try in a few years.

    I think I'll spend sometime adjusting the numbers being loaded into the various timer registers and see if I can learn some assembly code.

    Thanks for your help

Members who have read this thread : 1

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