I am using a pic18x with a sound sensor (mic and amp) to control both the brightness of leds as the noise increases as well as turning on 4 water pumps as the noise level increase. When I run the code for both the leds and the pumps seperetly it seems to run OK but when I combine the codes together the pic just seems to 'freeze' - it just stops with the leds and pumps staying on the same setting no matter what the noise level is. I have tried re-arranging the order of my code but I cant seem to get it to run smoothly, it seems to work OK in the simulator. Here is my code:
main:
readadc 2,b1
debug b1
if b1 =>101 then goto on1
if b1=< 100 then goto off1
on1:
w0 = b1-100
pwmout 3,255,w0
goto pumps
off1:
pwmout 3,255,0
goto pumps
pumps:
readadc 2,b1
if b1 =<110 then goto pumpoff
if b1 =>111 and b1=<130 then goto pump1
if b1 =>131 and b1=<160 then goto pump2
if b1 =>161 and b1=<190 then goto pump3
if b1 =>191 then goto pump4
pump1:
high 0
low 1
low 2
low 4
goto main
pump2:
high 0
high 1
low 2
low 4
goto main
pump3:
high 0
high 1
high 2
low 4
goto main
pump4:
high 0
high 1
high 2
high 4
goto main
pumpoff:
low 0
low 1
low 2
low 4
goto main
____________________________________________________
Any suggestions on why it seems to freeze? I could post a circuit diagram if its useful, but as far as I am aware it is just the code that is the issue.
Any help would be very welcome.
main:
readadc 2,b1
debug b1
if b1 =>101 then goto on1
if b1=< 100 then goto off1
on1:
w0 = b1-100
pwmout 3,255,w0
goto pumps
off1:
pwmout 3,255,0
goto pumps
pumps:
readadc 2,b1
if b1 =<110 then goto pumpoff
if b1 =>111 and b1=<130 then goto pump1
if b1 =>131 and b1=<160 then goto pump2
if b1 =>161 and b1=<190 then goto pump3
if b1 =>191 then goto pump4
pump1:
high 0
low 1
low 2
low 4
goto main
pump2:
high 0
high 1
low 2
low 4
goto main
pump3:
high 0
high 1
high 2
low 4
goto main
pump4:
high 0
high 1
high 2
high 4
goto main
pumpoff:
low 0
low 1
low 2
low 4
goto main
____________________________________________________
Any suggestions on why it seems to freeze? I could post a circuit diagram if its useful, but as far as I am aware it is just the code that is the issue.
Any help would be very welcome.