SOS Usage fault error

I’m currently building an electric brewing system which is controlled by a photon.

For some reason my code crashes with an SOS usage fault error and I can’t really find why.

My code is here.

It crashes when I send a “startbrew” command after I set a brewing step with “SetStep 50,-1” (heats to 50 deg C and wait for X min).
I added some serial prints in the code to see where it crashes but it prints exactly nothing when it crashes. The only thing I can see printed is the “gettemp” and “place18” when it is idle and sampling every second.

I also edited some minor things I saw before posting here but I didn’t test those yet. I highly doubt those small fixes fixed the error but I didn’t test that yet (currently at work :wink: ).

I’m guessing I am missing the obvious and made a stupid mistake somewhere but I can’t find it, hence I’m posting here in the hope of someone pointing out my mistakes :smile:

I found another mistake in my code,

#define SSRPIN D7 //PWM pin

I’ll be using this pin as PWM output but D7 is not a PWM capable pin. Would this cause a usage fault?

Probably not, unless there is a bug in the system.

But for your usage fault I'd check this line of code

analogWrite(SSRPIN, (1023/(steps[step].pwr/100)), PWMFREQ);

as it could result in a DIV/0 exception if steps[step].pwr is less than 100

Two things you should do when executing devisions

  1. perform the division as last step in the caclulation
  2. if you can't be sure that your result doesn't rely on rounding, write number literals as floats (e.g. 1023.0)

And since I'd expect your brewing to take longer than just a few hours, I'd strongly advise you to get rid of all these String objects and rather settle with char arrays to avoid side effects due to heap fragmentation.

3 Likes

I adjusted the code, I'll give it another shot tonight.

Thanks for the quick response! :smile:

Two things you should do when executing devisions

perform the division as last step in the caclulation
if you can’t be sure that your result doesn’t rely on rounding, write number literals as floats (e.g. 1023.0)

Good advice, thanks. I'm changing my divisions to multiplications.

And since I’d expect your brewing to take longer than just a few hours, I’d strongly advise you to get rid of all these String objects and rather settle with char arrays to avoid side effects due to heap fragmentation.

I didn't know this was a thing. I'll adjust my code.

2 Likes