Possible bug with Case switch statements?


i have been working on developing lab bench power supply unit , plan use small arduino (atmega328p based clone board) have ran strange problem while using switch case statement.

below code. sorry if it's poorly written , sloppy, no expert coder (and typically rely on hardware solutions before turning on software solutions :p 1 example use of capacitor rc network act digital buffer on input pin. you'll see mean if read code.

code: [select]

  switch(mode){
    // adjust voltage via function below. if out of range, clamp overwriting value maximum value.
    case 0:
      // multiply velocity it's absolute value primitive velocity control. (if turn pot 2x fast, voltage 4x faster.)
      //serial.print("set voltage: ");
      voltageset += (vel * vel * vel * 0.001);
      if(voltageset > 15){
        //serial.print("upper v threshold reached!  ");
        voltageset = 15;
      }
      else if(voltageset < 0){
        //serial.print("lower v threshold reached!  ");
        voltageset = 0;
      }
      break;

    // adjust current via function below. if out of range, clamp overwriting value maximum value.
    case 1:
      // multiply velocity it's absolute value primitive velocity control. (if turn pot 2x fast, voltage 4x faster.)
      //serial.print("set current:");
      currentset += (vel * vel * vel * 0.002);
      
      if(currentset > 5){
        //serial.print("upper threshold reached!  ");
        currentset = 5;
      }
      else if(currentset < 0){
        //serial.print("lower v threshold reached!  ");
        currentset = 0;
      }
      break;
    
    // select saved values
    case 2: ; break;
  }



the particular code of interest line 145 , line 160.
code: [select]
currentset += (vel * vel * vel * 0.002);
code: [select]
voltageset += (vel * vel * vel * 0.001);

it appears if these lines not execute unless uncomment serial.print() command directly above them.  i feel may issue compiler not interpreting these strange reason. code implementing velocity control on rotary encoder. "val" frequency of rotation, not accurate due it's simple implementation, i'll worry improving later. if instead assign literal expression in place of "val" variable, works fine. can have steadily increment voltage or current set , x number of times per loop. replace variable expression stops working, unless place serial.print statement directly above it.

i don't it...

any ideas?

quote
any ideas?
post code.


Arduino Forum > Using Arduino > Programming Questions > Possible bug with Case switch statements?


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor