Help with Comparator and Timer0


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    52

    Default Help with Comparator and Timer0

    I have been trying to write some code around the GIF that Darrel Taylor showed me but with mixed results. I have included the GIF and the code. Can someone take a look at it to see if what I am doing is a start? I am just using the LED to see if anything is working. It flashes but not when I expect it should

    Thanks Don

    (From Darrel Taylor)
    I'll second the Comparator idea, but with a little difference. (Don't filter the signal)

    Set a timer to have a delay of 20ms or more.
    Using the comparator Interrupts, reload that timer every time you get a pulse.

    If the voltage drops below the comparator's trigger point, the timer will overflow.
    Use the timer interrupt/flag to determine when there's an error condition

    Here is what I have for code:
    Code:
    OSCCON = $60      'Set up oscillator 4mhz
    CMCON = %11000001
    TRISB = %00000000 'Set port B to output
    TRISA = $%11111111 'Set port A to input
    T0CON = %01000110 'Set up Timer 0 Config bits prescale 128
    INTCON.7 = 1 'Enable all unmasked interrupts
    INTCON.6 = 1 'Enable all unmasked peripheral interrupts
    RCON.7 = 0 'Disable interrupt priority
    Intcon.5 = 1 'Timer 0 overflow interrupt enable bit
    PIE2.6 = 1 'Comparator interrupt enable bit
    
    Main:
          
    While Pir2.6 = 0 or Intcon.2 = 0 'Check to see if comparator interrupt bit or Timer0 interrupt bit is set
    wend   
          if TMR0IF = 1 then gosub LED
          TMR0L = $64 'Preload Timer 0 
          Pir2.6 = 0  'Clear comparator interrupt bit
          goto main
          
          
    LED:
    
          High portb.4
          pause 100
          low portb.4
          pause 100
          goto LED
          
    End
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    When you enable GIE (INTCON.7) you have to have an Interrupt Handler for it to jump to.

    If you just want to Poll the flags (as shown), then don't set GIE.
    <br>
    DT

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