Thanks for all of the input. After working on it a while, I ran into the same problems that you guys pointed out. Here is where I ended up. It required LONGs for me to get it to work right. When I started to look at it, I had no idea how to do it. Why is it that some projects seem to make you need every function or process that you are new at?
Code:
<font color="#000000"><b>DEFINE </b>OSC 8
<b>DEFINE </b>DEBUG_REG PORTA
<b>DEFINE </b>DEBUG_BIT 0
<b>DEFINE </b>DEBUG_BAUD 2400
<b>DEFINE </b>DEBUG_MODE 0
TRISA = %00100000 <font color="#0000FF"><i>' PortA : All outputs except RA.1 for INT_INT
</i></font>TRISB = %01000100 <font color="#0000FF"><i>' PWM1,3,5 outputs,RB2=INT, RB0,2,3: DIO
</i></font>ADCON1 = %00001111 <font color="#0000FF"><i>' Set up ADCON1
</i></font>OSCCON = %11111110 <font color="#0000FF"><i>' INTOSC, 8MHz
</i></font>EchoTime <b>VAR WORD
</b>Term1 <b>VAR WORD
</b>Term2 <b>VAR WORD
</b>Term3 <b>VAR LONG </b><font color="#0000FF"><i>' making this LONG solved the problem
</i></font>Duty0 <b>VAR WORD
</b>Near0 <b>VAR WORD
</b>Far0 <b>VAR WORD
</b>EchoTime = 28750 <font color="#0000FF"><i>' test value for the measurement
</i></font>Near0 = 6500 <font color="#0000FF"><i>' test setting for the minimum reading
</i></font>Far0 = 51000 <font color="#0000FF"><i>' test setting for the maximum
</i></font><b>DEBUG </b><font color="#FF0000">"1330-2l"</font>,13,10 <font color="#0000FF"><i>' splash
</i></font>Main:
Term1 = Far0 - Near0 <font color="#0000FF"><i>'51000 - 6500 = 44500
</i></font>Term2 = EchoTime-Near0 <font color="#0000FF"><i>'25500 - 6500 = 19000
</i></font>Term3 = Term2*1000 <font color="#0000FF"><i>'19000 * 1000 = 19000000
</i></font>Duty0 = Term3/Term1 <font color="#0000FF"><i>'19000000/44500 = 426.996
' ' Word won't work: divisor>32767, Need Long
' Duty0 = (EchoTime-Near0)/(Far0-Near0)*1000
</i></font><b>DEBUG </b>#Term1,<font color="#FF0000">" "</font>,#Term2,<font color="#FF0000">" "</font>,#Duty0, 13,10
<b>PAUSE </b>700
<b>GOTO </b>Main
Thank you all for looking at it.
Bo
Bookmarks