Incorrect hsync pulse width on 640x480@60 and others, due to incorrect hsync_start rounding
When I run cvt 640 480 60
, I get result:
# 640x480 59.38 Hz (CVT 0.31M3) hsync: 29.69 kHz; pclk: 23.75 MHz
Modeline "640x480_60.00" 23.75 640 664 720 800 480 483 487 500 -hsync +vsync
The hsync start position of 664 is incorrect; it should be 656, matching the PDF spec, spreadsheet calculator, and https://tomverbeure.github.io/video_timings_calculator.
This bug arises because you calculate hsync_start
using (link):
mode_info->hsync_start = mode_info->hsync_end -
(mode_info->htotal * CVT_HSYNC_PERCENTAGE) / 100;
mode_info->hsync_start += CVT_H_GRANULARITY -
mode_info->hsync_start % CVT_H_GRANULARITY;
The problem is that when hsync_start
starts out as a multiple of 8, this code erroneously adds 8 to it when "rounding up" to a multiple of 8. Instead the value should remain unchanged.
This bug can be fixed by replacing those lines with:
{
int hsync_w = (mode_info->htotal * CVT_HSYNC_PERCENTAGE) / 100;
hsync_w -= hsync_w % CVT_H_GRANULARITY;
mode_info->hsync_start = mode_info->hsync_end - hsync_w;
}
Should I file a pull request?
Links
- Spreadsheet: https://app.box.com/s/vcocw3z73ta09txiskj7cnk6289j356b/file/1161581097988 page CVTv1.2a (note that this spreadsheet sets CVT_MIN_V_BPORCH to 7, which doesn't match the PDF or every CVT calculator I've found in the wild)
- PDF: https://app.box.com/s/vcocw3z73ta09txiskj7cnk6289j356b/file/93518784646