Timing in PICBasic Pro commands


Closed Thread
Results 1 to 5 of 5
  1. #1
    freelancebee's Avatar
    freelancebee Guest

    Question Timing in PICBasic Pro commands

    Hi All:
    Thank you for your threads and posts by reading
    them I was able speed up process of learning PICs.
    I could not find information about time intervals
    or chart for specific statements or commands.
    In applications where time is critical is best way
    to calculate time needed for specific group of
    PicBasic statements or group of assembler
    statements or single command to avoid a mistakes.
    In Visual Basic Timer function can be used
    to record the starting and ending times
    for a series of commands.
    What kind of software tools I able to use
    when compile program to calculate time
    needed to run specific group of commands?
    I appreciate your help.
    Best Regards,
    Leonid

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


    Did you find this post helpful? Yes | No

    Default

    Use Timer1 something like this;
    Code:
    DEFINE OSC 20
    DEFINE LOADER_USED 1
    
        Symbol T1IF  = PIR1.0    ' Timer1 TMR1IF overflow flag bit
        SYMBOL TMR1ON = T1CON.0  ' Timer1 ON/OFF control bit
        T1CON = 0                ' Prescaler = 1:1,  Timer off
        Cycles  Var Word         ' Holds Timer1 counts
    
    Main:
        TMR1H = 0
        TMR1L = 0
        T1IF = 0    ' Clear timer1 int flag  
        T1CON = 1   ' Start timer
    
    ' --- Insert PBP commands or groups to time below
    ' --- MAX time @ 20MHz = 65,536 x 200nS = 13.1072mS
    ' --- MAX time @ 4MHz = 65,536 * 1uS = 65.536mS
    ' --- with 1:1 prescale on TMR1.
    
        serout2 0,16416,["ABC",13,10] ' Send 5 bytes at 19,200 bps
    
    ' ----------------------------------------
        T1CON = 0                ' Stop Timer1
        Cycles.lowbyte = TMR1L   ' Get low byte
        Cycles.highbyte = TMR1H  ' Get high byte
        
        ' Display Time result
        Hserout ["Timer1 Ticks = ",Dec Cycles,13,10]
        IF T1IF THEN
            HSEROUT ["TMR1 Over-flow, add 65,536 cycles to result",13,10]
            T1IF = 0
        ENDIF
        PAUSE 1000
        
    Here:
        Goto Here   ' Sit & spin after measurements
    Regards,

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

  3. #3
    freelancebee's Avatar
    freelancebee Guest


    Did you find this post helpful? Yes | No

    Question Timing in PICBASIC commands

    Hi Bruce:
    Thank you for your time.
    The code you wrote will really help.
    Thank you again.
    For some kind of tasks need 36 hours to complete production cycle.
    During this working time cycle PIC has to work by changing output codes
    depends from pre-programmed time intervals for example 90 minutes and
    preprogrammed speed, temperature, or current=load and real conditions
    on sensors.
    Time=0
    Start speed1, temperature1, or current=load1......
    Time 90 min
    Speed2, Temperature2, Current load 2......
    Time 180
    Speed3, Temperature3, Current load3.......
    ....
    Time 2160 min = 36 hours
    Stop
    What is your suggestion or what kind solution for 36 hour cycle is real
    and cheapest one:
    - use external pre-programmed IC Timer on interrupt
    - Use external EEPROM as counter and flag on interrupt
    - use sources of PIC - EEPROM counter and flag on interrupt
    Thank you again.
    Best Regards,
    Leonid

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


    Did you find this post helpful? Yes | No

    Default

    Tons of different way i guess but one of my favourite is an external RTC like DS1307. You can even use an internal timer to do it too. OR depending what else your PIC do, do everything in a loop with a mix of PAUSE and incrementing few variables like secondes/minutes/hours/day/week/month/year
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    and that thread should give you an easy to implement solution
    http://www.picbasic.co.uk/forum/showthread.php?t=190
    Steve

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

Similar Threads

  1. PicBasic Pro Demo
    By nbrucew in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th August 2009, 19:10
  2. Replies: 4
    Last Post: - 5th October 2008, 09:11
  3. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  4. Question for all that use MELABS PICBASIC PRO
    By oskuro in forum Off Topic
    Replies: 2
    Last Post: - 24th March 2005, 17:15
  5. PicBasic Pro & PicBasic syntax different
    By Billyc in forum General
    Replies: 5
    Last Post: - 16th April 2004, 21:19

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