-
Notifications
You must be signed in to change notification settings - Fork 455
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
Change duty cycle of PIO Tone to 50% #2770
Conversation
Note that something like
would even be an instruction shorter (5 in total – but 5 instead of 3 cycles overhead for a square wave half-period, which shouldn't matter), and the two (With a |
@magy00 Would it be possible to make a version that lets us set the mark/space ratio too, or just set the mark and space periods, to keep it simpler? Is there a way to make sure the current cycle or half cycle completes before it loads a new value (to avoid a glitch), or does it do that anyway? I've thought for a while that this is something the PIO modules would be good for, i.e. pulse width variable waveforms for music synthesis, if they can be made to do those two things, but I don't know enough about it to make a start. |
Neat. Tone was one of the first PIO programs I wrote and I think it was just 1 sysclk off in terms of duty cycle. For audio stuff, 1/133,000,000s didn't seem like an issue to me at the time. How'd you notice it was off by a sysclk? BTW, nice job reducing the instruction count by 1. @Andy2No it already works atomically, so glitch free. It basically pulls a counter load value, sets the output state, and counts down to 0 before pulling a new one (or the same one as before if not updated). |
Well, I was looking at the source code (because I was doing the tone ringer emulation stuff mentioned above) and noticed that the duty factor was off by 1 and the frequency by 7 cycles (fine enough for audio but might also be useful for clock signal generation without the 200 kHz limit).
@Andy2No Perhaps adapt their PWM example? |
Cool. Thanks, @earlephilhower and @magy00 |
Move
side
-setting of pin one instruction up and replacejmp
with.wrap
to get a 50% duty cycle.