Shop OBEX P1 Docs P2 Docs Learn Events
Multiple expression evaluation problems — Parallax Forums

Multiple expression evaluation problems

turbosupraturbosupra Posts: 1,088
edited 2014-09-12 13:55 in Propeller 1
adcOutput is currently ~ 1784 . Am I missing something obvious? The PWM is not consistent, it goes into the else loop (< 100) at the bottom consistently, and then every once in a while will sporadically go into one of the temperature pwm if statements.

I believe my problem is the way I'm evaluating the conditions, I just don't know how to fix it. Any advice on properly comparing 2 numbers in the same if statement would be appreciated.



  repeat
    {
    onTime := 35555560
    offTime := 711111
    outa[c_pwmOutputPin] := 1
    waitcnt(onTime + cnt)
    outa[c_pwmOutputPin] := 0
    waitcnt(offTime + cnt)
    }
    
    if (adcOutput > 100)
      
      if (adcOutput > 2048)
        'onTime := f.fmul(c_20CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_20CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 35555560
        offTime := 711111
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1       
        term.str(string("20C On"))      
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0       
        term.str(string("20C off"))
        term.tx(13)      
        waitcnt(offTime + cnt)
        
       
      elseif (adcOutput <= 2048) AND (adcOutput > 1802)
        'onTime := f.fmul(c_25CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_25CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 35555560
        offTime := 711111
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("25C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("25C Off"))
        term.tx(13)        
        waitcnt(offTime + cnt)
       
      elseif (adcOutput <= 1802) AND (adcOutput > 1556)
        'onTime := f.fmul(c_30CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_30CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 33777777
        offTime := 1777777
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("30C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("30C Off"))
        term.tx(13)       
        waitcnt(offTime + cnt)
       
      elseif (adcOutput <= 1556) AND (adcOutput > 1401)
        'onTime := f.fmul(c_33CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_33CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 32355555
        offTime := 3199999
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("33C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("33C Off"))
        term.tx(13)       
        waitcnt(offTime + cnt)
       
      elseif (adcOutput <= 1401) AND (adcOutput > 1253)
        'onTime := f.fmul(c_35CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_35CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 31644444
        offTime := 3911111
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("35C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("35C Off"))
        term.tx(13)       
        waitcnt(offTime + cnt)
       
      elseif (adcOutput <= 1253) AND (adcOutput > 1114)
        'onTime := f.fmul(c_40CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_40CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 29866666
        offTime := 5688888
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("40C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("40C Off"))
        term.tx(13)       
        waitcnt(offTime + cnt)
       
      elseif (adcOutput <= 1114) AND (adcOutput > 999)
        'onTime := f.fmul(c_45CelsiusOn, pwmOutputHertzToClkCycles)
        'onTime := f.fround(onTime)
        'offTime := f.fmul(c_45CelsiusOff, pwmOutputHertzToClkCycles)
        'offTime := f.fround(offTime)
        onTime := 28444444
        offTime := 7111111
        term.dec(adcOutput)
        term.Tx(13)
        outa[c_pwmOutputPin] := 1
        term.str(string("45C On"))
        term.tx(13)      
        waitcnt(onTime + cnt)
        outa[c_pwmOutputPin] := 0
        term.str(string("45C Off"))
        term.tx(13)       
        waitcnt(offTime + cnt)

    else
      
      term.str(string("Less than 100"))
      term.tx(13)
      term.dec(adcOutput)
      term.tx(13)               
       

                    
        

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2014-09-12 11:26
    You are using the <= operator instead of the =< operation. The <= operator has the same effect as "x := x < y". You actually don't need to do the =< comparisons since they will always be true because the earlier > comparisons were not true.
  • turbosupraturbosupra Posts: 1,088
    edited 2014-09-12 13:55
    Thanks :)

    homer_doh.png



    Dave Hein wrote: »
    You are using the <= operator instead of the =< operation. The <= operator has the same effect as "x := x < y". You actually don't need to do the =< comparisons since they will always be true because the earlier > comparisons were not true.
Sign In or Register to comment.