I’m building a control system that will burst fire a Solid State Relay (SSR) for a proportion of a 2 second period. I think I am experiencing some timing difficulties because my SSR will not fire with outputs from the Arduino Nano of less than about 600 milliseconds.
At SSR output of 603ms the SSR will not fire, and at 670ms it does so only briefly (fed from dig-out pin 13, so I’m observing the on-board led).
My suspicion is that the loop() function is taking longer to update than I had hoped for, and this will only get worse as I add more code to give my system an LCD display, and etc…
I am trying to implement the good practice shown in Robin2’s excellent article
by keeping the loop() code length short and by calling functions, however it appears that the main loop() will sit and wait for a function to finish before it continues, so I’m no better off, except that my code is getting neater!
The problem became apparent when I introduced the Dallas Temperature library to read the boiler flow temperature (brief description of the code’s function is at the top of the sketch below). The dallas sensors take up to 750ms to respond when set to 12 bits resolution, much less at 10 bits, but indicative of the delay I have built into my code, and which I am keen to reduce or eliminate.
Apologies in advance; I tried to include code line numbering, but failed to copy the numbers with the code, and I have had to put my full code into an attachment to get under the 9000 character forum cap.
The aim is to update the SSR output duration (on pin 13) as close to every 2 seconds as is possible, and I am hoping for help to reduce the delays to program execution so that I can achieve this. I am a coding novice, but willing to learn, so my questions are as follows:
Q1. Would the transfer of the SSR updating code to an interrupt routine improve things? If so I’ll have to read up on those…but that’s all to my future benefit, so quite ready to do that.
Q2. How else might I get the output to fire the SSR reliably for durations between 20ms and 2000ms?
Q3. I have been unsuccessful in trying to introduce some hysteresis to prevent possible relay chatter at the 3kW, 6kW and 9kW levels. Given that I may have to re-write the code to calculate the SSR output duration, please will you give alternatives which don’t have my code’s inherant faults; ie a way of giving 0 - 100% power using burst fire, but including a variable for hysteresis both on rising and falling outputs.
Q4. Will altering the code in the manner you suggest allow me to introduce more code for LCD display driving, and etc, without upsetting the SSR timing once more?
Q5. The program presently compiles using no more than 30% of memory in my Nano. Would a faster/better microcontroller be a solution (as opposed to merely disguising the coding faults)?
Kind regards, GM