for/loop for a timer?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Scott's Avatar
    Scott Guest

    Angry for/loop for a timer?

    Is it possible to use a for loop to create a timer in software? It does not need to be very accurate. I cannot use timer0, timer1 or timer2 for I am already using them for user interface. See below of an example of what I am trying to achieve. It works but why will it not work correctly?

    rx:
    for i = 0 to 60000
    timer = timer + i
    pause 1
    next i

    if (timer == 60000)then
    trigger = trigger + 1
    timer = 0
    endif

    if (trigger == 1)then
    trigger = 0
    goto a2d
    else
    goto rx
    endif

    I am using a PIC16F876A @ 20Mhz. I know the instruction cycle is around 200ns and the pause is for 1ms. It takes 1000ms to equal 1sec thus 60000.

    Thanks in advance,
    Scott

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


    Did you find this post helpful? Yes | No

    Default

    What are you trying to achieve?... doing an AD conversion once per minute, otherwise keeping time in 1mS Steps?

    CounterA var word

    Loop:
    For CounterA=0 to 60000
    Pause 1
    Next CounterA
    Gosub A2D
    Goto Loop

  3. #3
    Scott's Avatar
    Scott Guest


    Did you find this post helpful? Yes | No

    Default

    I am sending data out over the GPRS network to a webserver. One minute is the minimum for the timer! I would like to be able to increment trigger every time my loop reaches 60000 with trigger = trigger + 1. My thought is that I can set "if (trigger == X)" trigger with X = 1, 2 and so on... depending on the cellular sevice provided or customers request.

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Scott,

    Scott>>I am sending data out over the GPRS network to a webserver. One minute is the minimum for the timer! I would like to be able to increment trigger every time my loop reaches 60000 with trigger = trigger + 1. My thought is that I can set "if (trigger == X)" trigger with X = 1, 2 and so on... depending on the cellular sevice provided or customers request.<<

    Use Melanies Code, Unless you *must* use a interupt. Melanies code will give you 1 minute delay, it is much shorter.

    Or you can use a another kind of loop:

    Loop:
    Pause 60000
    Gosub A2D
    Goto Loop

    If you use a interupt, this is a poor way how to do it. PBP will not call the interupt until the Pause is over with. Unless you use a assembly interupt.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  4. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 08: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