1.6.1 installation broke my code but attempted roll back won't work either.

Hello,
Somewhat of a noob here…I was about to do some work on my project and got the upgrade available message so I thought, “why not?” and downloaded it. After upgrading from 1.6.0 to 1.6.1 via the windows installer, I compiled my sketch which reads PPM (Pulse Position Modulation) using timer2 and an ISR to measure pulse timing. When I executed it, the pulse times were all screwed up. I decided to uninstall 1.6.1 and reinstall 1.6.0. Once that was accomplished I compiled it again via 1.6.0 and it still exhibited the same behavior. :frowning:

I then connected my my Arduino Mega to my laptop which still was on the old 1.6.0 version which had not been upgraded and compiled my project and it is working fine.

Does the 1.6.1 installation make some sort of changes to my machine that can’t be undone by just uninstalling it and reinstalling 1.6.0? I really need to be able to work on my project with my current PC but I don’t know where to do from here. I’ve attached the code below for reference. I’m sure it could be improved since I’m new to this but I really just want to be able to compile it again on my home computer and have it work like it did prior to my upgrade.

Any suggestions would be greatly appreciated!

Thank You!

Mike

int chanCount = 8;
volatile int startPulseWidthMin = 5000; //This is the widgth of the start pulse.  You must use twice the value you like because the timer is .5 microseconds.  
String udpString;
char udpChar [90];


//  Setup Ethernet for UDP
#include <SPI.h>        
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888;      // local port to listen on

IPAddress remIP(192, 168, 1, 178); //Remote IP address
unsigned int remPort = 8888;      // Remote Port

EthernetUDP Udp;  // An EthernetUDP instance to let us send and receive packets over UDP
  

//These are volatile because they are used in interrupts
volatile long risingEdgeTime = 0; //useed for value stamp at beginning of each pulse
volatile long oldRisingEdgeTime = 0; //Temp storage of risingEdgeTime while getting new value
volatile long chanPositionTime[19]; //declare an array of up to 20 channels starts 0-19
volatile int counter = 0;


void setup () {
  
  //Setup Timer
  TCCR0A = 0;  //Reset register for timer1
  
  
  TCCR1A = 0;  //Reset register for timer1
  TCCR1B = 0;  //Reset second set of timer1 registers
  TCCR1B |= (1 << CS11);  //set timer1 to increment every .5 micro seconds.  This scalar devides the 16mhz clock by 8.      

  
  
  Serial.begin(9600); //Initialize serial communication for test output.
  attachInterrupt(0,risingEdge,RISING); //Setup the interrupt.  Interrupt 0 uses pin 2 on the mega2560.  
  

  //Start Ethernet and UDP
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);


}


void loop () {   
  
  String udpString = String(""); //Set udpString  back to null
  
  for (int x=1; x <= chanCount; x++) {
    udpString = String(udpString + chanPositionTime[x] + " ");
    }

Serial.println (udpString); //Print the udpString packet on the local terminal for debug. 


    // Send String via UDP
    Udp.beginPacket(remIP, remPort);
    Udp.print(udpString); //Udp.print instead of Udp.write to convert the String to a stream  Would have to use the udpString.toCharArray (udpChar, 90) for write 
    Udp.endPacket();

  delay (5); //Delay between UDP Packets
  
}

void risingEdge() {
  
  if (risingEdgeTime - oldRisingEdgeTime > startPulseWidthMin) counter = 1; //Starts a counter once a start pulse is detected
  
  oldRisingEdgeTime = risingEdgeTime; //hold the old time so it can grab a new one
  
  risingEdgeTime = TCNT1/2 ;  //get new time divide by two because of the .5 microsecond resolution set by scalar

  chanPositionTime[counter] = risingEdgeTime - oldRisingEdgeTime; //Write the pulse measurement to the appropriate chan in the array
  
  if (chanPositionTime[counter] < 0) chanPositionTime[counter] += 32767; //Handle negative results due to timer rollover.  
  
  //Set out of bounds values to their maximum to cut down on jitter from any line noise.  
  if (chanPositionTime[counter] > 2000)chanPositionTime[counter] = 2000;
  if (chanPositionTime[counter] < 1000)chanPositionTime[counter] = 1000;
     
  counter = counter++; //increment to the next pulse
   
 }

It compiles fine for me on 1.6.1 for both the Pro Mini and Mega 2560. What error messages are you getting?

It compiles fine but the resulting application behaves differently. I'm counting the length of pulses it receives but they come out differently when compiled on my home machine every since the 1.6.1 upgrade no matter what I try. I have no idea why it would do this. :frowning:

GCC 4.8.1 has far better optimizations that are highly sensitive to logic errors regarding memory management. This is quite a frequent problem now, the first thing I look for is bad array indices.

volatile long chanPositionTime[19]; //declare an array of up to 20 channels starts 0-19

If the comment is correct, you are overflowing your array.

I will check this. The radio I'm using is only 8 channels but; it is possible that the array overflows right as it starts because it can take a cycle or two to detect the start pulse which is the array's counter reset trigger. I'll try adding a delay or throwing out the first few pulses. Regardless of the results, thanks for at least giving me something to try.

volatile long chanPositionTime[19]; //declare an array of up to 20 channels starts 0-19

If you want an array to hold 20 items numbered 0 to 19, you have to declare it as chanPositionTime[20], not [19]

I agree this was an oversight but that's a max value. My current application only uses 9 of them. To be safe, I increased it to 30 but the results are still the same. Honestly, I do hope to address my noobish and somewhat sloppy code but my main problem is that it behaves differently when compiled on my primary machine after the 1.6.1 upgrade and rolling back does not help. :frowning: Of course it still works when compiled on a borrowed laptop with the old version.

Is there anything I can do to get this machine back to my prior baseline? Could it be a different version of Java. I'm grasping at straws but I really do appreciate the replies.

As I'm typing this it occurs to me I could just roll back my machine with a system point restore but that seems a bit drastic.

Ok...quick update. Rolling all the way back to 1.0.6 and it works like normal. :slight_smile: Now I'm doubting what prior version I had installed. :frowning: Anyway, can anyone suggest anything other than potentially overflowing my arrays (cause I tested increasing them to a much higher value than used) that would cause the code to function differently if compiled using 1.0.6 vs 1.6.1? Am I doomed to be stuck on this version forever?

  TCCR0A = 0;  //Reset register for timer1

That comment is incorrect. Probably not good to disable the millis() timer.

  counter = counter++; //increment to the next pulse

Someone else discovered the hard way that the undefined behavior of this construct is interpreted differently on 1.6 than 1.0. The result is no change to counter. Change it to a construct that does not have undefined behavior:

    counter++;
// or
    ++counter;
// or
    counter += 1;
// or
    counter = counter + 1;

Can't wait to get home and try/fix this. My current symptoms look very much like what one would expect if the counter isn't increasing correctly.

I can't thank you enough!

Code: [Select]
counter = counter++; //increment to the next pulse

Someone else discovered the hard way that the undefined behavior of this construct is interpreted differently on 1.6 than 1.0. The result is no change to counter.

John--
I was also bitten by this one. When I recompiled an older program I had written, it stopped working. When I determined that count = count++ had stopped incrementing I changed it to count = count+1, but I kept asking myself why did this ever work? Mystery now solved.

cattledog:
I kept asking myself why did this ever work? Mystery now solved.

It's one of the Frequently Asked Questions of the comp.lang.c newsgroup:
http://c-faq.com/expr/evalorder1.html

Tested and working perfectly now. Thank You johnwasser!