infineon4engineers

# Thread: How to work out a formula for the duty cycle

1. ## How to work out a formula for the duty cycle

Hi!
I am implementing a 4-20mA current loop to my PIC. I have everything working.
I am measuring the distance away from an object.
When I hardcoded the distance as 300 the output voltage is 4V and when the distance is 12cm the output voltage is 0.8V.
These values are got because the current needs to be 200uA before it enters the current loop.
The current loop has a gain of 100, therefore giving 20mA on the output.
The resistor I use is 20K.
Here is the datasheet of my proximity sensor: http://www.kynix.com/uploadfiles/pdf8827/XTR115UA.pdf

(300cm) Current=420K=200uA×100=20mACurrent=420K=200uA×100= 20mA
(12cm) Current=0.820K=40uA×100=4mACurrent=0.820K=40uA×100 =4mA

The problem is I have to work out a formula for the duty cycle to get these values.
The formula I am using is D.C = 300×2.2+158=818300×2.2+158=818 which gives 4V but if i substitute 12 for 300 I get 184 which does not correspond to 0.8V which is what I need.

Can anyone help on this, if I am going about the wrong way or what way I need to approach this.
Thank you