counter/ internal clock


Closed Thread
Results 1 to 11 of 11

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    DT

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


    Did you find this post helpful? Yes | No

    Default

    > Accuracy is not very important so long as its approximatly 1sec.

    Darrel - You forgot to list the obvious...

    PAUSE 1000

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


    Did you find this post helpful? Yes | No

    Default



    So true.

    _
    DT

  4. #4
    Join Date
    Apr 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    thanks for the replies

    i cant use pause as i have other processes that need to be run..

  5. #5
    Join Date
    Apr 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    can anyone help with the following code as its not working

    i'm trying to set the output to 100 if the timer is less than 5000 and 001 if its above....


    Code:
    device = 16F876a  	   			  	  	   'PIC device
    CMCON = 7 								   'disable comparators
    TRISB = %11111111 						   'Portb as inputs
    TRISA = %00000000 						   'Porta as outputs
    porta = %00000000 						   'Set all outputs low
    
    T1CON.0=0 'stop the timer
    TMR1H = 0 'Set the high part of the timer value to 0
    TMR1L = 0 'Set the low part of the timer value to 0
    T1CON.0=1 'start the timer
    
    MyCount VAR WORD
    
    Start:
    
    MyCount.HighByte = TMR0H	'Get high byte of counter
    MyCount.LowByte = TMR0L		'Get low byte of counter
     
    IF MyCount > 5000 THEN 'if the timer value > than your number
    
    porta = %00000001
    
    gosub timer_reset
    
    else
    
    porta = %00000100
    
    endif 
       
    Goto Start
    
    
    
    timer_reset:
    
    T1CON.0=0 'stop the timer
    TMR1H = 0 'Set the high part of the timer value to 0
    TMR1L = 0 'Set the low part of the timer value to 0
    T1CON.0=1 'start the timer
    
    return

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


    Did you find this post helpful? Yes | No

    Default

    OK, i see you have disabled the analog comparator, but not the ADCs

    ADCON1=7

    And... seems to miss some TIMER setting, like clock source, prescaller, Prescaller assignment.

    AND, maybe i'm wrong but TIMER0 on this one is a 8 bit counter....

    and have a closer look to those
    Code:
    MyCount.HighByte = TMR0H	'Get high byte of counter
    MyCount.LowByte = TMR0L		'Get low byte of counter
    maybe it's a copy/paste mistake too
    Last edited by mister_e; - 29th April 2007 at 16:16.
    Steve

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

  7. #7
    Join Date
    Apr 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help

    It seems I’m barking up the wrong tree then as I don't want to use an external clock source, and i can’t interrupt the program or pause it.


    Is it possible simply to increment a variable every execution cycle?

    i.e.

    tick var byte
    tick_flag var byte


    start:

    If tick > 99 then

    Tick = 0
    tick_flag = 1

    Else

    tick = tick + 1

    End if

    Goto start ‘ loop

    But how can I approximate this to a time scale I can use. The datasheet state the execution cycle time as 1uS , forgive my ignorance but does that mean the above code will increment every 1uS ?

Similar Threads

  1. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 18:44
  2. Setting up internal clock correctly?
    By JohnM in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th March 2008, 21:29
  3. Replies: 14
    Last Post: - 26th September 2007, 06:41
  4. 16F688 Internal clock and MCLR
    By manxman in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th August 2007, 19:38
  5. 16F628 Internal clock
    By srob in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th February 2007, 19:46

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