1st time COMPARATOR use...


Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default 1st time COMPARATOR use...

    Hello,

    I'm trying to use a comparator with my 12F675 for the first time.

    This is a simple battery low-level indicator project and I have reduced the schema to its minimum. The LED should light-up when the battery voltage drops lower than 6,5V.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1698&stc=1&d=118080488 0">

    I've found lots of information around the forum and the web but, I'm still stuck afters hours of testing...

    Here is my code:
    Code:
    ' Fuses
    @ DEVICE PIC12F675,INTRC_OSC_NOCLKOUT ;Internal oscillator 4MHz
    @ DEVICE PIC12F675,WDT_OFF
    @ DEVICE PIC12F675,PWRT_ON
    @ DEVICE PIC12F675,MCLR_OFF
    @ DEVICE PIC12F675,BOD_OFF
    @ DEVICE PIC12F675,PROTECT_OFF
    @ DEVICE PIC12F675,CPD_OFF
    
    '-------------------------------------------------------------------------------
    ' Registers    76543210
    OSCCAL      = %10000000 'Center frequency - used with Internal 4MHz OSC
    TRISIO      = %00000001 'Set Input/Output
    GPIO        = %00000000 'Ports High/Low
    WPU         = %00000000 'Weak pull-ups (check OPTION_REG)
    OPTION_REG  = %10000000 'Pull-ups / Interrupt / Prescaler
    ANSEL       = %00000001 'Analog I/O
    CMCON       = %01000010 'Comparator Module settings
    VRCON       = %10101100 'Voltage reference (= 2.5V)
    
    '-------------------------------------------------------------------------------
    ' Variables
    BatVal   var CMCON.6
    BatLoLED var GPIO.2
    
    '-----------------------------------------------------------------------------
    ' Program
    Pause 1 'Delay to allow for VREF to settle
    MAIN: 
        BatLoLED = BatVal
        Goto Main
    End
    I have to admit, I don't clearly understand all the comparator modes.

    But I hope to get it working so I can start doing experiences with all different modes... and learn.
    Attached Images Attached Images  
    Roger

Similar Threads

  1. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 03:55
  2. Measuring time
    By AugustoPedrone in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st July 2007, 00:46
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 20:55
  4. Alarm Time
    By Santana in forum Code Examples
    Replies: 1
    Last Post: - 8th December 2006, 14:58
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 15:24

Members who have read this thread : 1

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