I am relatively new to the chip programming game and I have some of my first code below for your review. I am trying to time some liquid flow between sensors. I found large discrepancies from count to count (value variable). Basically, I see a time decay. I tried resetting the flags for the TMRO counter, to no avail.
I thought I would try a chip with more memory (current chip is PIC16f84a, new chip is PIC18f2620), but I get a compiler error. I thought the pin assignments were off. I'm sure there are quite a few things I'm missing any help would be appreciated.
dummy var word ' div 32 variable
newdum var word
newdum3 var word
value var word ' raw counts
num var word
den var word
clear
input portb.5 'start signal first sensor
input portb.6 'stop signal second sensor
input portb.7 'resume
output portb.0 'solenoid
high 0
Pause 500 ' Wait 0.5s for LCD to startup
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Chromatography Inc." 'display message first line
Lcdout $fe, $c0, "Flow Meter2" ' Display meaasege second line
pause 4000
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "By Helcio" 'display message first line
Lcdout $fe, $c0, "Ver 1.0" ' Display meaasege second line
pause 4000
loop:
Lcdout $fe, 1 ' Clear LCD screen
value = 0
num = 0
den = 0
low 0
Lcdout "Waiting for" 'display message first line
Lcdout $fe, $c0, "Pump" ' Display meaasege second line
loop2:
' checks for first sensor
if portb.5 = 1 then loop2 'check start input
lcdout $fe, 1 ' Clear LCD screen
Lcdout "Measuring" ' Display message
loop3:
'counts while liquid is between sensors
Pause 1 ' Wait 0.001 second
value = value + 1 'count time delay
if value > 60000 then loop5
if portb.6 = 1 then loop3 'check stop input
high 0
if value < 2 then loop6
'num = value / 1000
'den = value // 1000
Lcdout $fe, 1 ' Clear LCD screen
'Lcdout "t = ", dec num, ".", dec den, "s" ' display time
Lcdout "t = ", dec value ' display time
dummy = value * 369 'm value of equation from slope equation y=mx+b
newdum = div32 1000
newdum3 = 5441 - newdum 'b value of equation
num = newdum3 / 1000
den = newdum3 // 1000
Lcdout $fe,$c0, "r = ", dec num, ".", dec den, "mL/min" ' ratio time
loop4:
if portb.7 = 0 then loop4 'check again input
goto loop
loop5:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Pump to slow"
Lcdout $fe,$c0, "Increase speed"
loop7:
if portb.7 = 0 then loop7 'check again input
goto loop
loop6:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Pump to fast"
Lcdout $fe,$c0, "Decrease speed"
loop8:
if portb.7 = 0 then loop8 'check again input
goto loop
Thanks for your help
Bookmarks