当前位置:   article > 正文

关于ov5640摄像头寄存器配置

关于ov5640摄像头寄存器配置

关于ov5640摄像头的寄存器有250个左右,但是往往在使用时不需要一一更改,以下是笔者在使用中认为需要关注的配置。

首先我们需要先了解的是基本图像的构成:

physical pixel size :物理感光的尺寸, 摄像头能够感光的大小

ISP input size:图像处理单元输入大小, 由物理感光的尺寸经过处理,输入进ISP进行处理

data output size:实际摄像头输出像素大小,为经过ISP进行处理缩放之后的图像数据

步入正题

1.输出图像寄存器配置

0x3800-0x3803           ISP的起点边界

0x3804-0x3807           摄像头能够感光的大小 (physical pixel size

0x3808-0x380b           实际摄像头输出像素大小(data output size

0x380c-0x380f            分别配置水平输出的像素的总个数和竖直输出像素的总个数,这个配置要                                        比data output size要大,和VGA的行列消影类似

0x3810-0x3813           偏移地址,默认X偏移16,Y偏移4

  1. //举例代码
  2. reg[1] = 24'h3800_00; // HS
  3. reg[2] = 24'h3801_00; // HS
  4. reg[3] = 24'h3802_00; // VS
  5. reg[4] = 24'h3803_fa; // VS
  6. reg[5] = 24'h3804_0a; // HW SET_OV5640 + HE}
  7. reg[6] = 24'h3805_3f; // HW SET_OV5640 + HE}
  8. reg[7] = 24'h3806_06; // VH SET_OV5640 + VE}
  9. reg[8] = 24'h3807_a9; // VH SET_OV5640 + VE}
  10. reg[9] = {16'h3808,IMAGE_WIDTH[15:8]}; // DVPHO
  11. reg[10] = {16'h3809,IMAGE_WIDTH[ 7:0]}; // DVPHO
  12. reg[11] = {16'h380a,IMAGE_HEIGHT[15:8]}; // DVPVO
  13. reg[12] = {16'h380b,IMAGE_HEIGHT[ 7:0]}; // DVPHO
  14. reg[13] = 24'h380c_07; // HTS
  15. reg[14] = 24'h380d_64; // HTS
  16. reg[15] = 24'h380e_02; // VTS
  17. reg[16] = 24'h380f_e4; // VTS
  18. reg[17] = 24'h3810_00; // Timing Hoffset[11:8]
  19. reg[18] = 24'h3811_10; // Timing Hoffset[7:0]
  20. reg[19] = 24'h3812_00; // Timing Voffset[10:8]
  21. reg[20] = 24'h3813_04; // Timing Voffset

2.时钟PCLK输出频率寄存器

PCLK时钟主要由0x3035 - 0x3037寄存器控制

0x3035             根据PLL配置输出帧率(15hz、30hz、60hz、90hz)

0x3036             根据PLL配置XCLK的时钟(一般48Mhz / 84Mhz)

0x3037             根据PLL配置分频或倍频

  1. //举例代码 input clock 24Mhz, PCLK 84Mhz
  2. rom[21] = 24'h3035_21; // PLL 21:30fps 41:15fps 81:7.5fps
  3. rom[22] = 24'h3036_69; // PLL
  4. rom[23] = 24'h3037_08; // PLL root divider, bit[4], PLL pre-divider, bit[3:0]

这里的3036寄存器xclk根据实际配置进行计算配置,这里配置OV5640的帧率为30帧,RGB格式为565,也就是两个输入拼成一个像素点,所以,像素时钟的计算为:总行数x总列数x帧率x2
1892x 740x30x2=84,004.800,约为84M。

3.图像输出格式寄存器 

0x4300 常见图像格式:YUV、RGB

0x501F 配置ISP输出格式

  1. //举例代码
  2. //YUV
  3. rom[24] = 24'h4300_30; // YUV 422, YUYV
  4. rom[25] = 24'h501f_00; // YUV 422
  5. //RGB
  6. rom[24] = 24'h4300_61; // RGB565
  7. rom[25] = 24'h501f_01; // RGB565

至此基本需要关注的寄存器配置就完成了,大家可以参照学习,完整的寄存器配置附上供参考,也可以在github上寻找其它资源。

  1. initial begin
  2. rom[0 ] = 24'h3103_11; // system clock from pad, bit[1]
  3. rom[1 ] = 24'h3008_82; // software reset, bit[7]
  4. //delay 5ms
  5. rom[2 ] = 24'h3008_42; // software power down, bit[6]
  6. rom[3 ] = 24'h3103_03; // system clock from PLL, bit[1]
  7. rom[4 ] = 24'h3017_ff; // FREX, Vsync, HREF, PCLK, D[9:6] output enable
  8. rom[5 ] = 24'h3018_ff; // D[5:0], GPIO[1:0] output enable
  9. rom[6 ] = 24'h3034_1a; // MIPI 10-bit
  10. rom[7 ] = 24'h3037_13; // PLL root divider, bit[4], PLL pre-divider, bit[3:0]
  11. rom[8 ] = 24'h3108_01; // PCLK root divider, bit[5:4], SCLK2x root divider, bit[3:2]
  12. rom[9 ] = 24'h3630_36; // SCLK root divider, bit[1:0]
  13. rom[10] = 24'h3631_0e;
  14. rom[11] = 24'h3632_e2;
  15. rom[12] = 24'h3633_12;
  16. rom[13] = 24'h3621_e0;
  17. rom[14] = 24'h3704_a0;
  18. rom[15] = 24'h3703_5a;
  19. rom[16] = 24'h3715_78;
  20. rom[17] = 24'h3717_01;
  21. rom[18] = 24'h370b_60;
  22. rom[19] = 24'h3705_1a;
  23. rom[20] = 24'h3905_02;
  24. rom[21] = 24'h3906_10;
  25. rom[22] = 24'h3901_0a;
  26. rom[23] = 24'h3731_12;
  27. rom[24] = 24'h3600_08; // VCM control
  28. rom[25] = 24'h3601_33; // VCM control
  29. rom[26] = 24'h302d_60; // system control
  30. rom[27] = 24'h3620_52;
  31. rom[28] = 24'h371b_20;
  32. rom[29] = 24'h471c_50;
  33. rom[30] = 24'h3a13_43; // pre-gain = 1.047x
  34. rom[31] = 24'h3a18_00; // gain ceiling
  35. rom[32] = 24'h3a19_f8; // gain ceiling = 15.5x
  36. rom[33] = 24'h3635_13;
  37. rom[34] = 24'h3636_03;
  38. rom[35] = 24'h3634_40;
  39. rom[36] = 24'h3622_01;
  40. // 50/60Hz detection 50/60Hz 灯光条纹过滤
  41. rom[37] = 24'h3c01_34; // Band auto, bit[7]
  42. rom[38] = 24'h3c04_28; // threshold low sum
  43. rom[39] = 24'h3c05_98; // threshold high sum
  44. rom[40] = 24'h3c06_00; // light meter 1 threshold[15:8]
  45. rom[41] = 24'h3c07_08; // light meter 1 threshold[7:0]
  46. rom[42] = 24'h3c08_00; // light meter 2 threshold[15:8]
  47. rom[43] = 24'h3c09_1c; // light meter 2 threshold[7:0]
  48. rom[44] = 24'h3c0a_9c; // sample number[15:8]
  49. rom[45] = 24'h3c0b_40; // sample number[7:0]
  50. rom[46] = 24'h3810_00; // Timing Hoffset[11:8]
  51. rom[47] = 24'h3811_10; // Timing Hoffset[7:0]
  52. rom[48] = 24'h3812_00; // Timing Voffset[10:8]
  53. rom[49] = 24'h3708_64;
  54. rom[50] = 24'h4001_02; // BLC start from line 2
  55. rom[51] = 24'h4005_1a; // BLC always update
  56. rom[52] = 24'h3000_00; // enable blocks
  57. rom[53] = 24'h3004_ff; // enable clocks
  58. rom[54] = 24'h300e_58; // MIPI power down, DVP enable
  59. rom[55] = 24'h302e_00;
  60. rom[56] = 24'h4300_61; // RGB565 //h4300_6f(千兆网模式)--------------------------------------------------------
  61. rom[57] = 24'h501f_01; // RGB565
  62. rom[58] = 24'h440e_00;
  63. rom[59] = 24'h5000_a7; // Lenc on, raw gamma on, BPC on, WPC on, CIP on
  64. // AEC target 自动曝光控制
  65. rom[60] = 24'h3a0f_30; // stable range in high
  66. rom[61] = 24'h3a10_28; // stable range in low
  67. rom[62] = 24'h3a1b_30; // stable range out high
  68. rom[63] = 24'h3a1e_26; // stable range out low
  69. rom[64] = 24'h3a11_60; // fast zone high
  70. rom[65] = 24'h3a1f_14; // fast zone low
  71. // Lens correction for ? 镜头补偿
  72. rom[66 ] = 24'h5800_23;
  73. rom[67 ] = 24'h5801_14;
  74. rom[68 ] = 24'h5802_0f;
  75. rom[69 ] = 24'h5803_0f;
  76. rom[70 ] = 24'h5804_12;
  77. rom[71 ] = 24'h5805_26;
  78. rom[72 ] = 24'h5806_0c;
  79. rom[73 ] = 24'h5807_08;
  80. rom[74 ] = 24'h5808_05;
  81. rom[75 ] = 24'h5809_05;
  82. rom[76 ] = 24'h580a_08;
  83. rom[77 ] = 24'h580b_0d;
  84. rom[78 ] = 24'h580c_08;
  85. rom[79 ] = 24'h580d_03;
  86. rom[80 ] = 24'h580e_00;
  87. rom[81 ] = 24'h580f_00;
  88. rom[82 ] = 24'h5810_03;
  89. rom[83 ] = 24'h5811_09;
  90. rom[84 ] = 24'h5812_07;
  91. rom[85 ] = 24'h5813_03;
  92. rom[86 ] = 24'h5814_00;
  93. rom[87 ] = 24'h5815_01;
  94. rom[88 ] = 24'h5816_03;
  95. rom[89 ] = 24'h5817_08;
  96. rom[90 ] = 24'h5818_0d;
  97. rom[91 ] = 24'h5819_08;
  98. rom[92 ] = 24'h581a_05;
  99. rom[93 ] = 24'h581b_06;
  100. rom[94 ] = 24'h581c_08;
  101. rom[95 ] = 24'h581d_0e;
  102. rom[96 ] = 24'h581e_29;
  103. rom[97 ] = 24'h581f_17;
  104. rom[98 ] = 24'h5820_11;
  105. rom[99 ] = 24'h5821_11;
  106. rom[100] = 24'h5822_15;
  107. rom[101] = 24'h5823_28;
  108. rom[102] = 24'h5824_46;
  109. rom[103] = 24'h5825_26;
  110. rom[104] = 24'h5826_08;
  111. rom[105] = 24'h5827_26;
  112. rom[106] = 24'h5828_64;
  113. rom[107] = 24'h5829_26;
  114. rom[108] = 24'h582a_24;
  115. rom[109] = 24'h582b_22;
  116. rom[110] = 24'h582c_24;
  117. rom[111] = 24'h582d_24;
  118. rom[112] = 24'h582e_06;
  119. rom[113] = 24'h582f_22;
  120. rom[114] = 24'h5830_40;
  121. rom[115] = 24'h5831_42;
  122. rom[116] = 24'h5832_24;
  123. rom[117] = 24'h5833_26;
  124. rom[118] = 24'h5834_24;
  125. rom[119] = 24'h5835_22;
  126. rom[120] = 24'h5836_22;
  127. rom[121] = 24'h5837_26;
  128. rom[122] = 24'h5838_44;
  129. rom[123] = 24'h5839_24;
  130. rom[124] = 24'h583a_26;
  131. rom[125] = 24'h583b_28;
  132. rom[126] = 24'h583c_42;
  133. rom[127] = 24'h583d_ce; // lenc BR offset
  134. // AWB 自动白平衡
  135. rom[128] = 24'h5180_ff; // AWB B block
  136. rom[129] = 24'h5181_f2; // AWB control
  137. rom[130] = 24'h5182_00; // [7:4] max local counter, [3:0] max fast counter
  138. rom[131] = 24'h5183_14; // AWB advanced
  139. rom[132] = 24'h5184_25;
  140. rom[133] = 24'h5185_24;
  141. rom[134] = 24'h5186_09;
  142. rom[135] = 24'h5187_09;
  143. rom[136] = 24'h5188_09;
  144. rom[137] = 24'h5189_75;
  145. rom[138] = 24'h518a_54;
  146. rom[139] = 24'h518b_e0;
  147. rom[140] = 24'h518c_b2;
  148. rom[141] = 24'h518d_42;
  149. rom[142] = 24'h518e_3d;
  150. rom[143] = 24'h518f_56;
  151. rom[144] = 24'h5190_46;
  152. rom[145] = 24'h5191_f8; // AWB top limit
  153. rom[146] = 24'h5192_04; // AWB bottom limit
  154. rom[147] = 24'h5193_70; // red limit
  155. rom[148] = 24'h5194_f0; // green limit
  156. rom[149] = 24'h5195_f0; // blue limit
  157. rom[150] = 24'h5196_03; // AWB control
  158. rom[151] = 24'h5197_01; // local limit
  159. rom[152] = 24'h5198_04;
  160. rom[153] = 24'h5199_12;
  161. rom[154] = 24'h519a_04;
  162. rom[155] = 24'h519b_00;
  163. rom[156] = 24'h519c_06;
  164. rom[157] = 24'h519d_82;
  165. rom[158] = 24'h519e_38; // AWB control
  166. // Gamma 伽玛曲线
  167. rom[159] = 24'h5480_01; // Gamma bias plus on, bit[0]
  168. rom[160] = 24'h5481_08;
  169. rom[161] = 24'h5482_14;
  170. rom[162] = 24'h5483_28;
  171. rom[163] = 24'h5484_51;
  172. rom[164] = 24'h5485_65;
  173. rom[165] = 24'h5486_71;
  174. rom[166] = 24'h5487_7d;
  175. rom[167] = 24'h5488_87;
  176. rom[168] = 24'h5489_91;
  177. rom[169] = 24'h548a_9a;
  178. rom[170] = 24'h548b_aa;
  179. rom[171] = 24'h548c_b8;
  180. rom[172] = 24'h548d_cd;
  181. rom[173] = 24'h548e_dd;
  182. rom[174] = 24'h548f_ea;
  183. rom[175] = 24'h5490_1d;
  184. // color matrix 色彩矩阵
  185. rom[176] = 24'h5381_1e; // CMX1 for Y
  186. rom[177] = 24'h5382_5b; // CMX2 for Y
  187. rom[178] = 24'h5383_08; // CMX3 for Y
  188. rom[179] = 24'h5384_0a; // CMX4 for U
  189. rom[180] = 24'h5385_7e; // CMX5 for U
  190. rom[181] = 24'h5386_88; // CMX6 for U
  191. rom[182] = 24'h5387_7c; // CMX7 for V
  192. rom[183] = 24'h5388_6c; // CMX8 for V
  193. rom[184] = 24'h5389_10; // CMX9 for V
  194. rom[185] = 24'h538a_01; // sign[9]
  195. rom[186] = 24'h538b_98; // sign[8:1]
  196. // UV adjust UV 色彩饱和度调整
  197. rom[187] = 24'h5580_06; // saturation on, bit[1]
  198. rom[188] = 24'h5583_40;
  199. rom[189] = 24'h5584_10;
  200. rom[190] = 24'h5589_10;
  201. rom[191] = 24'h558a_00;
  202. rom[192] = 24'h558b_f8;
  203. rom[193] = 24'h501d_40; // enable manual offset of contrast
  204. // CIP 锐化和降噪
  205. rom[194] = 24'h5300_08; // CIP sharpen MT threshold 1
  206. rom[195] = 24'h5301_30; // CIP sharpen MT threshold 2
  207. rom[196] = 24'h5302_10; // CIP sharpen MT offset 1
  208. rom[197] = 24'h5303_00; // CIP sharpen MT offset 2
  209. rom[198] = 24'h5304_08; // CIP DNS threshold 1
  210. rom[199] = 24'h5305_30; // CIP DNS threshold 2
  211. rom[200] = 24'h5306_08; // CIP DNS offset 1
  212. rom[201] = 24'h5307_16; // CIP DNS offset 2
  213. rom[202] = 24'h5309_08; // CIP sharpen TH threshold 1
  214. rom[203] = 24'h530a_30; // CIP sharpen TH threshold 2
  215. rom[204] = 24'h530b_04; // CIP sharpen TH offset 1
  216. rom[205] = 24'h530c_06; // CIP sharpen TH offset 2
  217. rom[206] = 24'h5025_00;
  218. rom[207] = 24'h3008_02; // wake up from standby, bit[6]
  219. // 12824'h720, 30fps
  220. // input clock 24Mhz, PCLK 42Mhz
  221. rom[208] = 24'h3035_21; // PLL 21:30fps 41:15fps 81:7.5fps
  222. rom[209] = 24'h3036_69; // PLL
  223. rom[210] = 24'h3c07_07; // lightmeter 1 threshold[7:0]
  224. rom[211] = {16'h3820, IMAGE_FLIP_DAT}; // flip
  225. rom[212] = {20'h38210, IMAGE_MIRROR_DAT}; // no mirror
  226. rom[213] = 24'h3814_31; // timing X inc
  227. rom[214] = 24'h3815_31; // timing Y inc
  228. rom[215] = 24'h3800_00; // HS
  229. rom[216] = 24'h3801_00; // HS
  230. rom[217] = 24'h3802_00; // VS
  231. rom[218] = 24'h3803_fa; // VS
  232. rom[219] = 24'h3804_0a; // HW SET_OV5640 + HE}
  233. rom[220] = 24'h3805_3f; // HW SET_OV5640 + HE}
  234. rom[221] = 24'h3806_06; // VH SET_OV5640 + VE}
  235. rom[222] = 24'h3807_a9; // VH SET_OV5640 + VE}
  236. rom[223] = {16'h3808, IMAGE_WIDTH[15:8]}; // DVPHO (<1280>500) (<640>280)IMAGE_WIDTH
  237. rom[224] = {16'h3809, IMAGE_WIDTH[ 7:0]}; // DVPHO
  238. rom[225] = {16'h380a, IMAGE_HEIGHT[15:8]}; // DVPVO (<720>2d0) (<480>1e0)IMAGE_HEIGHT
  239. rom[226] = {16'h380b, IMAGE_HEIGHT[ 7:0]}; // DVPHO
  240. rom[227] = 24'h380c_07; // HTS
  241. rom[228] = 24'h380d_64; // HTS
  242. rom[229] = 24'h380e_02; // VTS
  243. rom[230] = 24'h380f_e4; // VTS
  244. rom[231] = 24'h3813_04; // timing V offset
  245. rom[232] = 24'h3618_00;
  246. rom[233] = 24'h3612_29;
  247. rom[234] = 24'h3709_52;
  248. rom[235] = 24'h370c_03;
  249. rom[236] = 24'h3a02_02; // 60Hz max exposure
  250. rom[237] = 24'h3a03_e0; // 60Hz max exposure
  251. rom[238] = 24'h3a14_02; // 50Hz max exposure
  252. rom[239] = 24'h3a15_e0; // 50Hz max exposure
  253. rom[240] = 24'h4004_02; // BLC line number
  254. rom[241] = 24'h3002_1c; // reset JFIFO, SFIFO, JPG
  255. rom[242] = 24'h3006_c3; // disable clock of JPEG2x, JPEG
  256. rom[243] = 24'h4713_03; // JPEG mode 3
  257. rom[244] = 24'h4407_04; // Quantization scale
  258. rom[245] = 24'h460b_37;
  259. rom[246] = 24'h460c_20;
  260. rom[247] = 24'h4837_16; // MIPI global timing
  261. rom[248] = 24'h3824_04; // PCLK manual divider
  262. rom[249] = 24'h5001_83; // SDE on, CMX on, AWB on
  263. rom[250] = 24'h3503_00; // AEC/AGC on
  264. rom[251] = 24'h4740_20; // VS 1
  265. end

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/607729
推荐阅读
相关标签
  

闽ICP备14008679号