-
Notifications
You must be signed in to change notification settings - Fork 14
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
Frequency Setting off target #5
Comments
👍 this is useful. I never tested this with a scope, but now I really would like to track down this bug. |
Same issue. DS7102V oscilloscope. A frequency of 30.0Hz at 10% duty cycle has an actual frequency of 32.1Hz. More data: At 10% all frequencies seem to be off by a factor of ~1.071 |
Huh, okay, so something is definetly up. My partner has a beefy scope, I'll get them to help repro this on our end. |
Quick update with my findings. When I cat /sys/class/pwm/pwmchip0/pwm0 it returns the exact period of 35695236. However, when I clone the repository from github and try the same settings (30Hz at 10%) I get the correct value of 33333333. So this only arises when I try to use the pip package. Edit: Edit2: vcgencmd measure_clock pwm I was able to get the pwm clock rate which turns out to be 107143064 aka 107.143064MHz which is suspiciously close to the magic factor. I think the clock is supposed to be running at 100MHz. So, essentially the RPi 4B pwm clock is running faster than expected so that is why the frequency doesn't match up. I also found this thread which seems to be related to the issues https://forums.raspberrypi.com/viewtopic.php?t=275199. I don't really know how to fix this but I suppose that you could always fetch the actual clock frequency and apply a correction factor for the chipsets that need it. I am pretty sure that if you run the measure clock command on your device without issues, it will return something very close to 100MHz. Maybe there is a way to just adjust the clock frequency but I haven't looked into how that could be done. |
Very useful, thanks @BasVDriel. Running I'll spend some time this week / next week fixing this. |
What a great find! For those who need precision this sounds like the way to go and it shouldn't be too hard to implement, assuming the overhead of the lookup is minimal. |
Yeah all good, I'd make a pull request if I had time to fix it. But, if someone has a fix ready I can test it on the scope to test the real world accuracy. I only have a Pi 4 though. |
Follow-up: working on this issue this week |
Hm, so I had a moment to test with with an RPi4, and I'm still not able to fully reproduce it with either hardware pin. Some examples of what I'm seeing: Some more details:
I would appreciate it if other users could provide the same details! Still looking into a solution - that forum thread linked above helps. I have a
|
|
Using Rigol DS1054Z oscilloscope to measure the PWM output, I found to get 50.0hz, I had to set HardWarePWM to 46.7hz.
Setting function to 50hz, which is what is expected for SG-90 servos (really 20mS period), I was getting an output of 53.6hz or 18.66mS.
Otherwise I found this really easy to use and much more stable than software PWM that comes with Python library RPi.GPIO.
Too bad RPi only comes with 2 PWM channels, shared with the audio features of the RPi. I would have loved to use this for controlling RGB LED and get more stable results when using vPython.
The text was updated successfully, but these errors were encountered: