Comparator circuit thoughts....


+ Reply to Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108

    Question Comparator circuit thoughts....

    Hello all,

    It has been a long time since posting on this forum. I hope everyone is well. I am currently working (or thinking about working) on a circuit for one of my cnc machines. It currently exists in analog discrete form, but I thought a pic version would be well suited for an upgrade...but my thoughts are scattered with it! Hopefully one of you fine folks can lead me down the right path.

    Description of machine: 3 axis cnc plasma cutting gantry

    Description of circuit: torch height control

    Circuit operation:
    1. Torch voltage is scaled from 120vdc to 1.2vdc.
    2. Torch voltage is then fed into a window comparator.
    3. Window comparator threshold voltage is variable from .06vdc to 1.85vdc. (representing 60-185vdc)
      Comparator has hysteresis of .01vdc + and - of the set threshold voltage. (representing a 2vdc "lock range")
    4. As the torch voltage swings out of the lock range, either comparator goes high, causing the cnc software
      to "servo" the torch back into range.
    5. The circuit also has an enable input, provided by the plasma cutter itself.
      It is simply a dry contact, "ok to move" signal which indicates the torch is cutting.

    My thoughts for the pic are:

    The cnc software allows direct commands to be sent from the serial port of the PC, via VB scripting.
    Therefore:


    1. Include all of the above features.
    2. Add the option of changing the comparator threshold voltage through serial with say...
    Code:
    SERIN2 SerPin,84,["V",dec3 TargetVDC]
    3. Add the option of changing the comparator hysteresis through serial with say...
    Code:
    SERIN2 SerPin,84,["H",dec1 TargetHyst]
    Are these thoughts doable, and if so, can you fine folks lead me in the right direction?

    Thanks to you all,
    Chris

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


    Did you find this post helpful? Yes | No

    Default

    Here is a half baked thought.

    Look at using an ADC input.
    60 to 185. Scale this by 60 giving 1 to ~3 for the input. Set VREF for 4 volts. Now you have a 1 volt buffer either way for when the plate suddenly warps or something else happens.

    Now the optimal voltage can be set as VAR SetPoint and the hysteresis can now be SetPoint +- what ever. Beyond the +- all stop or torch out or...

    Have the analog at 10 bit giving 1024 steps in the 4 volt range I would think would allow for a nice smooth operation.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks mackrackit,

    That sounds like a great idea, albeit leads me to a ton more questions.
    If I understand correctly, is this how it would go?....

    If I divide the TorchVdcMax by 1024 ----> ( 200/1024=.195)

    So, if I do something like this:

    Code:
    SERIN2 SerPin,84,["V",dec3 TargetVDC]
    TargetADC=TargetVDC*.195       'EX:TargetADC=120*.195 ----> 615.3846
    The "615.3846" correlates to the ADC target count? ----> (200/1024)*615 = 120.117

    I'll stop right there for the moment...I'm way confused at this point!
    I think for the moment, I'de much rather focus on commanding the torch voltage rather than both the torch voltage and hysteresis. Maybe it will calm my nerves a bit.
    Can you correct my mindset to this thing, or shoot me an easier way to comprehend it? Thanks a ton so far!

    Chris

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


    Did you find this post helpful? Yes | No

    Default

    Normally a PIC will only handle a maximum voltage of 5 volts. When you said
    # Torch voltage is scaled from 120vdc to 1.2vdc.
    I thought you were doing this with a voltage divider to bring the 120 down to 1.2, stating that the divider you planned on using was 100 to 1.
    So...

    I was thinking that being the expected voltages from the torch are 60 to 185 a voltage divider that would bring the 60 volts down to 1 volt for the low end and the 185 high end volts would then be ~3 volts. That is where the divide (scale) by 60 came in.

    Many PICs have a 10 bit ADC. Even with a 10bit if you want you only have to use the first 8.
    The difference is the resolution. There is also a voltage reference available when using the ADC. VDD can be used or some other voltage less than VDD. Some have a low end VREF but I figure on this one zero volts will be fine.

    This all means that if an 8 bit (256 steps)ADC setup is used with VREF set for 4 volts, each step represents ~0.015 volts. In real life with the torch voltage being divided by 60, 0.015 would equal 0.94 volts. The torch voltage would have to change 0.94 volts before the PIC sees the change.

    A 10 bit setup works the same but with 1024 steps. Now the PIC can see a 0.23 volt change on the torch.

    This could be tightened up by lowering the VREF and/or scaling the 60 to maybe 0.5 volts, but I figure a little cushion would be good on both ends. I may have more than is needed...

    Now using all of this. Say you want the torch voltage to be 120. With the 4 volt VREF and the voltage dividing, 4 volts at the ADC is equal to 240 at the torch, so we want to see 2 at the ADC to be good. The ADC will give a value of 512. If the ADC is + or - 512 the torch height will need adjusted.

    Let me know how much I confused things
    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

    mackrackit,

    No more confusion than before . Actually, the way you described the voltage scaling makes more sense to me now. As far as the torch voltage is concerned, maybe I added confusion from the beginning by not stating what would be a good baseline hysteresis to go with. After trying to get my head around the scaling, I started looking at the numbers more, and in doing that, I think a resolution of 1 volt change at the torch would be more than ok. That being said, that's where I figured using a torch value ranging from 0 - 256 Vdc...

    8 bit ADC
    4 Vdc Vref
    Vdc per ADC count : 4 / 256 = .015625
    Torch Vdc scale : 1:64
    Torch Vdc per ADC count : .015625 * 64 = 1 Vdc
    Ex: Torch Vdc = 115
    ADC counts * Vdc per ADC count = ADC Vdc Now
    115 * .015625 = 1.796875 Vdc
    1.796875 * Torch Vdc scale = Torch Vdc
    1.796875 * 64 = 115 Torch Vdc
    So... for every 1 Vdc change at the torch, there will be a 1 count change at the ADC... correct?

    If this is the case, coding for this arrangment should be way easier?
    Am I making this easier or harder on myself? I think it's sinking in slowly but surely. Thanks for assisting me on my brain fryer!

    Chris
    Last edited by kevlar129bp; - 23rd October 2009 at 16:30. Reason: scattered

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


    Did you find this post helpful? Yes | No

    Default

    I think you got it.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks mackrackit,

    I'll hack away at a bit of the code and see what I get... Will you be around for some assistance in that arena, when I get to that point?

    Thank you again... TONS!

    Chris

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


    Did you find this post helpful? Yes | No

    Default

    We are always here....

    Start the testing with a POT to simulated the torch.

    Which PIC are you going to use?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    mackrackit,

    In looking at my options, I think the 16F88 is going to do the trick. I'de like to plan ahead to do something like this on the front of the cnc pc. I dunno, let me know what you think... And again, thank you so much for your help. I'm working through the code as we speak

    Chris
    Attached Images Attached Images  

  10. #10
    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.

  11. #11
    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.

  12. #12
    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

  13. #13
    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.

  14. #14
    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

  15. #15
    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

  16. #16
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts