Page 1 of 4

Timer example not working

Posted: Thu Oct 22, 2015 7:02 pm
by deshipu
While exploring WiPy, I tried the example from the documentation on timers, at http://micropython.org/resources/docs/e ... hine-timer

Code: Select all

from machine import Timer
tim = Timer(4)                                   # create a timer object using timer 4
tim.init(mode=Timer.PERIODIC)                    # initialize it in periodic mode
tim_ch = tim.channel(Timer.A, freq=2)            # configure channel A at a frequency of 2Hz
tim_ch.callback(handler=lambda t:led.toggle())   # toggle a LED on every cycle of the timer
(Before that, I disabled heartbeat and set

Code: Select all

led = Pin('GP25', machine.Pin.OUT)
.)

But that example doesn't work:

Code: Select all

>>> tim_ch = tim.channel(Timer.A, freq=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid argument(s) value
What's wrong?

Re: Timer example not working

Posted: Thu Oct 22, 2015 7:43 pm
by cswiger
I think you need to use a higher frequency than 2 - try 5 or more. The clock speed and max count are such that 5hz is about the lowest it can divide down to.

Mine's offline or I'd test it 8-)

Re: Timer example not working

Posted: Thu Oct 22, 2015 8:21 pm
by danicampora
Hi guys,

The timer class is broken in too many places. Needs serious fixing ASAP. Apologies...

Cheers,
Daniel

Re: Timer example not working

Posted: Thu Oct 22, 2015 11:49 pm
by cswiger
Ok, we'll wait. Getting past the op error (by using freq=5) I've run into this before:

>>> tim_ch.callback(handler=lambda t:led.toggle())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: no such attribute

>>> dir(tim_ch)
['freq', 'period', 'time', 'event_count', 'event_time', 'duty_cycle', 'irq']

Re: Timer example not working

Posted: Thu Oct 29, 2015 11:48 pm
by robotmad
Is it also the case that the 'callback' method (mentioned in another example) has been replaced by 'irq'?

Re: Timer example not working

Posted: Tue Nov 17, 2015 11:35 pm
by Oli_
danicampora wrote:Hi guys,

The timer class is broken in too many places. Needs serious fixing ASAP. Apologies...

Cheers,
Daniel
Hello Daniel,

Just to know if some work have been made to the Timer class ?

Best regards,

Olivier

Re: Timer example not working

Posted: Tue Nov 24, 2015 10:35 pm
by Oli_
cswiger wrote:Ok, we'll wait. Getting past the op error (by using freq=5) I've run into this before:

>>> tim_ch.callback(handler=lambda t:led.toggle())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: no such attribute

>>> dir(tim_ch)
['freq', 'period', 'time', 'event_count', 'event_time', 'duty_cycle', 'irq']
If you want to use freq lower then 5 seconds, you can use a 32-bit width timer like that :

Code: Select all

from machine import Timer
from machine import Pin
led = Pin('GP16', mode=Pin.OUT)
tim = Timer(1, mode=Timer.PERIODIC, width=32)
tim_ab = tim.channel(Timer.A|Timer.B, freq=1)
tim_ab.irq(handler=lambda t: led.toggle())

Re: Timer example not working

Posted: Sun Dec 20, 2015 9:37 am
by deshipu
So, is there any timeline or plan on when the timers are going to work? Without timers the WiPy is pretty much useless to me, so it would be nice to know if I should consider the money lost and just go and buy some other, working board. I see the example in the documentation is still wrong, raising a ValueError. I can make a pull request with a docs fix, but unfortunately can't really help with the API overhaul. Would it help if I reported this as an issue on Github?

Re: Timer example not working

Posted: Mon Dec 28, 2015 6:33 pm
by v923z
Daniel,

I don't want to be rude, or anything, and there might be millions of reasons for your not having time to fix something, but I would also agree with the previous post that the kickstarter campaign was not entirely honest (the kickstarter page even has an example demonstrating the use of timers, while these don't work on the shipped boards), and this board might have to be considered money down the drain. I believe, the first problem with the timer was reported at the end of September, and nothing has since happened. I think you'll agree that a microcontroller without timers is pretty much useless. The wipy was supposed to be the "Swiss Army knife of IoT", with "infinite possibilities", and "lots of fun". I am not entirely sure it has lived up to the promises...

Cheers,
Zoltán

Re: Timer example not working

Posted: Tue Dec 29, 2015 8:22 am
by pythoncoder
I notice there's a new firmware build out today (29th Dec). Perhaps this might fix it?