1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Switching Led

Discussion in 'General Electronics Chat' started by willeng, Jul 4, 2014.

  1. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    #357. If you need a reference high than 2.5 V, amplify with a nice single supply (+5) OP amp. i.e. 5V, so you don't risk blowing up the arduino.
     
  2. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,
    Yes, I will do that.
    I have for the first test used the 2.56V internal reference until I heard back from you, I have been keeping the set point voltage low enough so nothing exceeded this, treading carefully.
    I had my first test & I think I will get this to work, I have to spend a little time adjusting the PID as it has over shoot then under shoot which is expected as the PID sketch suited the Lamp.

    I am just using the resister divider circuit with 8 set points at the moment (the circuit everybody loved to hate):)
    The set points are 0.5V, 1V, 1.5V etc to 4V.

    I have a ten position switch to select the set points, I will of course change to a better set point circuit etc once I have this running correctly. One thing at a time.
    On the ten position switch, I have the first pin so it is 0V--OFF. I found that when the Analog pins on the Arduino are Floating (I think you call it FLOATING) on this 0V--OFF setting the 15 Analog pins actually have around 0.6V on them.
    This was triggering the circuits & the PID so I am going to use a 10K resistor to ground on the 0V--OFF setting as this appears to work & all the Analog pins are held to 0V--OFF.

    I have to go for a check up at the doctors this morning & will be a few hours as it takes an hour to get there.

    Do I need to Buffer:
    1 The set point voltage input to the Arduino
    2 The output from the INA126P to the Arduino

    Talk again when I get back.

    Cheers
     
  3. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3

    Hi Kiss,
    I have been playing with the PID since getting back & have it operating not to bad at this stage, I can get it stable to within 1mm of water which is excellent really considering the mains fluctuation etc.

    The PID is very sensitive, this is very interesting trying to control something. I noticed at very low set point voltage 0.5V it oscillates a little but above that it is very stable.
    The Triac circuit maintains the 0V at turn off & no sign of current surge to the motor when switching the circuit on.

    I had one Triac fail due to overheating when trying to tune the PID, the heat sink wasn't big enough & the Triac was surging on & off until I got the PID smoothed out, never mind though I have plenty of them.
    I decided to use the NTE56033 Triac as this will be the one used in the final circuit, it seems easier to control than the BTA16, I fitted a good size heat sink & it runs only just warm.

    I'll keep going & when I get things a little better I will post the results for your scrutiny.

    This is good stuff!

    Cheers
     
  6. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    Tuning PID always requires a step response. One of the better ways to tune is to have graph of measured value vs time. Look at the last figures here: http://fsinet.fsid.cvut.cz/en/u2052/node118.html and invert the 'y" axis. You want the "critically damped" scenario.

    1/Gain is what's called the proportional band. Your step has to be greater than that. Too much gain causes oscillation, but it also creates the best control.
    Increasing D tends to reduce overshoot and increasing I tends to make the setpoint and measured value agree.
    Software PID can't let the I term get out of hand. i.e. exceed +-100.

    Also look at: http://www.expertune.com/tutor.aspx There are ways to auto-tune, but I never programmed them.

    EDIT:
    Autotune Arduino: http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/
     
    • Like Like x 1
  7. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Thanks Kiss,
    I'll check things out, I see what you mean with the step response.

    Cheers
     
  8. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,

    I found that getting a good step response via adjusting the set points is very different than getting a good loaded step response at the same set point.
    With the test pieces on the flow test bench you adjust the test pieces just like the butterfly in a carburetor so you can basically go from minimal flow to maximum flow.

    I found that what seems a near perfect step response when adjusting the set point voltages with the same size orifice it is a little unstable when adjusting the actual load applied by restricting the airflow to the orifice just as in real life testing & the PID stepping back or up to the set point pressure.

    I guess it's much like everything that there needs to be compromise, but for this application the loaded step response is what needs to be very good so I will again have to fine tune things more to suit the actual application.

    The big question on my mind is:
    Should the PID be very good unloaded & loaded as well with proper tuning or is it in fact a matter of compromise, not actually knowing this from experience makes fine tuning harder as I don't know the answer to this?
    Personally, I think it should be good both unloaded & loaded but I may be flogging a dead horse not knowing.

    Cheers
     
    Last edited: Jan 20, 2016
  9. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    The PID constants won't work at every setpoint and step changes near the intended setpoint get you really close, but it's still not perfect. Then you need to look at if from start to finish again to really fine tune it. You probably should have a way of "turning it off" that would reset the integral of E back to zero. It could even be a set point of 0 or whatever to call it off.
     
    • Like Like x 1
  10. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
  11. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    I don't think you sleep, but then again, I don't think I do either.

    We are expecting up to 2 feet of snow starting about 42 hours from now. Probably at least a foot. So, I'll be shoveling.

    In an analog controller, reset windup is prevented by the power supply rails.
     
  12. Tony Stewart

    Tony Stewart Well-Known Member Most Helpful Member

    Joined:
    Aug 31, 2012
    Messages:
    3,151
    Likes:
    281
    Location:
    Richmond Hill , ON Canada near Toronto
    Make sure you define the sensor hysteresis if any.
     
  13. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Tony,
    Oh, not sure how to check that out or define it actually, first time I have heard about it, more study:arghh:

    I'll see how I go, any advice would be good?

    Cheers
     
  14. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss, no not much sleep, this is to interesting to sleep!.
    Especially after being bed ridden for over a year.

    I have spent the day mostly studying exactly what I am tuning, why I am tuning & how the tuning effects things, so instead of just changing numbers in the sketch at least I know what I am changing now.
    I have a better understanding of the PID now, so armed with that I went to Wiki to look at the math involved & found it is very simple, if your a damn physicist:)

    So I used my own formula's knowing I would at least be closer than trying the complex math examples.
    So, I divided our postcode number by my house number & divided by a factor of ten then took the sqrt of how many light years to Pluto multiplied one into the other & came up the answer.:woot:

    I actually have the PID very close but there is a problem that is interrupting things & I found it to be noise & interference from the Universal Motor & maybe the triac circuit.

    When I probed the output from the INA126 into the Arduino there is massive interference with the motor running. I then checked the set point voltage at the Arduino & there is also interference & you can see the gate pulse train in the signal.

    The set point voltage & the pressure sensor circuits along with the INA126 circuit are enclosed in a metal enclosure for this reason, so maybe the external wiring is the culprit.
    I have some shielded cable that I will have to try next to see if I can get things sorted out better.

    Considering the fact that there is massive interference, I don't know how the PID can be so stable, it is good but not good enough yet, it would be nearly usable now but not good enough for me.

    Some years back my wife wanted to see the snow so we drove for many hours to where it snows here, it was that bloody cold she took a picture with the camera & said lets get out of here before we freeze to death. I like the snow on postcards & television & that's about it?

    Cheers
     
  15. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    :hilarious:

    Remember to connect the shields at one end only. Typically the source, but it doesn't have to be.

    You can get the triac closer. There are shielded power cables. http://www.cableleader.com/6ft-shie...a-5-15p.html?gclid=CLn44-r_usoCFYUYHwodky8C9A I've used them once when building an RF CVD (Chemical Vapor Deposition) system.

    http://www.newark.com/pdfs/techarticles/alphaWire/Understanding_Shielded_Cable.pdf

    Also remember that shielding reduces RFI and twisting reduces EMI so you see a lot of twisted pair shielded cable for that reason.

    You can also put an RFI filter near the motor. That would reduce what's being radiated by the power cord (antenna).
    You can use RFI filters to prevent stuff from getting in and prevent it from getting out.

    Try the simplest first - twisted pair shielded cable for your sensor.
     
    • Like Like x 1
  16. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,
    I didn't know about the shielded power cable, I can use that on a lot of things, every power cable I have cut or stripped to get wire from has never been shielded, good to know this.

    Yep, not a problem, I will spend some hours now sorting it all out, it's all very close & getting better all the time.

    When you mentioned:
    I may have this totally wrong?
    Is this why you were referring to a rotary encoder before, so you can step to the setpoints that the PID constants only get you close to, something like +1 +1 +1 or -1 -1 -1 etc, if that makes sense?

    Cheers
     
    Last edited: Jan 21, 2016
  17. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,
    I have used shielded cable on the setpoint voltage circuit output & it made twice as good as it was so I added a cap to the output & this has smoothed it nicely, so that's good.

    I used the same cable on the INA126 output & it was the same as above so I added a cap & it is good also, the signal looks smooth now.

    I noticed there was still a problem in that the sensor is so sensitive that the IMPORTED vacuum cleaner from you know where must have a "badly copied impeller" as the vacuum is not smooth, in fact it gives a variation at the INA126 output of 40 to 60mV peak to peak with the pulsations. Basically the signal is bouncing all over the place.
    The PID must be reading the average of this, it might also explain why the Derivative adjustment can get out of control easily with adjustment.
    The PID works exceptionally well considering this issue!

    Obviously this is a problem so I added a plenum to smooth the flow & it has worked nicely & eliminated the pulsations.
    This has created another issue in that now the vacuum source to the sensor is now slow to respond due to the plenum which is an obvious side effect of adding a plenum.

    The slow response is not a worry for testing these days & it will be ok but of course I now have to re tune the PID to suit.

    Just an update, I'll keep at it!

    Cheers
     
    Last edited: Jan 21, 2016
  18. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    I think the rule of thumb would be sensor in the center of the duct with 5 diameters away from any bends. You want laminar flow. At least that's the rule I went by for measuring flow in a 10" duct. Agreed,it not pressure or differential pressure. Tilt and position mattered too.

    The hard part was mounting the sensor. I actually made a curved plate with molly bolts of all things. I didn't have the proper rivet tool and threadserts. For gas sensors, this plate had to be removable.

    For the 3/8 tube sensors, the tube had to be positionable both tilt and insertion depth. I then tapped an NPT hole in the plate and used NPT to swage connectors with Nylon ferrules around the tubes.

    That's what Tony said, with the 40 to 50 mV of noise, let PID just ignore that amount of variation, Turn it into a +- number and ignore it in PID. You make the error zero.

    Your other question will require thought. I just got home from shopping and now it's time for a late dinner. Some are calling it snowmeggedon. Some are stocking up with beer and wine.
     
  19. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,
    Yes, I was actually thinking about making up a laminar flow element which I will do now.

    After looking closely at this after fixing the noise issues, it is not noise or interference now but rather a variation from Turbulent flow past the tap point for the sensor tube.
    The variation is 30mV, I changed the resolution of the sensor circuit to 4V = 25" of water & this has helped a little but the PID is trying to correct for the fast fluctuations of the 30mV.

    This circuit is only for holding a precise pressure as my other recordable readings are from actual Turbulent flow for a very good reason unlike many Flow Test Benches.

    Yes, like you & Tony have mentioned I could try to get the PID to ignore that amount of variation but unfortunately this is around 0.2" or 5mm of water, it doesn't sound like much but when recordable flow readings are taken from inclined manometers chasing fractional HP this is quite a lot.

    I know that may sound like BS!
    The reason for the accuracy is that since I have not been able to work any more, my grandson has conned me into building his very small Gokart engines for racing.
    This has prompted me to make this controller as I can not get the fine adjustments required manually anymore as stated before due to health reasons.

    You may not be interested but seeing your Snowed in you may have time to look at this video of my grandson with an engine I built for him before being layed up.
    He is only 12 but doing very well, you will see in the video that it takes him a lap or two to warm things up then he gets into it.
    Have a look, the little bugger can drive & wrings the engines neck, not because he is my grandson either, if you look at the front wheels he is actually driving this thing with a bent steering arm in this video & it's way out of control.
    I added the ___ so it didn't put the video here.
    https://___ www.youtube____ .com/watch?v= ____ iZGTJsro2uM

    This is why fractional HP is required now & precision for the Flow Test Bench & why I am so interested in trying to work this out as it gives me the opportunity to do what I love doing (building engines) once again although on a very small scale this time.

    I'll make some changes & see how I go.

    Oh yeah, you will see my sons big ugly head in the video as well:).

    Cheers
     
    Last edited: Jan 21, 2016
  20. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,918
    Likes:
    1,098
    ONLINE
    You would love this: http://www.chevyhardcore.com/news/video-worlds-smallest-running-327ci-small-block-engine/

    Ignoring the "noise" might actually make it more stable because the derivative function is disabled at this point, so your not hunting. Try it.

    12-18" predicted starting about 25 hours from now at about 10:30 PM. There's a possibility of "thundersnow" This is where there's thunder when it's snowing. Really weird. Makes Stevie Nicks song "Dreams" where she says "Thunder only happens when it's raining" is pure nonsense.
     
  21. willeng

    willeng Member

    Joined:
    Jul 5, 2012
    Messages:
    303
    Likes:
    3
    Hi Kiss,
    I'll have a look at that engine, built plenty of big chevy's in my day, these little ones only have 1 cylinder but that's me now!.
    Ok i'll give it a try, need to work it out in the sketch?

    Don't mind Fleetwood Mac either.
    Sounds like you'll need a big shovel!

    Cheers
     
    Last edited: Jan 21, 2016

Share This Page