-->
Page 1 of 2

Program in debug mode work in run mode no

PostPosted: Fri Mar 03, 2017 6:42 am
by Miloit
This program activate two relays with web interface and real pushbuttons. In debug mode the program works ok but in run mode when i push button with interrupt 14 and button with interrupt 12 the relative relay go on for one second and go off, why?
Code: Select allmemclear
a = 1
b = 1
r1 = 16
r2 = 3
ciclo = 1
dimmer = 0
t1 = 5000
t2 = 5000
bounce = 200
io(po,r1,1)
io(po,r2,1)
interrupt 14,[inta]
interrupt 12,[intb]
interrupt 13,[intc]
interrupt 0,[intd]
interrupt 2,[inte]
interrupt 5,[intf]

[lop]
cls
wprint "Out A (On/Off) "
wprint htmlvar(a)
button "On", [Aon]
button "Off", [Aoff]
wprint "<br><br>"
wprint "Out B (On/Off) "
wprint htmlvar(b)
button "On", [Bon]
button "Off", [Boff]
wprint "<br><br>"
wprint "Out A (Pulse Time) "
wprint htmlvar(t1)
button "On", [PulseAon]
wprint "<br><br>"
wprint "Out B (Pulse Time) "
wprint htmlvar(t2)
button "On", [PulseBon]
wprint "<br><br>"
wprint "Out A and B (Cilic) A "
wprint htmlvar(a)
wprint " B "
wprint htmlvar(b)
button "On", [ciclic]
wprint "<br><br>"
wprint "Dimmer C "
wprint htmlvar(dimmer)
button "On", [dimm]
wprint "<br><br>"
wait

[Aon]
io(po,r1,0)
a = 0
returngui
wait

[Aoff]
io(po,r1,1)
a = 1
returngui
wait

[Bon]
io(po,r2,0)
b = 0
returngui
wait

[Boff]
io(po,r2,1)
b = 1
returngui
wait

[PulseAon]
io(po,r1,0)
delay t1
io(po,r1,1)
returngui
wait

[PulseBon]
io(po,r2,0)
delay t2
io(po,r2,1)
returngui
wait

[ciclic]
if ciclo = 0 then
io(po,r1,1)
a = 1
io(po,r2,1)
b = 1
ciclo = 1
goto [lop]
end if

if ciclo = 1 then
io(po,r1,0)
a = 0
io(po,r2,1)
b = 1
ciclo = 2
goto [lop]
end if

if ciclo = 2 then
io(po,r1,1)
a = 1
io(po,r2,0)
b = 0
ciclo = 3
goto [lop]
end if

if ciclo = 3 then
io(po,r1,0)
a = 0
io(po,r2,0)
b = 0
ciclo = 0
goto [lop]
end if

[inta]
if a=1 then
io(po,r1,0)
a = 0
else
io(po,r1,1)
a = 1
endif
'delay bounce
returngui
wait

[intb]
if b=1 then
io(po,r2,0)
b = 0
else
io(po,r2,1)
b = 1
endif
'delay bounce
returngui
wait

[intc]
wait

[intd]
wait

[inte]
wait

[intf]
wait

[dimm]
wait

end


Re: Program in debug mode work in run mode no

PostPosted: Fri Mar 03, 2017 11:28 am
by heckler
Hi Miloit,

What does your schematic look like? Do you have pullup resistors (10K or so) on all the inputs that are defined with interupt?

I have not tested your code but I would suggest you drop back and simplify it as much as possible and see how it behaves. Like just set up with one relay and one INT and then start moving forward adding more complexity and see where it breaks.

good luck
dwight

Re: Program in debug mode work in run mode no

PostPosted: Fri Mar 03, 2017 2:05 pm
by Miloit
Thanks for the quick reply heckler. Yes i have pulled a 10k resistor on every pin except D0 and D2.
I do not understand why program run well in debug mode and bad in run mode...

Re: Program in debug mode work in run mode no

PostPosted: Fri Mar 03, 2017 3:45 pm
by Electroguard
I might be wrong, but I thought there was only 1 interrupt available (and similarly only 1 timer), which could therefore only be attached to one pin at any one time.
In which case your script keeps re-defining the single interrupt to different pins, and only the last defined interrupt pin assignment will actually cause an interrupt, rather than having multiple pins each with their own interrupts as you were presumably expecting.

If that's the case, you would either need to keep polling the pins for change...
or perhaps use a multi-i/o port expander for your inputs, and have a port expander input change cause its interrupt output to trigger the esp's single interrupt pin to branch to an interrupt handler routine that would read the port expander inputs for what changed.