I think I discovered a Visual Micro bug. The reason I state is because when I compile and upload the Nano with Visual Studio 2017, I get the below issue. When I upload with the Arduino IDE, my code works regardless of the below issue. Wondering if anyone has come across this...
Basically adding or removing a line of code that has nothing to do with an output on or off,state disables control of all the output pins.
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 PWM fans need to be 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 to this function call, the PWM value is verified correctly.
- "Closed" refers to an enclosure 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.
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.
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);
}
}