Avatar for verdeimpacat

verdeimpacat

Member since Dec 2015 • Last active Apr 2017
  • 2 conversations
  • 12 comments

Born and living in Bucharest/Romania.
IT professional since more than 30 years.

Most recent activity

    • 15 comments
    • 1,196 views
  • in Projects
    Avatar for verdeimpacat

    Updated code after extensive testing:

    var triac;
    var htu;
    var temp;
    var averageTemp;
    var humidity;
    var compHumidity;
    var targetTemp;
    var tempHistory = Float32Array(60); 
    function onInit () {
       I2C2.setup( {scl: B10, sda: B3, bitrate: 19200 } );
       htu = require('HTU21D').connect( I2C2 );
       // Before anything else we should turn off the triac
       triac=A8;
       digitalWrite(triac,0); //this shoud reset the pin and set it as output
       temp = (htu.readTemperature()+htu.readTemperatu­re()+htu.readTemperature())/3;
       //at power-on we assume the temperature was constant for the entire measurement history
       tempHistory.fill(temp);
       averageTemp = temp;
       //turn HTU21D heater on for two seconds just to make sure the HTU21D sensor
       //has no condensation
       htu.setHeaterOn( true );
       setTimeout('htu.setHeaterOn(false);', 2000);
       targetTemp = 8.00;
    }
           
    function pidControlLoop() {
       temp = (htu.readTemperature()+htu.readTemperatu­re()+htu.readTemperature())/3;
       humidity = htu.readHumidity();
       compHumdity = htu.getCompensatedHumidity( humidity, temp );
       var regulatedTemp = targetTemp;
       //we want to check that moving towards regulated temp does not produce 
       //condensation. Furthermore, if the current temp is close or bellow
       //dew point we wish to move to slightly higher temp
       var dewPointTemp=htu.getDewPoint(temp,compHu­mdity);
       if (((targetTemp-dewPointTemp) < 1) || ((temp - dewPointTemp) < 1)) {
          regulatedTemp=dewPointTemp + 1;
       }
       //same, we want to check that the oldest temperature measured was above the dew point temperature
       //this is needed to avoid condensation due to thermal inertia for glass or metal objects
       //we better move slowly to higher temperature if such.
       if ((tempHistory[59] - dewPointTemp) < 1) {
          regulatedTemp = tempHistory[59] + 1;
       }
       // here we apply the proportional-integrative-derivative control 
       var PIDresult =0.75 * (regulatedTemp-temp + 2 * (regulatedTemp-averageTemp) + 2 * (tempHistory[0]-temp));
       calculatedPWM  = E.clip (PIDresult, 0, 1);
       analogWrite(triac, calculatedPWM, { freq : 0.2 });
       //Prepare for the next loop
       averageTemp = averageTemp - (tempHistory[59] - temp)/60;
       for (i=59;i>0;i--) {
          tempHistory[i] = tempHistory[i-1];
       }
       tempHistory[0] = temp;
    }
    //power on initialization. Will be deleted if code saved in flash
    onInit();
    // hereby we set the control loop to 60 seconds
    setInterval('pidControlLoop()',60000);
    

    And few thoughts after the prototype build:

    • It is wiser to use a snuberless triac. It's even chipper and allows you to build the power control circuit without R4 and C1. That's good because you will want to keep the ac circuitry as simple as possible;
    • The triac needs a 6 cm x 4cm radiator. I trust the triac will not dissipate more than 10-15W, and due to the fact that it is triggered with the MOC3083 zero cross circuit, the heat is kept to a minimum. But since it is powered directly to the ac mains circuitry it's good to avoid any overheating, plastic melting or even worse - fire. After all the load is over 10A at 220V ac;

    The regulation precision is 0,15°C with the suited PID parameters but may easily move to +/- 1°C when the PID parameters are not adequate.

    No humans, animals or Espruino pico boards were hurt during this experiment, do not attempt to build this project if you are not familiar working with mains electricity and power electronics.

  • in General
    Avatar for verdeimpacat

    That's fair enough! As a matter of fact I was afraid that one would need to write the code in Assambler language to keep code delay to minimum. And it's fine that there is no hardware lock due to use in whatever board functionality of conflicting resources.
    As for the speed in accessing data: there are plenty of applications like digital to analog audio conversion, bluetooth audio and possibly others where you won't need to store the data ( at least this is my assumption today ) but just to process it on the fly.

  • in General
    Avatar for verdeimpacat

    Hi Gordon,
    What are your thoughts about supporting I2S for audio digital on Espruino? I notice that the ST processor has such interfaces & features and I trust that nice application scenarios may arise from these (like enabling sound output, bluetooth audio, a.s.o.).
    No particular project in my mind, just wondering if there are any hardware/software limitations for use.

  • in Projects
    Avatar for verdeimpacat

    The power control looks like this:

  • in Electronics
    Avatar for verdeimpacat

    Hope the Real Time Clock is kept in the new design.
    Another thought: would the new Espruino board be also available in a SMD version ? I trust it may be of great use as soon as you move from prototype to small series "production".

  • in Projects
    Avatar for verdeimpacat

    The testing over the weekend went fine and revealed several errors that are already corrected in the second version of the code published above.
    Attached the image of the "test benchmark". It took three minutes to build ( half of the time because the LED was connected the other way around in the first instance) : )

    Meanwhile, all the prototype components arrived and I will move from software to electronics. It will take a while so... make no mistake, the project is not dropped!
    PS: Really fast process working with an interpreter and not compiled code!

  • in Projects
    Avatar for verdeimpacat

    Wise! My compliments luwar! I will edit my posting two days ago to reflect this advice.

  • in Projects
    Avatar for verdeimpacat

    Thank you Frida! I corrected this error by editing the yesterday posting.

Actions