Comparator circuit thoughts....


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    At this point I would say whatever you have laying around. The 88 is good for starters. Might run out of memory or pins later but might not.

    But how are you writing code if you have not picked a PIC?
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    I have opted to write the code for the '88. Hopefully I don't run out of space . I'll keep you posted on that one.

  3. #3
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Major stupid question...
    If I declare something like Number var BYTE...
    Then I do: Number = 1.01567
    Does that get truncated to 1, or something else, or rejected altogether?

    Wow, I feel like a moron for asking! Sorry.

    Chris

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No problem with the questions.....
    Unless you get into floating point routines we are stuck with integer math.
    But if You need to be more accurate there are ways to do so. Basically mutiply by a power of ten and ...... Well you get the idea.

    So it would become 1.

    The PBP manual has a good section about the math.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Cool... I guess I'll put this mess up for you to take a look at. Mark it up at will. Thanks a ton....and here goes

    Code:
    '   Name    : THC.BAS                                      
    '   Author  : Me                                                
    '   Notice  : Copyright (c) 2009 None                           
    '          : All Rights Reserved                               
    '   Date    : 10/20/2009                                        
    '   Version : 1.0                                               
    '   Notes   : 
    '                                                                                          
    '
    include "MODEDEFS.BAS"
    '
    '\\\\ADC DEFINES////
    DEFINE ADC_BITS 8       'Number of bits in ADCIN result
    DEFINE ADC_CLOCK 3      'ADC clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50  'ADC sampling time in microseconds
    CVRCON = 143            'Reference on, not tied to pin, set to 3.59vdc
    ANSEL = 64              'Enable analog select, select channel 6
    CMCON = 7
    '
    '\\\\SERIAL PORT SETUP////
    DEFINE HSER_RCSTA 90h   'Enable serial port 
    define HSER_TXSTA 24h   'Enable transmit 
    define HSER_SPBRG 25    'Set baudrate to 9600                   
    DEFINE HSER_CLOERR 1    'Automatic clear overrun error
    INTCON = 64             'Enable peripheral interrupts
    PIE1 = 32               'Enable AUSART receive interrupt
    '
    '\\\\PINS SETUP////
    TRISB.0 = 0             'Up LED Output
    TRISB.1 = 1             'Enable THC Input
    TRISB.3 = 0             'LCD Pin
    TRISB.4 = 0             'Dn LED Output
    TRISB.6 = 0             'THC Enabled LED Output
    TRISB.7 = 1             'Scaled Torch Voltage Analog Input
    '
    '\\\\VARIABLE DECLARATIONS////
    TargetVDC var byte      '000-256 Allowed
    TargetVDCDiv var byte
    TorchPin var PORTB.0
    TorchVoltsNow var byte
    TorchDown var PORTB.4
    TorchUp var PORTB.0
    EnableIn var PORTB.1
    TorchVoltsFull var byte
    '
    '
    '
    '\\\\POWER UP STARTS HERE////
    Pause 500               'Wait for LCD to startup
    TargetVDC = 120         'Start up target volt value
    '
    '
    '\\\\LOOK FOR SERIAL DATA ON AUSART RX PIN////
    on interrupt goto NewSerialData
    '
    NewSerialData:
    hserin [wait ("V"),DEC3 TargetVDC]
    TargetVDCDiv = TargetVDC / 256
    goto mainloop
    '
    '\\\\START MAIN PROGRAM LOOP HERE////
    Mainloop:
    TargetVDCDiv = TargetVDC / 256
        IF Enablein = 1 then
            ADCIN 6,TorchVoltsNow
            if torchvoltsnow > TargetVDCDiv then
                high torchup    'Turn off TorchUp Pin
                low torchdown   'Turn on TorchDown Pin
            else
                high Torchdown  'Turn off TorchDown Pin
                Low torchup     'Turn on TorchUp Pin
            endif
        TorchVoltsFull = TorchVoltsNow * 256
        '\\\\SEND STATUS OUT TO LCD////
        LCDOUT $FE, 1
        LCDOUT $FE, 2
        LCDOUT "PLASMA VDC : "TorchVoltsfull
        PAUSE 50
        LCDOUT $FE, $C0
        LCDOUT "TARGET VDC : "TARGETVDC
        PAUSE 50    
        HSEROUT TorchVoltsFull
    else
        LCDOUT $FE, 1
        LCDOUT $FE, 2
        LCDOUT "---CONTROL IS---"
        PAUSE 50
        LCDOUT $FE, $C0
        LCDOUT "----DISABLED----"
        PAUSE 50
    ENDIF
    Goto mainloop
    Don't be cruel....newbie with ambition!

    Thanks a ton!

    Chris

  6. #6
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default 1333

    Typo in:
    TorchPin var PORTB.0
    Change to
    TorchPin var PORTB.7

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is for comparators
    Code:
    CVRCON = 143
    you want
    Code:
    ADCON1 = %00100000 'Pin #2 is voltage reference
    The LCD lines and HSEROUT line should be something like
    Code:
    LCDOUT "TARGET VDC ", #TARGETVDC
    HSEROUT [#TorchVoltsFull]
    The divide by multiply by 256 should not be there. The 8bit ADC goes from 0 to 255. As we talked before withe the voltage divider feeding the ADC and using using the reference voltage. Well it worked pretty neat for you. The torch voltage will be the same "number" as the ADC value.

    Other than that it should do something

    Now I will toss something else at you.
    Think how fast the torch move up and down. Those few line of code before the ADC is read could mean trouble. You may want to increment the movement.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 01:01

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