Please ignore this thread - will re-post after re-writing it!

Hi all,

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 (that is <30% of its load demanded).

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 code into a seperate thread to get under the 9000 character forum cap, that code coming next…

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 40% of memory in my Nano. Would a faster/better microcontroller be a solution (as opposed to merely disguising the coding faults)?

Kind regards, GM

PS. I’ve fallen foul of the 9000 character limit, and can’t append my code. Please will someone (anyone!) ask for the code in a reply, and I should be able to post it up.

You don't need someone to add a post as far as I know, there's nothing to stop you posting twice in a row apart from the 5 minute rule that will go away once you reach 100.

Note also that you can attach code to a post and there is not a 9000 character limit on it.

As to DS18B20s, there is a function in the library that makes it non blocking - you can then ask the sensor to get the temperature and then go back to collect it after 750mS.

But anyway, post your code please :)

Don't try to include line numbers in your code. It's not really that useful, sometimes it would prevent someone from copying it easily for testing purposes.