tmr as pwm not working or working with huge memory leak
Posted: Tue May 26, 2015 7:20 pm
I try to use the tmr to do a pwm function but either i get a memory is leak or the tmr do not work.
I need a faster pwm than the one that is included that is why i am doing this.
This one is not working when i try to use the "tmr" as local variable, the tmr.delay just don't do anything in this case.
----------------------------------------------------------------------------------------------
This one is working when i try to use the "tmr" but leak memory.
----------------------------------------------------------------------------------------------
Any suggestions?
I need a faster pwm than the one that is included that is why i am doing this.
This one is not working when i try to use the "tmr" as local variable, the tmr.delay just don't do anything in this case.
----------------------------------------------------------------------------------------------
Code: Select all
function forwardandrewind()
local tmr = tmr
if(forward == 1) then
forward = 0
gpio.write(3,gpio.HIGH)
else
forward = 1
gpio.write(3,gpio.LOW)
end
for x=1,16000 do
gpio.write(4,gpio.HIGH)
tmr.delay(1)
gpio.write(4,gpio.LOW)
tmr.delay(1)
tmr.wdclr()
end
tmr = nil
print(node.heap())
end
This one is working when i try to use the "tmr" but leak memory.
----------------------------------------------------------------------------------------------
Code: Select all
function forwardandrewind()
if(forward == 1) then
forward = 0
gpio.write(3,gpio.HIGH)
else
forward = 1
gpio.write(3,gpio.LOW)
end
for x=1,16000 do
gpio.write(4,gpio.HIGH)
tmr.delay(1)
gpio.write(4,gpio.LOW)
tmr.delay(1)
tmr.wdclr()
end
tmr = nil
print(node.heap())
end
Any suggestions?