Controlling a DC motor using PWM and a potentiometer

constrain(val,90,255); //this restricts the analog value to between 90 and 255

no it does not, however

val = constrain(val,90,255); //this restricts the analog value to between 90 and 255

does work