using counter using basic


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

    Default using counter using basic

    How to use counter in pic16f628 using picbasic pro?

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


    Did you find this post helpful? Yes | No

    Default

    Wich counter? The PIC TIMER0,1,2?

    Code:
        '
        '    PIC Configuration
        '    =================
    
    	@ __CONFIG  _HS_OSC & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON  
        DEFINE OSC 20    
        '
        '    Hardware configuration
        '    ======================
        TRISB=%11111111            ' PORTB<7:0> => all set to input
        T1CON = %00000110          ' TIMER1 counter :
                                   '        Prescaller 1:1
                                   '        Oscillator shut off
                                   '        no synchronisation
                                   '        use PORTB.6 as clock input
    
        '   
        '    Variables/Alias definition 
        '    ==========================
        TMR1ON      VAR T1CON.0
        CounterA    VAR WORD
    
    Start: 
        TMR1L=0                  ' Clear 
        TMR1H=0                  '       Counter
                                 ' 
        TMR1ON=1                 ' Start counter
        PAUSE 1000               ' Sampling time               
        TMR1ON=0                 ' Stop counter
                                 '
        CounterA.HIGHBYTE=TMR1H  ' Get results                          
        CounterA.LOWBYTE=TMR1L   ' 
        '
        '  Blah blah blah
        '
        goto start
    Last edited by mister_e; - 18th May 2006 at 15:28.
    Steve

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

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Question How to setup TIMER2 as a counter?

    Hi Steve,

    I have succesfully set up Timer0 and Timer1 as counters individually working in the background (F877).

    As I need one more counter, and went through the Data Sheet, how do I set Timer2 as a counter?

    Data sheet says in "Microcontroller Core Features" that "Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler".

    However, there is no mention of counter in "7.0 TIMER2 MODULE" section in the data sheet.

    Am I missing a key point here, and thus Timer2 can not be used as a counter from an external source?


    Thanks in advance.

    ---------
    Last edited by sayzer; - 20th August 2006 at 18:31.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    From what i remind, Timer2 is unfortunately just a timer and have something to do with the HPWM and CCP2 module.. not a counter. But timer0, timer1 can be used as counter.

    In your case you could also use any interrupt source and increment a variable in the ISR.
    Steve

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

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05

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