Timer example not working

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Timer example not working

Post by deshipu » Thu Oct 22, 2015 7:02 pm

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?

cswiger
Posts: 13
Joined: Fri Oct 16, 2015 9:51 pm

Re: Timer example not working

Post by cswiger » Thu Oct 22, 2015 7:43 pm

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-)

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Timer example not working

Post by danicampora » Thu Oct 22, 2015 8:21 pm

Hi guys,

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

Cheers,
Daniel

cswiger
Posts: 13
Joined: Fri Oct 16, 2015 9:51 pm

Re: Timer example not working

Post by cswiger » Thu Oct 22, 2015 11:49 pm

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']

robotmad
Posts: 3
Joined: Thu Apr 17, 2014 9:46 pm

Re: Timer example not working

Post by robotmad » Thu Oct 29, 2015 11:48 pm

Is it also the case that the 'callback' method (mentioned in another example) has been replaced by 'irq'?

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: Timer example not working

Post by Oli_ » Tue Nov 17, 2015 11:35 pm

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

Oli_
Posts: 15
Joined: Sun Nov 15, 2015 1:36 am

Re: Timer example not working

Post by Oli_ » Tue Nov 24, 2015 10:35 pm

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())

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Timer example not working

Post by deshipu » Sun Dec 20, 2015 9:37 am

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?

v923z
Posts: 168
Joined: Mon Dec 28, 2015 6:19 pm

Re: Timer example not working

Post by v923z » Mon Dec 28, 2015 6:33 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Timer example not working

Post by pythoncoder » Tue Dec 29, 2015 8:22 am

I notice there's a new firmware build out today (29th Dec). Perhaps this might fix it?
Peter Hinch
Index to my micropython libraries.

Post Reply