Timer Function? Not sure what I need here.


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default Timer Function? Not sure what I need here.

    I need to call a sub on a schedule, say every 30 minutes. The sub reads 8 ADC's into a VAR Array and sets PORTB based on those numbers.
    I dont need it so accurate that I would need a RTC, but I would like to get in the neiborhood of 30 minutes. and I need it to do this like an interupt where it will fire even in a pause mode.

    Here is what I need to call every 30 minutes (and optional on button would be nice but PORTB INT's are being used)

    Code:
    ReadVolts:                                                        
    For X = 0 to 7                                                    
    PORTE = X   'Activates Binary Relays
    PAUSE 100     ' Allow Relay contacts to settle before ADC Conversion                                                     
    ADCIN 0, VOLTS[X]               ' Read Channel 0 data             
    VOLTS[X] = VOLTS[X] / 13        ' 64k = ~5000 mv  (temporary math)
    if VOLTS[X] > 4000 then                                           
    PORTB.0[X] = 1                                                    
    ELSE                                                              
    PORTB.0[X] = 0                                                    
    ENDIF                                                             
    PauseUS 100                     ' Pause for ADC Refresh           
    NEXT X                                                            
    RETURN

    PORTB uses Bipolar LEDs for status indicators. I am going to assume I need to use one of the internal timers, but I have never used them. So if anyones got any ideas or code samples....
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Timer Function? Not sure what I need here.

    Have you looked at
    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    ?

    Robert

    Edit: checking if 30 minutes has passed is one possibility:
    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Last edited by Demon; - 15th April 2013 at 02:32.

  3. #3
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Timer Function? Not sure what I need here.

    yea thats a thought, I didnt think of useing darrels INT's, I havent messed with them yet. I was waiting till I had a few days to play with them and other bits of his code.

    right now I need to use a internal timer INT? I think. Using a 18F4550 chip. so something like timer1 set for every 30 minutes using DT's INT's
    I might need a second timer to run a second sub to flash a led, not sure if this can be done so that they dont conflict. will post some code in a bit as example.
    Do you think thats the best way though to do the 30 minute timer INT using DT_INTS? trying to KISS! "keep it simple stupid" want program small but stable.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Timer Function? Not sure what I need here.

    Hi,
    You probably won't be able to set up any hardware timer to interrupt at a rate as low once every 30 minutes - if you don't run the PIC REALLY slow that is.
    What you usually do is set it up to interrupt at something like 10Hz or whatever and then keep track of the number of interrupts in order to get a total of 30 minutes (18000 interrupts in this case). That way you can use the same timer and interrupt for the LED flashing and any other timing tasks you might need.

    Darrels DT-Ints are a great way to this.

    /Henrik.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Timer Function? Not sure what I need here.

    Personally, I'd check if 30 minutes elapsed; as KISS as you get.

    Check DT's thread and link to his site for details.

    Robert

Similar Threads

  1. ARCSIN function
    By mjphillips1981 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 20:19
  2. Hash function
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th September 2007, 10:09
  3. Need help with write function
    By Christopher4187 in forum General
    Replies: 10
    Last Post: - 12th July 2006, 04:12
  4. COUNT Function
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th June 2006, 06:26
  5. log10 function
    By dampf in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2004, 17:54

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