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

Fix panic in scanvideo.c with recurring sys_clk #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanSB
Copy link

@IanSB IanSB commented Mar 16, 2023

When the system clock is set to a value which is a recurring number, scanvideo.c will always panic even when the system clock is effectively an integer multiple of 2 times the desired pixel clock.

This is due to the system clock and the pixel clock being truncated to different levels of precision. e.g:

I was experimenting with custom scanvideo timings and wanted an output using a 14.318181Mhz pixel clock (or a close approximation of this NTSC frequency) and vcocalc.py gave the following solution for an 8x system clock:

Requested: 114.545448 MHz
Achieved: 114.66666666666667 MHz
FBDIV: 86 (VCO = 1032 MHz)
PD1: 3
PD2: 3

I set the system clock with the above values and specified the pixel clock frequency as 14333333 in my scanvideo timing struct (timing->clock_freq) and that led to the panic:
System clock (114666666) must be an integer multiple of 2 times the requested pixel clock (14333333).

This is due to the way the comparison is made by multiplying the pixel clock by the scale factor and comparing with the system clock which will fail as 14333333*8 = 114666664 not 114666666.

The fix is to divide the system clock by the scale factor and compare with the pixel clock and this will succeed as both sides have been truncated to the same level of precision. (114666666 / 8 = 14333333)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant