Interupts

I actually want to generate interrupt when the distance of my robot from wall reaches a threshold value. obviously this threshold value is calculated in software (Arduino environment).

If the sensor value is read and threshold calculated in the sketch there is hardly a reason I can think of why you need that to generate an interrupt. Just setting a global flag variable in your sketch when the threshold is met can be used anywhere else in the sketch as required.

If you can explain why you think that generating an interrupt is required or desirable, please share your thinking.

Lefty