Shop OBEX P1 Docs P2 Docs Learn Events
Nitrox Stick Controller — Parallax Forums

Nitrox Stick Controller

willembadwillembad Posts: 47
edited 2012-06-25 14:58 in BASIC Stamp
I finally have it working! Thanks so much for all the help from this forum. It has been quite a learning experience and I'm sure I would not have gotten to this point without the help I received here.

AutoEANx-1.jpg

' {$STAMP BS2}
' {$PBASIC 2.5}


' Declarations
Baud            CON   32
NeedleStep      CON   10


Compressor      PIN   0
MixDown         PIN   1
MixUp           PIN   2
AdcCs           PIN   3
AdcClk          PIN   4
AdcIo           PIN   5
Text            PIN   6
Solenoid        PIN   7
Green           PIN   8
Red             PIN   9
Servo           PIN   10


Index           VAR   Nib
Counter         VAR   Nib
Counter2        VAR   Nib
AdcIn           VAR   Nib
Run             VAR   Nib
ButtonSpace     VAR   Byte
Remainder       VAR   Word
CurrentMix      VAR   Word
CurrentMixFrac  VAR   Word
MixSetting      VAR   Word
AdcOut          VAR   Word
Calibrate       VAR   Word
CalibrateFrac   VAR   Word
Average         VAR   Word
NeedleSet       VAR   Word


Initilization:
HIGH Green
LOW Red
SEROUT Text, Baud, [22, 17]
PAUSE 500
SEROUT Text, Baud, [22, 17, 12, "     Startup"]
PAUSE 500
INPUT Compressor
INPUT Mixup
INPUT MixDown
READ 0, Word MixSetting
LOOKDOWN MixSetting, [210, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360], Index
LOOKUP Index, [1020, 980, 940, 900, 860, 820, 780, 740, 700, 660, 620, 580], NeedleSet
AdcIn = AdcIn | %1011
GOSUB ServoSet
SEROUT Text, Baud, [12, "      Ready"]
DO UNTIL Compressor = 1
LOOP


Calibration:
LOW Red
FOR Counter = 1 TO 10
  HIGH Green
  SEROUT Text, Baud, [12, "Calibrating...", DEC2 Counter]
  GOSUB ReadAdc
  PAUSE 500
  LOW Green
  PAUSE 500
  Average = Average + AdcOut
NEXT
AdcOut = Average / 10
Average = 0
Calibrate = AdcOut * 10 / 209
Remainder = AdcOut * 10 // 209
CalibrateFrac = Remainder * 10 / 209
Calibrate = (Calibrate * 10) + CalibrateFrac
GOSUB CalcMix
GOTO CalConfirm


Main:
IF MixSetting > 210 THEN HIGH Solenoid
DO
  LOW Red
  HIGH Green
  FOR Counter = 0 TO 15
    GOSUB SysCheck
    BUTTON MixUp, 1, 255, 255, ButtonSpace, 1, SetMixUp
    BUTTON MixDown, 1, 255, 255, ButtonSpace, 1, SetMixDown
    GOSUB CalcMix
    Average = Average + CurrentMix
  NEXT
  Average = Average / 16
  IF ABS(MixSetting - Average) > 3 THEN GOSUB AdjustMix
  Average = 0
  GOSUB Display
LOOP


SysCheck:
FOR Counter2 = 1 TO 10
   Run = Run + Compressor
NEXT
IF Run = 0 THEN ShutDown
Run = 0
IF CurrentMix > 380 THEN ShutDown
RETURN


SetMixUp:
Index = Index + 1
LOOKUP Index, [210, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360], MixSetting
WRITE 0, Word MixSetting
IF MixSetting > 210 THEN HIGH Solenoid
GOSUB Display
PAUSE 300
GOTO Main


SetMixDown:
Index = Index - 1
LOOKUP Index, [210, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360], MixSetting
WRITE 0, Word MixSetting
IF MixSetting = 210 THEN LOW Solenoid
GOSUB Display
PAUSE 300
GOTO Main


CalcMix:
GOSUB ReadAdc
CurrentMix = AdcOut * 10 / Calibrate
Remainder = AdcOut * 10 // Calibrate
CurrentMixFrac = Remainder * 10 / Calibrate
CurrentMix = (Currentmix * 10) + CurrentMixFrac
RETURN


AdjustMix:
LOW green
IF CurrentMix < MixSetting THEN NeedleSet = NeedleSet - NeedleStep ELSE NeedleSet = NeedleSet + NeedleStep
IF NeedleSet < 460 THEN GOSUB O2Increase
IF NeedleSet > 1100 THEN GOSUB O2Decrease
FOR Counter2 = 1 TO 2
  PULSOUT Servo, NeedleSet
  PAUSE 250
NEXT
RETURN


Display:
SEROUT Text, Baud, [12, "Set      = ", DEC1 MixSetting DIG 2, DEC1 MixSetting DIG 1, ".", DEC1 MixSetting DIG 0, "%"]
SEROUT Text, Baud, ["Current  = ", DEC1 CurrentMix DIG 2, DEC1 CurrentMix DIG 1, ".", DEC1 CurrentMix DIG 0, "%"]
RETURN


ReadAdc:
LOW AdcCs
SHIFTOUT AdcIo,AdcClk,LSBFIRST,[AdcIn\4]
SHIFTIN AdcIo,AdcClk,MSBPOST,[AdcOut\12]
HIGH AdcCs
RETURN


ShutDown:
LOW Solenoid
HIGH Red
LOW Green
DO
  SEROUT Text, Baud, [12, "     OXYGEN         SHUT OFF"]
  PAUSE 1000
  SEROUT Text, Baud, [12]
  PAUSE 1000
LOOP


O2Increase:
NeedleSet = 460
LOW Green
HIGH Red
SEROUT Text, Baud, [12, "INCREASE OXYGEN     PRESSURE"]
PAUSE 1000
LOW Red
HIGH Green
RETURN


O2Decrease:
NeedleSet = 1100
LOW Green
HIGH Red
SEROUT Text, Baud, [12, "DECREASE OXYGEN     PRESSURE"]
PAUSE 1000
LOW Red
HIGH Green
RETURN


ServoSet:
FOR Counter = 0 TO 15
  PULSOUT Servo, NeedleSet
  PAUSE 250
NEXT
RETURN


CalConfirm:
SEROUT Text, Baud, [12, "Confirm  : ", DEC1 CurrentMix DIG 2, DEC1 CurrentMix DIG 1, ".", DEC1 CurrentMix DIG 0, "%"]
SEROUT Text, Baud, ["Up/YES   Down/NO"]
DO
  BUTTON MixUp, 1, 255, 255, ButtonSpace, 1, Confirmed
  BUTTON MixDown, 1, 255, 255, ButtonSpace, 1, Calibration
LOOP


Confirmed:
PAUSE 300
GOTO Main
1024 x 620 - 85K

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2012-06-09 05:36
    Good job! Nice to see you finally got it all working.
  • HulkHulk Posts: 68
    edited 2012-06-09 10:21
    So, is the re-breather on deck :)
  • willembadwillembad Posts: 47
    edited 2012-06-09 17:41
    Thanks Rick. I went from "How hard could it be?" to "I'll never get this!" to "That wasn't so bad". Learned a lot along the way.

    No breather for me Hulk. Too much money in those.
  • davejamesdavejames Posts: 4,047
    edited 2012-06-11 09:27
    ...very, very nice!

    :thumb:
  • willembadwillembad Posts: 47
    edited 2012-06-11 18:43
    Thanks :)

    Feel free to critique (anyone). I'm sure it could be better.
  • willembadwillembad Posts: 47
    edited 2012-06-18 18:56
    One step back here :( The controller has been working and I'm slowly perfecting the program but another question arose. The solenoid I'm using produces quite a bit of heat which isn't uncommon for these but I would like to minimize this. It is normally closed to shut of oxygen in the event of a power loss so it is contiguously energized during normal operation. It seems that I can lower the duty cycle by using pwm to provide only the necessary voltage to keep the valve open. Any suggestions on how to implement this in pbasic?
  • SapphireSapphire Posts: 496
    edited 2012-06-18 20:55
    PWM won't work for you because it only generates pulses while the instruction is being executed. Since your program has to go off and do other things, you would end up with some pulses followed by a constant on or off output. If you know for sure that your solenoid operates at less than 12V, then you could either change your 12V transformer to say 9V, or put a string of one or more power diodes in series with the PMOS switch. Each diode will drop the voltage by just over half a volt. Make sure the forward current rating on the diode exceeds that of the solenoid.
  • willembadwillembad Posts: 47
    edited 2012-06-19 05:32
    Thanks. That was what I was suspecting. I'll look into supplying lower voltage to the coil. I did get hold of the manufacturer and he said that normal operating temps could be as high as 170F but I'd like it to be less, so I'll tinker some more.
  • willembadwillembad Posts: 47
    edited 2012-06-25 14:58
    Replaced the solenoid coil with a 24vdc rated one and it operates just fine with 150mA draw. MUCH cooler than the other coil. Controller is now fully integrated and full tanks of nitrox is coming off the compressor :)

    Gut shot:
    2012-06-19083626.jpg


    Front panel:
    2012-06-25143508.jpg


    System:
    2012-06-25142807.jpg
    768 x 1024 - 106K
    1024 x 768 - 67K
    1024 x 768 - 99K
Sign In or Register to comment.