float to short conversion error in c
You should know that casting float to int or short, can result in undefined behavior, if the float has a value outside the range of the integer. So, if that is possible, you should think about how to handle the exception cases, if pid_out>255, or pid_out&lt;0. 

Otherwise the answer to your question is to use a "unsigned short" data type:

unsigned short duty=(unsigned short)pid_out;


This casts pid_out in the range 0..255, the same range as duty can hold.

See http://en.wikipedia.org/wiki/C_data_types for a list of C data types.