0

syntax for pin type pulsein
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

syntax for pin type pulsein

by drtomsutherland on Tue Feb 12, 2019 9:01 am

I wish to measure the duty cycle of a PWM signal. I have been following the example of how to read a pulse with a trinket MO. I have done a similar example for servo PWM and used A3 as the output pin, it worked fine. When I try to use "A4" as an input to the pulsein(A4,1,False) the processor seems to hangup. I've looked at the pinout of the Trinket and I am confused about which pins do what and/or what syntax you use. If I wan to use the pin labeled "4" do I use A4, D4, etc...?


ref:
pulsein()
https://circuitpython.readthedocs.io/en ... lseIn.html

PWM for servo :
https://learn.adafruit.com/using-servos ... cuitpython

Trinket Pinout:
https://learn.adafruit.com/adafruit-tri ... no/pinouts

drtomsutherland
 
Posts: 5
Joined: Wed Jan 23, 2019 3:43 pm

Re: syntax for pin type pulsein

by XRAD on Tue Feb 12, 2019 4:30 pm

From the pin dgm, you should be able to read PWM 0,2,3,4. I know PWM outputs fine on those channels.

Can you post your code?

Are you using serial monitor to asses the pin pulses?

XRAD
 
Posts: 348
Joined: Sat Nov 19, 2016 3:28 pm

Re: syntax for pin type pulsein

by adafruit_support_carter on Tue Feb 12, 2019 4:31 pm

The little labels are for the digital pin numbers, so for example "4" would be D4. The corresponding analog pins may be different. For example, the pin labeled "0" is D0 but is A2. That mapping is shown in the pinout diagram:
https://learn.adafruit.com/adafruit-tri ... no/pinouts
and also mentioned here:
https://learn.adafruit.com/adafruit-tri ... lities-3-4

It turns out for "4" , that they match up. It is D4 and also A4.

adafruit_support_carter
 
Posts: 11091
Joined: Tue Nov 29, 2016 2:45 pm

Re: syntax for pin type pulsein

by drtomsutherland on Tue Feb 12, 2019 4:38 pm

XRAD wrote:From the pin dgm, you should be able to read PWM 0,2,3,4. I know PWM outputs fine on those channels.

Can you post your code?

Are you using serial monitor to asses the pin pulses?


I am using the code from the example link in my original question posting, except I changed the pin D7 to D4. Honestly I don't know what this code is doing. I want to get the duty cycle of a PWM input(the high part or the low part doesn't matter), in microseconds if possible.
----------------------------------------------- CODE BELOW -----------------------------------------------------------------
import pulseio
import board

pulses = pulseio.PulseIn(board.D4)

# Wait for an active pulse
while len(pulses) == 0:
pass
# Pause while we do something with the pulses
pulses.pause()

# Print the pulses. pulses[0] is an active pulse unless the length
# reached max length and idle pulses are recorded.
print(pulses)

# Clear the rest
pulses.clear()

# Resume with an 80 microsecond active pulse
pulses.resume(80)

drtomsutherland
 
Posts: 5
Joined: Wed Jan 23, 2019 3:43 pm

Re: syntax for pin type pulsein

by XRAD on Tue Feb 12, 2019 5:54 pm

Got it. Sorry, I am not fluent in CircuitPy. Have PWM test examples using arduino IDE..... somewhat different coding....

XRAD
 
Posts: 348
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.