usign MC9S12DP256BD micro and codewarrior 5.1, a variable i declared keeps doubling in value every other time through a function and for no reason. not sure how to fix it?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

usign MC9S12DP256BD micro and codewarrior 5.1, a variable i declared keeps doubling in value every other time through a function and for no reason. not sure how to fix it?

517 Views
kevansherwood
Contributor I

I am trying to create an error buffer which sets the amount of time in seconds in which it will delay an error message on my LCD. The second value can be between 1 sec and 99 secs.

 

code for setting the value works and is fine it lets me change the value:

    case MODE_CHANGE:
    {
      if(param == MOD_MAIN_ERR_BUF_MODE)
      {
        alh_allow_alarms(FALSE);
        hid_control_LED(MOD_RATE_LED,
                        HID_LED_ON);
        hid_set_LCD_solid(HID_LCD_INT_PARAM |
                          err_buf_val |
                          HID_LCD_0_DP |
                          HID_LCD_LZ_BLANK);
        hwi_kpd_scroll_16(&err_buf_val,
                          MOD_ERROR_BUF_LOW_LIMIT,
                          MOD_ERROR_BUF_HIGH_LIMIT,
                          HID_LCD_0_DP);
      }

       break;
    }

 

once i get the err_buf_val, i do some math to save tha value in seconds:

 

                  if(min>= err_buf_val <=max)

                  {

                  err_seconds = (err_buf_val * 1000000);

                  }

 

the problem is that err_buf_val will be doubled the value entered on the keypad everyother time it runs through the code. for instance if i set the value to 5 seconds then it switches between 5 and 10 seconds everytime through the function. and the err_seconds value will change between 5000000 and 10000000.

 

if anyone understands than let me know what u think.

 

err_buf_val is declared as a uint16

err_seconds is declared as a uint32

Labels (1)
0 Kudos
1 Reply

458 Views
matthewkendall
Contributor V

It may be unrelated, but this line of code:

if (min >= err_buf_val <= max)

almost certainly does not do what you think it does.

0 Kudos