Analog comparator in action


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612

    Default Re: Analog comparator in action

    Hi,
    Sorry, I don't know anything about that document and the link just takes me to dead end.

    Using the comparators in the PIC is like using any comparator except you "connect" the various inputs and outputs to different things (I/O-pin, internal peripherals etc) using bits in a register. What the bits in those registers do is spelled out in the datasheet, what to set the register TO totally depends on what it is you want to do.

    This application note from Microchip has a bunch of tips and tricks for using the comparators, perhaps it'll help.

    /Henrik.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653

    Default Re: Analog comparator in action

    looking for that one ???

    Code:
    Making all these decisions and calculations was the hard bit (honest)... the easy bit is the programming... 
    
    
    
    ' 
    ' Program BatLo 
    ' ============ 
    ' Embedded Software Version 1.00 
    ' Target Processor PIC16F628-04/P 
    ' Target PCB BB-001 
    ' 
    
    Created 09/04/02 
    ' Last Updated 09/04/02 
    ' Written by Melanie Newman 
    ' 
    ' Melanies very complicated Battery Low Indicator 
    ' 
    
    ' 
    ' Device 
    
    Programming Options 
    ' -------------------------- 
    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT 
    ' System Clock Options 
    @ DEVICE pic16F628, WDT_ON 
    ' 
    
    Watchdog Timer 
    @ DEVICE pic16F628, PWRT_ON 
    ' Power-On Timer 
    @ DEVICE pic16F628, MCLR_OFF 
    ' Master Clear Options (Internal) 
    @ DEVICE 
    
    pic16F628, BOD_ON 
    ' Brown-Out Detect 
    @ DEVICE pic16F628, LVP_OFF 
    ' Low-Voltage Programming 
    @ DEVICE pic16F628, CPD_OFF 
    ' Data Memory 
    
    Code Protect 
    @ DEVICE pic16F628, PROTECT_OFF 
    ' Program Code Protection 
    
    ' 
    ' Hardware Assignments 
    ' -------------------- 
    BatVal var CMCON.7 
    
    
    ' Read Comparator 2 for Battery Low 
    ' Port RA1 has +VBatt Input 
    BatLoLED var PORTB.7 
    ' Port for Battery Low LED 
    
    ' 
    ' Start Program 
    ' 
    
    ============ 
    
    ' 
    ' Setup Hardware 
    ' -------------- 
    ' 
    ' Comparator Control 
    ' ------------------ 
    CMCON=%00100101 
    ' CM7 C2OUT 
    
    Comparator Output 2 (Read Only) 
    ' CM6 C1OUT Comparator Output 1 (Read Only) 
    ' CM5 C2INV Comparator 2 Output Inversion 
    ' the way I'm driving my LED I need 
    
    inversion 
    ' so C2OUT goes Low when Battery is Low 
    ' CM4 C1INV Comparator 1 Output Inversion 
    ' CM3 Comparator Input Switch 
    ' not relevant for Comparator 
    
    Mode 101 
    ' CM2 ) refer to Datasheet figure 9-1 
    ' CM1 ) Mode 101 for Single Comparator C2 
    ' CM0 ) Comparator C1 Disabled 
    ' 
    ' Voltage Reference Control 
    
    
    ' ------------------------- 
    VRCON=%11101100 
    ' 7 VREN Voltage Reference Enable (1=on) 
    ' 6 VRON VREF Output Enable 
    ' 1=Connects output of VREF to RA2 
    
    
    ' This is real convenient so we'll use it 
    ' 5 VRR VREF Range Selection (1=Low Range) 
    ' 4 Unused (0) 
    ' VR3 ) 
    ' VR2 ) Set for Reference Voltage 
    ' VR1 
    
    ) 1100 sets 2.5v in Low Range 
    ' VR0 ) 
    ' 
    Pauseus 10 
    ' Delay to allow for VREF to settle 
    ' see datasheet section 11-1 
    ' 
    ' And the Usual Stuff 
    ' 
    
    ------------------- 
    TRISA=%11111111 ' Set All Inputs 
    TRISB=%00000000 ' Set All Outputs 
    
    ' 
    ' Actual Program 
    ' -------------- 
    BatLoLoop: 
    
    
    BatLoLED=BatVal 
    ' You better believe it... just ONE line of code! 
    Goto BatLoLoop 
    
    ' 
    End 
    
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Replies: 1
    Last Post: - 5th September 2015, 18:52
  2. Replies: 2
    Last Post: - 31st May 2013, 18:19
  3. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  4. Replies: 4
    Last Post: - 5th October 2008, 09:11
  5. Action on line sync
    By hansknec in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd August 2006, 13:42

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