1st time COMPARATOR use...


Closed Thread
Results 1 to 8 of 8

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Even more basics...

    Yes Paul, I read Melanie's tutorial. At my level of comprehension, it is more like an example using a Comparator module in a 16F628.

    Yes Darrel, I read the MICROCHIP's Comparator Tips & Tricks document.

    The problem is, I don't clearly understand all the different pin/port/register names described in the datasheet. If some of them are obvious to me (VRef, A, D, etc..), others are not (CINV, VIN, CIN, etc..).

    Sorry if this sounds stupid and looked easy as a conventional ampli-op before I started, but all the µC-specific terminology messes my mind up.

    Just an example; when I read the 12F765's datasheet Comparator Operating Modes, I get lost at the very first figure....
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1703&stc=1&d=118095092 1">
    Here, I assume I have to set ports GPIO.0 & GPIO.1 to Analog (ANSEL register); is this right? But what is with the Output? Is it going to turn to an "1" when CIN+ > CIN-? How will I use it?

    And now, is it just the same as before but when the condition is CIN+ > CIN-, does COUT (bit) go to a "1"?
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1704&stc=1&d=118095155 5">

    What are CINV, VIN, CIN and what are they doing exactly?

    It's confusing me.
    Attached Images Attached Images   
    Roger

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Got it working!

    Okay, after some more trials and a correct connection to GP1 (... not GP0!!!), I got it working.

    BUT how do I improve the accuracy?

    When the measured voltage ist between 2,3V and 2,6V, my led flickers.

    How do I fix this?

    Another strange thing: if I "forget" to set the GP1 input as Analog (ANSEL), it still works(!?).

    BTW, here are my corrected schema and code:
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1708&stc=1&d=118097654 5">

    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      = %00000010 'Set Input/Output
    GPIO        = %00000000 'Ports High/Low
    WPU         = %00000000 'Weak pull-ups (check OPTION_REG)
    OPTION_REG  = %10000000 'Pull-ups / Interrupt / Prescaler
    ANSEL       = %00000010 'Analog I/O
    CMCON       = %01000100 '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
        pause 10
        Goto Main
    End
    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, 02:55
  2. Measuring time
    By AugustoPedrone in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th July 2007, 23:46
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. Alarm Time
    By Santana in forum Code Examples
    Replies: 1
    Last Post: - 8th December 2006, 13:58
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

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