Wondering if anyone has come across this issue.
Basically adding or removing a line of code that has nothing to do with an output on or off,state disables control of some outputs. In my case I'm noticing one in particular - pin 11.
Background
The below code is snip-it of a function which is part of the a 27,644 bytes of code being uploaded to my genuine Nano. The function is part of a temperature control system. It determines if a set of fans (PWM) are on or off. Fans do not turn off with a PWM value of 0 therefore the DC power must be cut to the fans in order to turn them off.
- Arduino "FAN_EN" (#defined elsewhere as pin 11) drives an opto-isolator that feeds a relay controlling power to the fans.
- Another function outside the below code determines the PWM speed of those fans. Prior the this function call, the PWM value is verified correctly.
- "Closed" refers to a door status being supplied by a second Nano (MC1_STATUS). When open (logic 0), the fan enable pin goes low and cuts power to the fans.
- FanOverride is used to manually override fan on/off
- UseTemp and tmFanOnTemp essentially determine if the ambient temp is higher than the fan on set temp.
- SW2 and SW3 are just dip switches feeding two other inputs.
All that is quite irrelevant but thought it would give you a better picture and would likely get asked.
Here is the rub... The below snip-it of code works perfectly. Yet if I only change the code by commenting out the serial.print.. on lines 3 and 4 (put there for debug purposes only) all the output pins become dysfunctional. I can confirm my code is running because if I can manually override the fans on or off via a serial command I can see the FAN_EN output (pin 11) change between 0V and 1.2V (scoped). It never goes to 5V as it does when the Serial.print lines are un-commented/active. I also have an Serial monitor window opened that replies with data to my several serial commands so the MC must be executing the code in flash memory.
No other changes to any other code. Just commenting out the two serial.print commands kacks the entire output functionality.
Have I discovered an AVR bug?? I read somewhere that using a big chunk of the flash memory causes strange things to happen. But yet, by commenting out the two lines, I'm actually occupying less flash memory? I'm puzzled.
Any info our similar experience would be greatly appreciated.
Here is my example code:
void CoolOn(){
if ((SW2 || SW3) && !(SW2 && SW3)) Closed = 1;
Serial.print(Closed); // does not work if I comment out this print command.
Serial.print(bitRead(MC1_STATUS, bitClosedstatus)); // does not work if I comment out this print command.
if ((Closed == 1 && UseTemp > tmFanOnTemp[profile]) && FanOnOverRide == 1)
{
digitalWrite(HEATER_PIN, LOW);
digitalWrite(FANEN, HIGH);
}
else
{
digitalWrite(FANEN, LOW);
}
}