Setting pin alternate function
Setting pin alternate function
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
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
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Setting pin alternate function
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
>>> 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
Re: Setting pin alternate function
GP25 is connected to the heartbeat LED on the wipy
Re: Setting pin alternate function
I have some issues getting the timer.channel part working.
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
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
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Setting pin alternate function
Hi,
You need to provide at least the frequency for the timer channel to be initialized:
I know that the Timer API is inconsistent... we really need to define a proper one as part of the new Hardware API.
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)
Re: Setting pin alternate function
That is what I tried first and did not work either, so I tried doing it step by stepdanicampora wrote:Hi,
You need to provide at least the frequency for the timer channel to be initialized:
I know that the Timer API is inconsistent... we really need to define a proper one as part of the new Hardware API.Code: Select all
tim_a = tim.channel(Timer.A, freq=10000)
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
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Setting pin alternate function
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.
Re: Setting pin alternate function
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.