Shop OBEX P1 Docs P2 Docs Learn Events
Process control - need very slow variable frequency — Parallax Forums

Process control - need very slow variable frequency

ErlendErlend Posts: 612
edited 2014-11-17 01:48 in General Discussion
As part of one of my projects I need to control an impulse pump using a varable frequency signal of 5 - 60 HZ with ~10mS pulses - this drives the pump coil through a fat MOSFET. Easy to do from a Propeller pin. I also need to control a servo which operates the valve of a propane burner. The pump, burner, and a pipe coil act together to produce hot water at a controlled rate and temperature.
In the present solution the pump has to pause each time a new setting servo signal is needed for temperature control (it stays in position when there is no signal) - or otherwise I have to spend one more cog to allow the pump continue running in the other cog. I do not have spare cogs now.
So- my idea was to move these two tasks out and onto a chip - a cheap multichannel PWM controller I thought. Except, I cannot find one which can go that low in frequency (5Hz).
Do I have to use a small microcontroller connected by e.g. I2C which I can program to do both vF and servo control, or is there a suitable chip which is easily availble?

Erlend

snippet of code:
PRI Volume | freq, heat, strokes               'Ignite (if not burning) heat, and pump setpoint volume (= n 100strokes) at setpoint pressure, min and max setpoint temperature

    freq:= 30
    heat:= 80
    strokes:= 0
                                      
    ReadGlobals
    
    IF flameRate < CintMinFlame
      Ignite(1)
      
    REPEAT UNTIL tempWater > intSPtemp             'Wait until water is hot enough for brewing
      'flash 'Wait' indicator
      
    REPEAT UNTIL strokes > LintSPvol
      Pump1sec(freq)
      strokes:=+ freq                                             'Count how much / how many strokes have been pumped
      ReadGlobals     
      IF opmode== 0                                               'Check for stop command from parent
        Stop
        
      IF pressWater > LintSPpress + 5 OR tempWater < LintSPtemp   'Speed control
        freq:= (freq - 5) #> 0                     '
      IF pressWater < LintSPpress AND tempWater > LintSPtemp + 1
        freq:= (freq + 1) <# 20
        
      IF tempWater < LintSPtemp                                   'Heat control
        heat:= (heat + 1) <# 100
        ServoPos(heat)                   
      IF tempWater > LintSPtemp + 1
        heat:= (heat - 5) #> 50                    
        ServoPos(heat)
                                    
      IF tempWater > 100                                          'Overheat shutdown
        stop
      IF pressWater > 1600                                        'Overpressure shutdown
        stop
      IF flameRate < CintMinFlame                                 'Flameout shutdown
        stop  
                 
    Stop

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-11-16 03:31
    Square wave or sine wave? (I guess square wave will work for you.)

    You might consider a VCO chip, such as the DS1099. You may need to develop a resitance ladder to provide the appropriate voltages or a digitally controlled pot might work.
    http://www.maximintegrated.com/en/products/digital/clock-generation-distribution/silicon-crystal-oscillators/DS1099.html
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-11-16 03:56
    Oops.. the DS1099 seemed right, but it has to be special ordered with specific frequencies desired.

    But there are other VCO chips that are adjustable, and one can always divide the frequency down.
  • ErlendErlend Posts: 612
    edited 2014-11-16 04:20
    Sqaure wave is fine - as is almost any curveform I guess. It will be smoothed out by the large coil.

    Erlend
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-16 05:25
    Erlend wrote: »
    As part of one of my projects I need to control an impulse pump using a varable frequency signal of 5 - 60 HZ with ~10mS pulses - this drives the pump coil through a fat MOSFET. Easy to do from a Propeller pin. I also need to control a servo which operates the valve of a propane burner. The pump, burner, and a pipe coil act together to produce hot water at a controlled rate and temperature.
    In the present solution the pump has to pause each time a new setting servo signal is needed for temperature control (it stays in position when there is no signal) - or otherwise I have to spend one more cog to allow the pump continue running in the other cog. I do not have spare cogs now.
    So- my idea was to move these two tasks out and onto a chip - a cheap multichannel PWM controller I thought. Except, I cannot find one which can go that low in frequency (5Hz).
    Do I have to use a small microcontroller connected by e.g. I2C which I can program to do both vF and servo control, or is there a suitable chip which is easily availble?

    Erlend

    snippet of code:
    PRI Volume | freq, heat, strokes               'Ignite (if not burning) heat, and pump setpoint volume (= n 100strokes) at setpoint pressure, min and max setpoint temperature
    
        freq:= 30
        heat:= 80
        strokes:= 0
                                          
        ReadGlobals
        
        IF flameRate < CintMinFlame
          Ignite(1)
          
        REPEAT UNTIL tempWater > intSPtemp             'Wait until water is hot enough for brewing
          'flash 'Wait' indicator
          
        REPEAT UNTIL strokes > LintSPvol
          Pump1sec(freq)
          strokes:=+ freq                                             'Count how much / how many strokes have been pumped
          ReadGlobals     
          IF opmode== 0                                               'Check for stop command from parent
            Stop
            
          IF pressWater > LintSPpress + 5 OR tempWater < LintSPtemp   'Speed control
            freq:= (freq - 5) #> 0                     '
          IF pressWater < LintSPpress AND tempWater > LintSPtemp + 1
            freq:= (freq + 1) <# 20
            
          IF tempWater < LintSPtemp                                   'Heat control
            heat:= (heat + 1) <# 100
            ServoPos(heat)                   
          IF tempWater > LintSPtemp + 1
            heat:= (heat - 5) #> 50                    
            ServoPos(heat)
                                        
          IF tempWater > 100                                          'Overheat shutdown
            stop
          IF pressWater > 1600                                        'Overpressure shutdown
            stop
          IF flameRate < CintMinFlame                                 'Flameout shutdown
            stop  
                     
        Stop
    

    Isn't another Prop chip the logical solution as it is a very good "multi-channel PWM controller"? This is the "cheapest" solution as you have the parts and tools, software, and experience for this, unless of course you are building production quantities which leads on to the next question.

    However, I also have to ask what is it that has used up all the cogs? I always like to stand back to look at the application objectively and weigh the requirements in such a way that one comes up with a simplistic but elegant solution (rather than just "Prop'ing" it up :) )
  • ErlendErlend Posts: 612
    edited 2014-11-16 06:38
    I am learning how to make a Propeller-driven Frankenstein-like espresso machine. Learning by making. Like with Frankenstein, I want it to interact with people in a strange way. So I end up with lots of interfaces to lots of I/O. After this, I can make anything.
    Brewed and drank first gas'presso coffee just now, but I am not yet happy with the hot water control. Anyway, with all that is going on in the background the cogs get eaten away quickly.
    Here's an overview:

    FunctionalDiagram.jpg

    Erlend
    1024 x 662 - 104K
  • jmgjmg Posts: 15,173
    edited 2014-11-16 12:02
    Erlend wrote: »
    So- my idea was to move these two tasks out and onto a chip - a cheap multichannel PWM controller I thought. Except, I cannot find one which can go that low in frequency (5Hz).
    Do I have to use a small microcontroller connected by e.g. I2C which I can program to do both vF and servo control, or is there a suitable chip which is easily availble?

    Most small uC can cascade timers, to clock a PWM unit from a prescaler, or another timer.

    Standard chips like LED drivers do often have PWM options, but I'm not sure they can scale to your numbers, as that is not so useful an area for LED dimming.

    However, Peter has the best suggestion for development - just use another Prop - Cheaper than another Micro's eval kit, and you already have code proven.
  • MJBMJB Posts: 1,235
    edited 2014-11-16 12:40
    Erlend wrote: »
    Brewed and drank first gas'presso coffee just now, but I am not yet happy with the hot water control. Anyway, with all that is going on in the background the cogs get eaten away quickly.
    Here's an overview:

    FunctionalDiagram.jpg

    Erlend
    it is a little hard to read.
    but what I see is that you use COGs for ADC / I2C etc. drivers.
    Maybe this is required in SPIN ??
    In Tachyon I2C, SPI, SD, NMEA-Serial etc. can be handled without needing a separate COG.
    As long as the frequency of the readings are low, many such sensors can be handled from the main program COG.
    Maybe the timer COG can be utilized for cyclical polling of the sensors.
    It does not sound like you have really hard microsecond timings for reading the sensors.
    The timing within I2C and SPI protocols is handled by dedicated kernel routines.

    Probably not an option to rewrite your existing program - just mentioning this different approach.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-16 12:46
    Erlend wrote: »
    I am learning how to make a Propeller-driven Frankenstein-like espresso machine. Learning by making. Like with Frankenstein, I want it to interact with people in a strange way. So I end up with lots of interfaces to lots of I/O. After this, I can make anything.
    Brewed and drank first gas'presso coffee just now, but I am not yet happy with the hot water control. Anyway, with all that is going on in the background the cogs get eaten away quickly.
    Here's an overview:

    FunctionalDiagram.jpg

    Erlend

    Er, you are some freak! Do you have some photos of your "Frankenstein"? I hope it makes really good coffee or do you have to wait for a lightning storm?

    You can save at least 4 pins by combining those two external I2C buses with P28,P29 as there is no reason to have separate pins and "bus" infers that it can handle multiple chips. It also looks like you can combine a few functions into the one cog easily enough such as having the same cog read the I2C and SPI bus as none of these devices here require ultra-high update rates. That's just for starters.

    Do you have the original of your diagram, it looks interesting.

    EDIT: Just saw MJB's post. Yes, if you use Tachyon this would make the whole task easier and fit onto a single Prop chip. But I wonder, where is your networking connection? How otherwise are we to know when the coffee is ready?!
  • AribaAriba Posts: 2,690
    edited 2014-11-16 15:58
    An Espresso machine with GPS? Does it make coffee adapted to the country?

    Anyway, I think you can do the pump pulses and the servo PWM in one cog without waits. Just make a fast repeat loop and check if it's time for a pulse or pulsend with the help of the systemcounter CNT. For such low frequencies this should work fine in Spin.

    Here is the idea in code form, in addition you need to declare the variables, the pins and pindirections and maybe more. Is absolutetly untested:
    ms := clkfreq / 1000
      us := ms / 1000
    
      ServoRate := 20*ms                       'Servo every 20ms
      ServoPuls := 1500*us                     'Servo Pos 1000..2000us pulse time
      PumpRate := 100*ms                       'Pump Freq 5..60Hz = 200ms..16ms periode
      PumpPuls := 10*ms                        'Pump pulse length
    
      servotime := CNT + ServoRate
      ServoPulsEnd := servotime + ServoPuls
      pumptime := CNT + PumpRate
      PumpPulsEnd := pumptime + PumpPuls
    
      repeat
    
        if (CNT-servotime) > 0                 'Servo PWM
          OUTA[ServoPin] := 1
          servotime += ServoRate
    
        if (CNT-ServoPulsEnd) > 0 
          OUTA[ServoPin] := 0
          ServoPulsEnd := servotime + ServoPuls
    
        if (CNT-pumptime) > 0                  'Pump freq
          OUTA[Pump1Pin] := 1
          pumptime += PumpRate
     
        if (CNT-PumpPulsEnd) > 0
          OUTA[Pump1Pin] := 0
          PumpPulsEnd := pumptime + PumpPuls
    
        if opmode == 0
          quit
    
        IF pressWater > LintSPpress + 5 OR tempWater < LintSPtemp   'Speed control
    '      freq:= (freq - 5) #> 0
          PumpRate := PumpRate + 1*ms <# 200*ms
        IF pressWater < LintSPpress AND tempWater > LintSPtemp + 1
    '      freq:= (freq + 1) <# 20
          PumpRate := PumpRate - 1*ms #> 16*ms
    
        IF tempWater < LintSPtemp                                   'Heat control
          heat:= (heat + 1) <# 100
          ServoPuls := (heat*10+1000) * us                   
        IF tempWater > LintSPtemp + 1
          heat:= (heat - 5) #> 50                    
          ServoPuls := (heat*10+1000) * us                   
    
        IF tempWater > 100                                          'Overheat shutdown
          quit
        IF pressWater > 1600                                        'Overpressure shutdown
          quit
        IF flameRate < CintMinFlame                                 'Flameout shutdown
          quit
    
      Stop
    

    Andy
  • ErlendErlend Posts: 612
    edited 2014-11-17 00:14
    Er, you are some freak! Do you have some photos of your "Frankenstein"? I hope it makes really good coffee or do you have to wait for a lightning storm?

    You can save at least 4 pins by combining those two external I2C buses with P28,P29 as there is no reason to have separate pins and "bus" infers that it can handle multiple chips. It also looks like you can combine a few functions into the one cog easily enough such as having the same cog read the I2C and SPI bus as none of these devices here require ultra-high update rates. That's just for starters.

    Do you have the original of your diagram, it looks interesting.

    EDIT: Just saw MJB's post. Yes, if you use Tachyon this would make the whole task easier and fit onto a single Prop chip. But I wonder, where is your networking connection? How otherwise are we to know when the coffee is ready?!

    The Franken'spresso is still a crow's nest, I have not moved out from the P Dev Board and onto a permanent pcb. It is powered off 12V solar energy and a bottle of Propane, but maybe I should look into lightneing...
    The serious part of this project is to build a range of 'modules' = sets of know-how, code, electronic, electric, mechanical - for a range of sub-functions. This machine does a lot of things, and from that toolkit/set of modules I can build virtually anything. That means I try to avoid tailor making and combining - like putting I2C and SPI into one cog. I want the 'modules' to be generic, not spesific to Franken'spresso. Networking? I have been putting that off, because I fear it will be (yet another) steep learning curve, but definitly, the Forumers deserve to know when coffee is ready, and where in the world it is. (and start hacking into the machine...).
    The diagram I posted is in png format and should be zoom'able, but some day soon I will update my web too.
    I am in love with Spin, I would never cheat on her - even with sporty Tachyon.

    Erlend
  • ErlendErlend Posts: 612
    edited 2014-11-17 00:40
    Ariba wrote: »
    An Espresso machine with GPS? Does it make coffee adapted to the country?

    Anyway, I think you can do the pump pulses and the servo PWM in one cog without waits. Just make a fast repeat loop and check if it's time for a pulse or pulsend with the help of the systemcounter CNT. For such low frequencies this should work fine in Spin.

    Here is the idea in code form, in addition you need to declare the variables, the pins and pindirections and maybe more. Is absolutetly untested:

    ...
    ..

    Andy

    Excellent. I will do this. Guess I am hampered by human thinking patterns - the scheme you propose would be very exhausting if it were me who had to run around checking if the pulses have expired yet.

    Erlend
  • MJBMJB Posts: 1,235
    edited 2014-11-17 01:48
    Erlend wrote: »
    I try to avoid tailor making and combining - like putting I2C and SPI into one cog.
    Erlend
    a combined configurable SPI / I2C COG, that can be commanded to do this or that would be generic and reusable as well.
Sign In or Register to comment.