Setting pin alternate function

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
cswiger
Posts: 13
Joined: Fri Oct 16, 2015 9:51 pm

Setting pin alternate function

Post by cswiger » Tue Oct 20, 2015 9:34 pm

Looking at the PWM example http://micropython.org/resources/docs/e ... modulation
some things have changed - Pin.ALT instead of Pin.AF and I can do these:

>>> p24 = Pin('GP24',Pin.ALT)
>>> p24.alt_list()
[('UART1_RX', 2), ('TIM3_CC0', 4), ('TIM0_PWM0', 5), ('I2C0_SDA', 9)]

How to set the alternate function? af=9 just gets a type mismatch

>>> p24 = Pin('GP24',Pin.ALT,af=9)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument num/types mismatch

User avatar
andrew
Posts: 22
Joined: Sun Aug 10, 2014 9:22 am

Re: Setting pin alternate function

Post by andrew » Tue Oct 20, 2015 9:51 pm

Looks like it's now "alt=9".

http://micropython.org/resources/docs/e ... achine-pin

Andrew

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

Re: Setting pin alternate function

Post by danicampora » Wed Oct 21, 2015 7:23 am

Upps, will fix asap.

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

Re: Setting pin alternate function

Post by cswiger » Wed Oct 21, 2015 3:01 pm

Ha - thought I'd tried that somewhat obvious variation but guess not - that works! thanks.

>>> p24 = Pin('GP24',Pin.ALT,alt=5)

I'll readup on Timers to adapt it to GP24 as I don't see 25 on the pinout. This stab didn't work:

>>> p24.alt_list()
[('UART1_RX', 2), ('TIM3_CC0', 4), ('TIM0_PWM0', 5), ('I2C0_SDA', 9)]

>>> from machine import Timer
>>> tim = Timer(0,mode=Timer.PWM,width=16)
OSError: resource not available

TheoAms
Posts: 2
Joined: Wed May 27, 2015 8:27 pm

Re: Setting pin alternate function

Post by TheoAms » Wed Oct 21, 2015 6:48 pm

GP25 is connected to the heartbeat LED on the wipy ;-)

phsdv
Posts: 12
Joined: Wed Apr 22, 2015 2:36 pm

Re: Setting pin alternate function

Post by phsdv » Thu Oct 22, 2015 2:55 pm

I have some issues getting the timer.channel part working.

Code: Select all

>>> gp = 'GP10'
>>> pout = Pin(gp, mode=Pin.ALT)
>>> for x in pout.alt_list():     # why should I find the alt number for PWM of the system already knows it
...     if 'PWM' in x[0]:
...         pout = Pin(gp, mode=Pin.ALT, alt=x[1])
>>> print('pout:', pout)
pout: Pin('GP10', mode=Pin.ALT, pull=None, drive=Pin.MED_POWER, alt=12)
>>> tim = Timer(3, mode=Timer.PWM, width=16)
>>> tim_chA = tim.channel(Timer.A)
>>> tim_chA.freq(440)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: no such attribute
>>> tim_chA.duty_cycle(50)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: no such attribute
I can set the channel to Timer.A or Timer.B, however changing freq or duty cycle does not work. This is with update WyPi to version 1.1

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

Re: Setting pin alternate function

Post by danicampora » Thu Oct 22, 2015 3:04 pm

Hi,

You need to provide at least the frequency for the timer channel to be initialized:

Code: Select all

tim_a = tim.channel(Timer.A, freq=10000)
I know that the Timer API is inconsistent... we really need to define a proper one as part of the new Hardware API.

phsdv
Posts: 12
Joined: Wed Apr 22, 2015 2:36 pm

Re: Setting pin alternate function

Post by phsdv » Thu Oct 22, 2015 3:14 pm

danicampora wrote:Hi,

You need to provide at least the frequency for the timer channel to be initialized:

Code: Select all

tim_a = tim.channel(Timer.A, freq=10000)
I know that the Timer API is inconsistent... we really need to define a proper one as part of the new Hardware API.
That is what I tried first and did not work either, so I tried doing it step by step

Code: Select all

tim_chA = tim.channel(Timer.A, freq=1000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid argument(s) value

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

Re: Setting pin alternate function

Post by danicampora » Thu Oct 22, 2015 3:16 pm

The frequency is too low for a 16 bit timer (PWMs are always 16 bit on the CC3200), set it to 10KHz. The error messages also need improvement, will work on it.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Setting pin alternate function

Post by dhylands » Thu Oct 22, 2015 4:06 pm

I'm not yet familiar with the WiPy way of doing things, but on the stm, the frequency is associated with the timer and not with a timer channel.

Post Reply