Use a pot to adjust COUNT value


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    92

    Default Use a pot to adjust COUNT value

    I've been away from programming for a while now and need a little help if you will. I have a 40 watt CO2 laser cutter/engraver that requires water flow to keep the tube cool, the flow is provided by a small "waterfall" pump. If the flow were to stop the tube will be destroyed so I'm installing a flow sensor to monitor the flow. If the flow drops too low or stops, I will have the PIC activate a relay to instantly shut off power to the tube.

    The flow sensor I'm using has a turbine with a magnet and a hall sensor on the outside, this of course produces pulses which vary with flow rate. I can program the PIC (12F675) with a COUNT value that will work but I would like to be able to adjust that value with a pot for future uses and I'd just really like to learn how to do this.

    I'm using PBP, not sure which version, my manual is copyright 2003 which is when I purchased it.

    I have the COUNT working fine and Im using ADCIN to read the pot, (also used it for reading a thermistor I may want to add to monitor temp of the water too). I'll post both codes below, again, I'd like to know how to make them work together using the pot to adjust the "pulse" value in COUNT if anyone can get me on the right track.

    Thanks !

    COUNT
    Code:
    
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
    @ DEVICE pic12F675, WDT_ON
    @ DEVICE pic12F675, PWRT_ON
    @ DEVICE pic12F675, MCLR_OFF
    @ DEVICE pic12F675, BOD_ON
    
    c var byte
    
    pulse var word
    Green var GPIO.2
    Red Var GPIO.0
    
    low Red
    Low Green
    
    flow:
    count GPIO.1, 500, pulse
    if pulse > 120 then
    high Green            
    goto flow
    else 
    gosub alert
    endif
    pause 100
    goto flow
    
    
    
    alert: 
    for c = 1 to 4
    low Green
    high Red
    pause 100
    low Red
    pause 500
    next
    When flow is good, Green LED is lit, when no flow or too little flow, Red flashes routine. I'll add a relay to another pin.

    ADCIN
    Code:
    CMCON=�000111
    ANSEL=�000000
    
    
    
    
    
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
    @ DEVICE pic12F675, WDT_ON
    @ DEVICE pic12F675, PWRT_ON
    @ DEVICE pic12F675, MCLR_OFF
    @ DEVICE pic12F675, BOD_ON
    
    define ADC_BITS 8
    define ADC_CLOCK 3
    
    
    rdpot var word
    Green var GPIO.2
    Red Var GPIO.0
    Blue var GPIO.4
    Yellow var GPIO.5
    
    low Red
    Low Green
    
    flow:
    adcin 1,rdpot
    if rdpot > 20 then
    high Green
    else
    low Green 
    endif 
    if rdpot > 80 then
    High Red
    else
    Low Red
    endif
    if rdpot > 110 then
    high Blue
    else
    low Blue
    endif
    if rdpot < 20 then
    high Yellow
    else
    low Yellow
    endif
    goto flow
    I did the four LEDs just to see it work.

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


    Did you find this post helpful? Yes | No

    Default Re: Use a pot to adjust COUNT value

    Are you wanting to use the POT to change the COUNT period or the value the count var compares to?

    Also, have you looked/thought about PULSIN ?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: Use a pot to adjust COUNT value

    I started off with trying to use PULSIN, it worked but very strangely and I couldn't get it to adjust properly, COUNT works absolutely perfect for this application.

    I want the pot to be able to vary the value not the period. you see in the COUNT code "if pulse > 120 then", that's what I'd like to vary with a pot if possible.

    Thanks

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Use a pot to adjust COUNT value

    Hi,
    As far as I can see you've already done it.
    You have your pot, which you read with ADCIN and get a value in rdpot, then you have your sensor which read with count and get a value in pulse. Then just do
    Code:
    Flow:
      COUNT GPIO.1, 500, pulse
      ADCIN 1, rdpot
    
      IF pulse < rdpot THEN   ' Compare pulse with rdpot
        ' Flow is under limit
        ' Do what needs to be done.
      ELSE
        ' Flow is OK  
      ENDIF
    
      Goto Flow
    Or you can use a series of IF-THEN to light up the various LEDs or perhaps SELECT CASE, like
    Code:
    ' rdpot sets the absolute low limit = red ligtht and stop
    SELECT CASE pulse
      pulse is < rdpot
        ' Stop and turn on red LED
    
      pulse is < (rdpot * 2)
        ' Turn on yellow LED
    
      pulse is < (rdpot * 4)
         'Turn on Green LED
    
      END SELECT
    Something like that (untested). To be honest, when I think about it I'm not exactly sure how SELECT CASE works in this case. I mean when pulse < rdpot all cases are true and I'm not sure if it only executes the first the one and then exits (which is what we want) or if it continues to evauluate the other cases as well. Worth a try peraps.

    /Henrik.

  5. #5
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: Use a pot to adjust COUNT value

    Henrik, you are correct ! I had it close and didn't even realize it. The code below seems to work exactly like I want it to. Just need to add an output for a relay now.

    I've been wanting to learn how to use a pot for things like this for a long time, I have other uses for it now too.

    Thanks VERY much for your help, I really appreciate it,

    Sam

    Adjust pot for desired water flow rate
    Code:
    CMCON=�000111
    ANSEL=�000000
    
    
    
    
    
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
    @ DEVICE pic12F675, WDT_ON
    @ DEVICE pic12F675, PWRT_ON
    @ DEVICE pic12F675, MCLR_OFF
    @ DEVICE pic12F675, BOD_ON
    
    define ADC_BITS 8
    define ADC_CLOCK 3 
    
    rdpot var word
    c var byte
    pulse var word
    Green var GPIO.2
    Red Var GPIO.0
    
    
    low Red
    Low Green
    
    PAUSE 50
    
    flow:
    count GPIO.4, 500, pulse
    adcin 1,rdpot
    if PULSE > RDPOT then
    high Green
    low RED            
    goto flow
    else 
    GOSUB ALERT
    endif
    pause 50
    goto flow
    
    
    
    alert: 
    for c = 1 to 4
    low Green
    high Red
    pause 100
    low Red
    pause 500
    next

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