Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Arduino Nano Flaky Code Execution - VISUALMICRO Bug? (Read 1368 times)
Bunzino69
Newbies
*
Offline


Posts: 9
Joined: Apr 24th, 2018
Arduino Nano Flaky Code Execution - VISUALMICRO Bug?
Sep 2nd, 2018 at 5:16am
Print Post  
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. 
Code (C++)
Select All
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);
 }

} 

« Last Edit: Sep 2nd, 2018 at 5:16am by Bunzino69 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Nano Flaky Code Execution - VISUALMICRO Bug?
Reply #1 - Sep 2nd, 2018 at 7:19am
Print Post  
Visual Micro and Arduino use the same external .EXE tool to compile. Therefore any difference is probably related to using Debug mode instead of Release. Debug mode can take a little more  memory and you are already near the Nano limits. Arduino boards can become erratic when near the limits.

Switch the tools bar from Debug to Release and try the upload so see if it now works same as arduino ide

If you have continued problems then always post a verbose build output with your reports so we can see what is being built.

Thanks
  
Back to top
IP Logged
 
Bunzino69
Newbies
*
Offline


Posts: 9
Joined: Apr 24th, 2018
Re: Arduino Nano Flaky Code Execution - VISUALMICRO Bug?
Reply #2 - Sep 3rd, 2018 at 6:01pm
Print Post  
Thank you for the reply. I tried both debug and release and I am still having the same problem. I also tried... in the Visual Micro tool bar, I selected the Arudino IDE instead of the Visual Micro (No IDE) setting within Visual Studio and see if this made any difference.  It did not. 

I couldn't figure out how to post the verbose build as you requested but click on https://1drv.ms/f/s!AsorZq6k5VoNiPFQIgPzA07bwf0dqQ (Microsoft OneDrive link) to view two text files. One called "works" contains build info for compiled code which includes the two serial.print commands in the source code. The other call "works not" contains the build that does not work which excludes the two serial.print commands from the source code (kills Arduino output pins). 

I did a comparison between the two files and didn't see anything obvious. Any suggestions are greatly appreciated.
« Last Edit: Sep 3rd, 2018 at 6:15pm by Bunzino69 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Nano Flaky Code Execution - VISUALMICRO Bug?
Reply #3 - Sep 3rd, 2018 at 9:00pm
Print Post  
Please switch on "vmicro>compiler>show build properties" 

Then click build>clean.

Then build 1st example

The click Build>Clean

The build 2nd example

This will show more info.

Thanks
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint