type
status
date
slug
summary
tags
category
icon
password
System Analysis
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fdd485e64-7986-4bae-abd3-87d7b4b347f7%2FUntitled.png?table=block&id=025084c6-1c4b-4be2-8256-997f0e1f0b86&t=025084c6-1c4b-4be2-8256-997f0e1f0b86&width=798&cache=v2)
lcd reset module
Analysis
最重要的信号是lcd_rst信号,用来重置lcd,我们需要知道rst的所需波形
因此我们需要看到lcd 驱动的driver ic 文档,这里是ST7735S,reset timing部分
需要长于10us,取消即
NVM 是存储设备。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fdd968ce1-11ad-46b0-a132-bc1a92ef71da%2FUntitled.png?table=block&id=1b04b9b8-d1ca-49ee-a852-87cd2632e301&t=1b04b9b8-d1ca-49ee-a852-87cd2632e301&width=772&cache=v2)
It is necessary to wait 5msec after releasing RESX before sending commands. Also Sleep Out command cannot be sent for 120msec.
第一部分
第二部分 最少为10us
第三部分 至少120ms
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F46a533a8-3f50-4e06-a0b1-26e7a5bcc32c%2FUntitled.png?table=block&id=9bf071f9-7104-4096-81c1-e13e8396d61d&t=9bf071f9-7104-4096-81c1-e13e8396d61d&width=809&cache=v2)
我们需要生成这个波形来控制lcd reset
code
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fe1d0b799-35ef-4cee-b833-15fde7db4615%2FUntitled.png?table=block&id=9d8188d4-96e4-475d-90cf-1c03b1ef5614&t=9d8188d4-96e4-475d-90cf-1c03b1ef5614&width=849&cache=v2)
各部分的时间控制,这里他的fpga板载晶振是50
Hz,因此除了20。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fe8cef829-c70d-49bc-bb84-62a690052f2d%2FUntitled.png?table=block&id=f8699fd1-d5ee-4f3d-a962-e7ed0e7ed122&t=f8699fd1-d5ee-4f3d-a962-e7ed0e7ed122&width=890&cache=v2)
三种状态
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F261ef9e3-b060-4172-b013-82391bfed952%2FUntitled.png?table=block&id=aa65a61f-52dd-4a71-89a0-bf24fc7b2e2c&t=aa65a61f-52dd-4a71-89a0-bf24fc7b2e2c&width=471&cache=v2)
状态机部分
always1:将next_state切换
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F8c04038b-0374-4c1d-9311-222d4e57f707%2FUntitled.png?table=block&id=0e175abe-abcb-4d9d-8641-d7165f8dd745&t=0e175abe-abcb-4d9d-8641-d7165f8dd745&width=583&cache=v2)
always2:描述状态切换条件
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F9d80a817-8951-4de5-b2e0-5ad281dca329%2FUntitled.png?table=block&id=4f4b021b-3121-4005-ae4f-b686a54c5be5&t=4f4b021b-3121-4005-ae4f-b686a54c5be5&width=630&cache=v2)
always3:通过task描述各个状态的功能
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F5edaeec1-f44b-475c-b092-bc203aba5bec%2FUntitled.png?table=block&id=fab01771-a66f-4bad-8be6-0c7361c0a9cd&t=fab01771-a66f-4bad-8be6-0c7361c0a9cd&width=419&cache=v2)
idle_task:初始化变量
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Ff0d92295-409f-4911-8166-1e78e870d638%2FUntitled.png?table=block&id=62ed825e-4ba1-4128-9914-be5c81b64376&t=62ed825e-4ba1-4128-9914-be5c81b64376&width=718&cache=v2)
lcd_rst_task 生成时钟序列
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fcfce83fc-ce69-411b-95ba-41f74a0ac4aa%2FUntitled.png?table=block&id=eb6dbffa-58a9-489f-8e22-3068cfb94fcf&t=eb6dbffa-58a9-489f-8e22-3068cfb94fcf&width=826&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fa4d5b403-a4d1-459e-a890-ff388b90c9e2%2FUntitled.png?table=block&id=65aa19a9-6f10-49f1-9423-561c135cb08d&t=65aa19a9-6f10-49f1-9423-561c135cb08d&width=715&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F4e3ea1f0-ce60-452b-81ee-4282c0cd5ec9%2FUntitled.png?table=block&id=8ecf974d-2f4f-4a36-9325-9d71d49ca28f&t=8ecf974d-2f4f-4a36-9325-9d71d49ca28f&width=758&cache=v2)
进入完成态
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F9d604807-da02-45aa-8288-b02d253e9431%2FUntitled.png?table=block&id=ea26a79b-1dd1-4fa2-b631-8a66d453b930&t=ea26a79b-1dd1-4fa2-b631-8a66d453b930&width=564&cache=v2)
完成态只传输完成
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F0b61a69b-4177-4723-8c60-91c6ed2d843c%2FUntitled.png?table=block&id=c0207f3e-44a3-41aa-abd6-12096b8de2d3&t=c0207f3e-44a3-41aa-abd6-12096b8de2d3&width=744&cache=v2)
simulate
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F93cc4914-5264-43d7-ac1b-ca5327ebbf80%2FUntitled.png?table=block&id=b1278b67-d696-421a-86e4-f9a5d227a541&t=b1278b67-d696-421a-86e4-f9a5d227a541&width=837&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F2e780506-06db-4b29-bdce-7ba86c34e405%2FUntitled.png?table=block&id=84824e77-96f1-4ea5-89ba-ee0fe7f839c4&t=84824e77-96f1-4ea5-89ba-ee0fe7f839c4&width=777&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F02794306-5c4e-45d3-bab9-31e8a7dbdc9c%2FUntitled.png?table=block&id=9b55b23e-7c01-40de-8338-de6a8379b94d&t=9b55b23e-7c01-40de-8338-de6a8379b94d&width=831&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F7c2a6692-70eb-4907-97ba-93a159414348%2FUntitled.png?table=block&id=1c2238d1-4d32-4bde-8ad7-faeb1fa2fe96&t=1c2238d1-4d32-4bde-8ad7-faeb1fa2fe96&width=907&cache=v2)
符合规格书的要求
SPI DRIVER
analysis
串行写接口
CSX select pin,低电平有效,高电平忽略SDA和D/CX
SCL低电平的中间 SDA改变,其他时间保持稳定
D/CX 对应 data and command DC,最后一clk接受黄色的bit,最后一clk需要保持稳定,0是command,1是data(D7~D0)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F2b35d381-db87-4b17-af6f-f6df1d2e08d9%2FUntitled.png?table=block&id=27decec4-7b1e-4043-a8dd-c586b8cc11b9&t=27decec4-7b1e-4043-a8dd-c586b8cc11b9&width=815&cache=v2)
timing
对150ns的读最短时间,最大频率6.667MHz
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fe5744452-84a3-4d68-8e57-a7ef02ed3ed1%2FUntitled.png?table=block&id=07a646c1-d725-463f-b082-5a859a05194e&t=07a646c1-d725-463f-b082-5a859a05194e&width=708&cache=v2)
因此,需要5MHz的时钟
code
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F972ed1cc-a9eb-4ebd-9765-e8f535569639%2FUntitled.png?table=block&id=2241aa53-e44b-47d7-a41f-58de6dd6fd3a&t=2241aa53-e44b-47d7-a41f-58de6dd6fd3a&width=758&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fb7d43908-eaf1-40e5-95a0-49222c4bf2f7%2FUntitled.png?table=block&id=9abc9aac-b094-4cbb-973d-add2f70534aa&t=9abc9aac-b094-4cbb-973d-add2f70534aa&width=909&cache=v2)
simulation
串行将数据输出给sda口,从而传输给lcd,并且sda数据改变在scl时钟的中间。
首先初始化状态,随后使en_i为1,开始状态切换
随后即开始进行IDLE、LCD_WR、DONE三个状态的切换
在LCD_WR状态,根据analysis,在negedge将cs置为0,并将额外1位数据给到dc,并减少bit_id以读取下一位,切换到将数据编码到SDA的flow
数据被编码到DC,每当SCL在中间时。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fc51f4520-53ea-4f4f-9dd0-2223085ba21c%2FUntitled.png?table=block&id=e172a0b2-407f-4396-850c-3f7ecd9d42c2&t=e172a0b2-407f-4396-850c-3f7ecd9d42c2&width=733&cache=v2)
完成后发送done_o
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F2e82b5d9-0dfe-42ce-911e-65582de5862b%2FUntitled.png?table=block&id=1bac7d66-0fb9-41ac-80df-ef0e8477ed2d&t=1bac7d66-0fb9-41ac-80df-ef0e8477ed2d&width=1174&cache=v2)
lcd_driver module
第一个function为lcd_rst
第二个function为lcd_init,通过spi_driver模块来初始化lcd
第三个为disp_rgb,通过spi_driver来在LCD上显示像素
第四个为disp_pic,通过spi_driver来在LCD上显示图片
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F060ca7ee-1482-4c76-8ab8-b4eb68bd3f5d%2FUntitled.png?table=block&id=7662a970-3363-46de-9ddc-f2eb0476a56e&t=7662a970-3363-46de-9ddc-f2eb0476a56e&width=921&cache=v2)
lcd_rst
初始化LCD,包括fpga的变量。
init_reg_task;用于初始化LCD 参数
lcd_dc告诉lcd ic发送的是command 还是 data
输入文件格式转换
性能
理论传输带宽
6.25MHz时钟,9clk一个byte,0.694MBps?
帧刷新时间计算
共有128*160像素,每个像素为2byte数据,=40960byte
每byte需要9个时钟,每个时钟周期160ns = 1440ns
理论速度(不含指令)为58ms,挺接近的。
仿真显示约为62ms,即16.1FPS
debug
屏幕不显示
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F1b8a5328-f337-4791-a683-0157d126717c%2FUntitled.png?table=block&id=bc7da272-5377-46b4-82b8-273ce783c4aa&t=bc7da272-5377-46b4-82b8-273ce783c4aa&width=865&cache=v2)
尝试通过仿真查看情况,发现仿真速度较慢,尝试Linux虚拟机发现速度类似,修改代码减少等待时间
- 发现代码逻辑问题,每次信号传输时长均为120ms
- 使用不同SCL频率,MID POS忘记修改
- Linux虚拟机并不更加高效
仿真与规格书
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Faa9157f4-6e78-4f6e-ab14-4846d24393dd%2FUntitled.png?table=block&id=1c1e9883-7b8e-49c6-8ae2-1249b57122e5&t=1c1e9883-7b8e-49c6-8ae2-1249b57122e5&width=1306&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2Fc3c5fb1b-600a-401f-a216-48dbaedeb550%2FUntitled.png?table=block&id=0a20b7f0-f7d9-4a5c-b47f-420f62d05853&t=0a20b7f0-f7d9-4a5c-b47f-420f62d05853&width=1205&cache=v2)
问题可能是:第一位data/command分辨位没有传输
长时间(9s)rst_n花屏
状态机控制错误,修改后120ms花屏
花屏不发生改变—屏幕没有被刷新
一条command被当作数据
delay无效
3s数据超过了28位,不会达到条件,因此不刷新
图片变形
像素尺寸不匹配
开发已有单片机的FPGA版本trick
比如这个init指令,可以翻一翻arduino库的代码。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F5eb400a7-3f77-4950-8c0a-487da2b240cb%2FUntitled.png?table=block&id=59f88b23-8077-43ab-b8fd-a5244eae5223&t=59f88b23-8077-43ab-b8fd-a5244eae5223&width=431&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fe11fbe68-040d-41a6-8b37-0405a354bcd8%2F466b7d34-f01f-4e9a-957d-5c7918739690%2FUntitled.png?table=block&id=5fd6c062-ac58-4d5f-a161-8e0c4a40a1ff&t=5fd6c062-ac58-4d5f-a161-8e0c4a40a1ff&width=240&cache=v2)
- Author:NotionNext
- URL:https://tangly1024.com/article/FPGA-SPI-LCD-Driver
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!