Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Example for reading a PWM signal with PIO #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zeroflow
Copy link

@zeroflow zeroflow commented Apr 8, 2021

Works well up to a 200 kHz input signal - deviation below 1% of frequency and duty cycle.

The example has a build-in testmode. Lower frequencies are dead on, higher ones have a slight error.

100 Hz / 0.5 duty OK
	100.00 Hz / 0.50 duty cycle measured
	Diff: 0.00 Hz
	Diff: 0.00% of freq
	Diff: 0.00% duty cycle

1000 Hz / 0.5 duty OK
	1000.02 Hz / 0.50 duty cycle measured
	Diff: 0.02 Hz
	Diff: 0.00% of freq
	Diff: 0.00% duty cycle

10000 Hz / 0.5 duty OK
	10002.00 Hz / 0.50 duty cycle measured
	Diff: 2.00 Hz
	Diff: 0.02% of freq
	Diff: 0.01% duty cycle

200000 Hz / 0.5 duty OK
	200803.21 Hz / 0.50 duty cycle measured
	Diff: 803.20 Hz
	Diff: 0.40% of freq
	Diff: 0.20% duty cycle

500000 Hz / 0.5 duty OUTSIDE LIMITS ---------
	505050.47 Hz / 0.49 duty cycle measured
	Diff: 5050.50 Hz
	Diff: 1.01% of freq
	Diff: 0.50% duty cycle

pio/pio_pwmin.py Outdated
Comment on lines 14 to 15
set(x, 0) # Set x = 0
mov(x, x | (0b01 << 3)) # invert x = Max-Value for 32 bits. (0b01 << 3) sets the invert bit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could just do MOV x with a NULL source and the invert bit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that works.
Great Idea - thanks!

@aallan aallan added the enhancement New feature or request label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants