All-terrain obstacle-crossing EOD vehicle

Table of contents

Let’s record the projects of last year’s engineering competition. It’s a pity that we didn’t go to the provincial competition due to the epidemic.

1. Competition venue

(1) The venue floor is 408cm×175cm (size error ±3cm) Polycloth,

(2) Dimensional drawing of narrow bridge:

(3) Step size diagram:

(4) Pipe size diagram:

(5) Balloon:

Instructions for balloons:

 2. Modules used in the competition

2.1 Color recognition - OV7670 module

2.1.1 Main parameters of camera

(1)CCD VS CMOS

(2) Image resolution

(3) Features of camera OV7670

2.1.2 Protocol used—sccb protocol

1. Introduction to SCCB protocol

2. SCCB reading and writing process

3.The difference between SCCB and I2C

4.SCCB implementation code

2.1.3 OV7670 module initialization code

1.OV7670.h

2.OV7670.c

2.1.4 The role of FIFO

OV7670 with FIFO pin definition

What is FIFO?

Why do you need FIFO?

FIFO pin function

Reading of an image


1. Competition venue


      There are four types of obstacles with five different characteristics and different difficulties in the venue. Each obstacle has a certain score. The participating teams independently design and make all-terrain cars according to the competition rules to complete the competition across each obstacle. 

      The obstacles are balloons, stairs, pipes, and narrow bridges in three colors. Each obstacle is connected by a black guide line to form a complete competition track, and the starting point and end point of the competition are set. The competition venue is uniformly arranged by the organizing committee.

      After the all-terrain car starts to drive automatically and crosses three other obstacles (pipes, narrow bridges, stairs), it needs to identify the color of the random color card on the color board and pop the corresponding color balloon.

(1) The venue floor is 408cm×175cm (size error ±3cm) Polycloth ,

It is surrounded by a fence with a height of 18cm. There are starting and ending lines on the ground of the venue, 90cm from the edge. There are marking lines 20cm before and after some obstacles for reference by participating teams. The two red lines 60cm from the long side are decorative lines. The five obstacles should be placed according to the type, quantity and location shown in Figures 1 and 2, and fixed on the ground with double-sided tape and cannot be moved. The black wire is laid with 3.8cm wide low-reflective insulating tape.

(2) Dimensional drawing of narrow bridge:

                         Unit: cm

                         Material: Foamed EVA

                         Colour: Black

( 3) Step size chart:

                         Unit: cm

                         Material: Foamed EVA

                         Colour: Black

(4) Pipe size diagram:

                         Unit: cm

                         Material: Acrylic Color: Transparent

(5) Balloon:

           Unit: cm

           Material: rubber

           Color: one each of red, blue and green

           Regarding narrow bridges and step obstacles: Apply matte sandpaper to the surface.

           Balloon layout instructions (dimensions are marked ±10mm):

Instructions for balloons:

Balloon colors are: dark red, dark green, dark blue

Balloon size (width): between 22cm and 26cm, measure the width direction as shown by the black line in the figure below as a reference (the widest distance in the lateral direction);

Balloon installation angle: place the balloon horizontally, with the air nozzle facing the opposite direction to the finish line. The middle part of the bottom surface of the balloon is closely attached to the field cloth. The balloon and the field cloth are fixed with high-viscosity double-sided tape (subject to not falling off when slapped sideways). The error between the fixed position of the balloon and the midpoint of the bottom surface of the balloon is ±5cm;

Instructions on the balloon tying device: Small sharp objects can be used at the end of the balloon tying device, such as paper clips, thumbtacks, toothpicks, etc. The balloon tying device will be inspected before the robot goes on stage;

Regarding the layout of the baffle, see the blue frame as shown below (the dimension error is ±10mm) 

 2. Modules used in the competition

In fact, this game mainly completes three functions, one is line finding, one is balloon tying, and the other is color recognition.

2.1 Color recognition - OV7670 module

OV7670 camera module information_-liming-'s blog-CSDN blog

——————————————
Copyright Statement: This article is an original article by CSDN blogger “-liming-” and follows the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: https://blog.csdn.net/qq_38393591/article/details/116291875

The main purpose here is to strengthen your understanding through the analysis of the code.

2.1.1 Main parameters of camera

(1)CCD VS CMOS

CCD has high imaging quality and relatively good dynamic response, but the manufacturing process is complex, expensive, relatively heavy, and has a voltage of 12V.
CMOS is light in weight, has low requirements on power supply voltage, relatively low power consumption, poor imaging quality, and high noise.
At present, most consumer-level and high-end digital cameras on the market use CCD as the sensor; CMOS sensors are used in some cameras as low-end products.

(2) Image resolution

SXGA (resolution 1280x1024), also known as 1.3 million
pixels ; 320x240) QCIF (resolution 176x144) QSIF/QQVGA (resolution 160x120)




(3) Features of camera OV7670

High sensitivity and low voltage suitable for embedded applications;
standard SCCB interface, compatible with IIC interface;
supports RawRGB, RGB (GBR4:2:2, RGB565 /RGB555 /RGB444), YUV (4:2:2) and YCbCr (4: 2: 2) Output format;
supports VGA, QVGA, CIF, and various size outputs from CIF to 40*30;
supports automatic exposure control, automatic gain control, automatic white balance, automatic elimination of light stripes, and automatic black level calibration and other automatic control functions. It also supports color saturation, hue, gamma, sharpness and other settings;
supports flash;
supports image scaling;

2.1.2 Protocol used—sccb protocol

SCCB protocol_FPGA Xiaobai 758’s blog-CSDN blog

1. Introduction to SCCB protocol

SCCB (Serial Camera Control Bus) is a serial camera control bus. Very similar to the I2C protocol .
SCCB's start signal, stop signal and data validity are exactly the same as I2C.
1. Start signal: When SCL (SIO_C in the figure) is high level, SDA (SIO_D in the figure) appears with a falling edge, and SCCB starts transmission.
2. Stop signal: When SCL is high level, SDA has a rising edge, and SCCB stops transmission.
3. Data validity: In addition to the start and stop states, during the data transmission process, when SCL is high,
the data on SDA must be guaranteed to be stable. That is to say, the level change on SDA can only occur when SCL is low. level, the SDA signal is collected when SCL is high.


2. SCCB reading and writing process

Writing process: start signal + device address write + don’t care + register address + don’t care + write data + don’t care + stop bit.
Like I2C, ID ADDRESS consists of a seven-bit address line plus a read and write bit. X means don't care.

Reading process: start signal + device address write + don't care + register address + don't care + stop signal + start signal + device address write + don't care + read data + unanswered + stop bit.

3.The difference between SCCB and I2C

SCCB (Serial Camera Control Bus) and I2C (Inter-Integrated Circuit) are two serial communication protocols, usually used to control communication between the image sensor and the main control chip. The differences between them are as follows:

1. Response bit: The I2C response bit is ACK (0 means response, 1 means no response). The response bit in SCCB is X, which means don't care

2. Some devices in I2C support page operations, but SCCB does not support page operations

In I2C, page operation refers to accessing multiple registers inside the device by specifying the page register. By setting the page register, multiple related register values ​​can be read or written in one transfer, thereby improving the efficiency of data transfer.

However, in SCCB, there is no mechanism like the page register to support the operation of reading and writing multiple related registers at one time. SCCB is more simplified and focused on the control of the image sensor and can only read and write designated registers one by one.

Therefore, when using the I2C interface, page operations can be used to transfer data in batches, while when using the SCCB interface, each specific register needs to be read and written sequentially. This is also one of the reasons why I2C is more flexible and efficient than SCCB in some scenarios.

3. In the SCCB read operation, there is a stop signal after the dummy write, but it is optional in I2C .

4. Performance: SCCB is a protocol based on I2C. Compared with standard I2C, SCCB has a higher clock rate and shorter transmission cycle , so it has better performance in image sensor control.

5. Address format: I2C uses 7-bit or 10-bit address format to address slave devices, and multiple slave devices can be connected at the same time. SCCB usually uses an 8-bit address format, with a relatively small addressing range, and can often only connect a single image sensor.

6. Simplified protocol: Compared with I2C, SCCB's protocol is more simplified and has more specific functions, which is suitable for specific application scenarios such as image sensors.

4.SCCB implementation code

sccb.c

#include "sys.h"
#include "sccb.h"
#include "delay.h"
//
//本程序参考自网友guanfu_wang代码。
//ALIENTEK MiniSTM32开发板
//OV7670 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2012/10/31
//版本:V1.0
//

//初始化SCCB接口
//CHECK OK
void SCCB_Init(void)
{


    GPIO_InitTypeDef  GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);	 //使能PC端口时钟


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;				 // 端口配置
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //输输出
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		 //IO口速度为50MHz
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC,GPIO_Pin_6|GPIO_Pin_7);						 // 输出高

    SCCB_SDA_OUT();
}

//SCCB起始信号
//当时钟为高的时候,数据线的高到低,为SCCB起始信号
//在激活状态下,SDA和SCL均为低电平
void SCCB_Start(void)
{
    SCCB_SDA=1;     //数据线高电平
    SCCB_SCL=1;	    //在时钟线高的时候数据线由高至低
    delay_us(50);
    SCCB_SDA=0;
    delay_us(50);
    SCCB_SCL=0;	    //数据线恢复低电平,单操作函数必要
}

//SCCB停止信号
//当时钟为高的时候,数据线的低到高,为SCCB停止信号
//空闲状况下,SDA,SCL均为高电平
void SCCB_Stop(void)
{
    SCCB_SDA=0;
    delay_us(50);
    SCCB_SCL=1;
    delay_us(50);
    SCCB_SDA=1;
    delay_us(50);
}
//产生NA信号
void SCCB_No_Ack(void)
{
    delay_us(50);
    SCCB_SDA=1;
    SCCB_SCL=1;
    delay_us(50);
    SCCB_SCL=0;
    delay_us(50);
    SCCB_SDA=0;
    delay_us(50);
}
//SCCB,写入一个字节
//返回值:0,成功;1,失败.
u8 SCCB_WR_Byte(u8 dat)
{
    u8 j,res;
    for(j=0; j<8; j++) //循环8次发送数据
    {
        if(dat&0x80)SCCB_SDA=1;
        else SCCB_SDA=0;
        dat<<=1;
        delay_us(50);
        SCCB_SCL=1;
        delay_us(50);
        SCCB_SCL=0;
    }
    SCCB_SDA_IN();		//设置SDA为输入
    delay_us(50);
    SCCB_SCL=1;			//接收第九位,以判断是否发送成功
    delay_us(50);
    if(SCCB_READ_SDA)res=1;  //SDA=1发送失败,返回1
    else res=0;         //SDA=0发送成功,返回0
    SCCB_SCL=0;
    SCCB_SDA_OUT();		//设置SDA为输出
    return res;
}
//SCCB 读取一个字节
//在SCL的上升沿,数据锁存
//返回值:读到的数据
u8 SCCB_RD_Byte(void)
{
    u8 temp=0,j;
    SCCB_SDA_IN();		//设置SDA为输入
    for(j=8; j>0; j--) 	//循环8次接收数据
    {
        delay_us(50);
        SCCB_SCL=1;
        temp=temp<<1;
        if(SCCB_READ_SDA)temp++;
        delay_us(50);
        SCCB_SCL=0;
    }
    SCCB_SDA_OUT();		//设置SDA为输出
    return temp;
}
//写寄存器
//返回值:0,成功;1,失败.
u8 SCCB_WR_Reg(u8 reg,u8 data)
{
    u8 res=0;
    SCCB_Start(); 					//启动SCCB传输
    if(SCCB_WR_Byte(SCCB_ID))res=1;	//写器件ID
    delay_us(100);
    if(SCCB_WR_Byte(reg))res=1;		//写寄存器地址
    delay_us(100);
    if(SCCB_WR_Byte(data))res=1; 	//写数据
    SCCB_Stop();
    return	res;
}
//读寄存器
//返回值:读到的寄存器值
u8 SCCB_RD_Reg(u8 reg)
{
    u8 val=0;
    SCCB_Start(); 				//启动SCCB传输
    SCCB_WR_Byte(SCCB_ID);		//写器件ID
    delay_us(100);
    SCCB_WR_Byte(reg);			//写寄存器地址
    delay_us(100);
    SCCB_Stop();
    delay_us(100);
    //设置寄存器地址后,才是读
    SCCB_Start();
    SCCB_WR_Byte(SCCB_ID|0X01);	//发送读命令
    delay_us(100);
    val=SCCB_RD_Byte();		 	//读取数据
    SCCB_No_Ack();
    SCCB_Stop();
    return val;
}




sccb.h

#ifndef __SCCB_H
#define __SCCB_H
#include "sys.h"
//
//本程序参考自网友guanfu_wang代码。
//ALIENTEK MiniSTM32开发板
//OV7670 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2012/10/31
//版本:V1.0
//

#define SCCB_SDA_IN()  {GPIOC->CRL&=0X0FFFFFFF;GPIOC->CRL|=0X80000000;}
#define SCCB_SDA_OUT() {GPIOC->CRL&=0X0FFFFFFF;GPIOC->CRL|=0X30000000;}

//IO操作函数
#define SCCB_SCL    		PCout(6)	 	//SCL
#define SCCB_SDA    		PCout(7) 		//SDA	 

#define SCCB_READ_SDA    	PCin(7)  		//输入SDA    
#define SCCB_ID   			0X42  			//OV7670的ID

///
void SCCB_Init(void);
void SCCB_Start(void);
void SCCB_Stop(void);
void SCCB_No_Ack(void);
u8 SCCB_WR_Byte(u8 dat);
u8 SCCB_RD_Byte(void);
u8 SCCB_WR_Reg(u8 reg,u8 data);
u8 SCCB_RD_Reg(u8 reg);
#endif


2.1.3 OV7670 module initialization code

1.OV7670.h
#ifndef _OV7670_H
#define _OV7670_H
#include "sys.h"
#include "sccb.h"
//
//本程序参考自网友guanfu_wang代码。
//ALIENTEK MiniSTM32开发板
//OV7670 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2012/10/31
//版本:V1.0
//
#define OV7670_WRST		PCout(0)		//写指针复位
#define OV7670_RCK		PCout(5)		//读数据时钟
#define OV7670_RRST		PCout(1)  		//读指针复位
#define OV7670_CS		PCout(3)  		//片选信号(OE)
#define OV7670_WREN		PCout(2)		//写入FIFO使能
#define OV7670_VSYNC  	PCout(4)		//同步信号检测IO

#define OV7670_DATA   GPIOA->IDR&0x00FF  					//数据输入端口
/

u8   OV7670_Init(void);
void OV7670_Light_Mode(u8 mode);
void OV7670_Color_Saturation(u8 sat);
void OV7670_Brightness(u8 bright);
void OV7670_Contrast(u8 contrast);
void OV7670_Special_Effects(u8 eft);
void OV7670_Window_Set(u16 sx,u16 sy,u16 width,u16 height);


#endif


2.OV7670.c
#include "sys.h"
#include "ov7670.h"
#include "ov7670cfg.h"
#include "timer.h"
#include "delay.h"
#include "usart.h"
#include "sccb.h"
#include "exti.h"
//
//本程序参考自网友guanfu_wang代码。
//ALIENTEK MiniSTM32开发板
//OV7670 驱动代码
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//修改日期:2012/10/31
//版本:V1.0
//

//初始化OV7670
//返回0:成功
//返回其他值:错误代码
u8 OV7670_Init(void)
{
    u8 temp;
    u16 i=0;
    //设置IO

    GPIO_InitTypeDef  GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);	 //使能相关端口时钟

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_5;				 // 端口配置
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		 //IO口速度为50MHz
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_5);


    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4; //PA15输入 上拉
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC,GPIO_Pin_4);

    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_3|GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC,GPIO_Pin_3|GPIO_Pin_2);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;				 //LED0-->PB.5 端口配置
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 		 //推挽输出
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		 //IO口速度为50MHz
    GPIO_Init(GPIOA, &GPIO_InitStructure);					 //根据设定参数初始化GPIOB.5

    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);	//SWD

    SCCB_Init();        		//初始化SCCB 的IO口
    if(SCCB_WR_Reg(0x12,0x80))return 1;	//复位SCCB
    delay_ms(50);
    //读取产品型号
    temp=SCCB_RD_Reg(0x0b);
    if(temp!=0x73)return 2;
    temp=SCCB_RD_Reg(0x0a);
    if(temp!=0x76)return 2;
    //初始化序列
    for(i=0; i<sizeof(ov7670_init_reg_tbl)/sizeof(ov7670_init_reg_tbl[0]); i++)
    {
        SCCB_WR_Reg(ov7670_init_reg_tbl[i][0],ov7670_init_reg_tbl[i][1]);
        delay_ms(2);
    }
    return 0x00; 	//ok
}

//OV7670功能设置
//白平衡设置
//0:自动
//1:太阳sunny
//2,阴天cloudy
//3,办公室office
//4,家里home
void OV7670_Light_Mode(u8 mode)
{
    u8 reg13val=0XE7;//默认就是设置为自动白平衡
    u8 reg01val=0;
    u8 reg02val=0;
    switch(mode)
    {
    case 1://sunny
        reg13val=0XE5;
        reg01val=0X5A;
        reg02val=0X5C;
        break;
    case 2://cloudy
        reg13val=0XE5;
        reg01val=0X58;
        reg02val=0X60;
        break;
    case 3://office
        reg13val=0XE5;
        reg01val=0X84;
        reg02val=0X4c;
        break;
    case 4://home
        reg13val=0XE5;
        reg01val=0X96;
        reg02val=0X40;
        break;
    }
    SCCB_WR_Reg(0X13,reg13val);//COM8设置
    SCCB_WR_Reg(0X01,reg01val);//AWB蓝色通道增益
    SCCB_WR_Reg(0X02,reg02val);//AWB红色通道增益
}
//色度设置
//0:-2
//1:-1
//2,0
//3,1
//4,2
void OV7670_Color_Saturation(u8 sat)
{
    u8 reg4f5054val=0X80;//默认就是sat=2,即不调节色度的设置
    u8 reg52val=0X22;
    u8 reg53val=0X5E;
    switch(sat)
    {
    case 0://-2
        reg4f5054val=0X40;
        reg52val=0X11;
        reg53val=0X2F;
        break;
    case 1://-1
        reg4f5054val=0X66;
        reg52val=0X1B;
        reg53val=0X4B;
        break;
    case 3://1
        reg4f5054val=0X99;
        reg52val=0X28;
        reg53val=0X71;
        break;
    case 4://2
        reg4f5054val=0XC0;
        reg52val=0X33;
        reg53val=0X8D;
        break;
    }
    SCCB_WR_Reg(0X4F,reg4f5054val);	//色彩矩阵系数1
    SCCB_WR_Reg(0X50,reg4f5054val);	//色彩矩阵系数2
    SCCB_WR_Reg(0X51,0X00);			//色彩矩阵系数3
    SCCB_WR_Reg(0X52,reg52val);		//色彩矩阵系数4
    SCCB_WR_Reg(0X53,reg53val);		//色彩矩阵系数5
    SCCB_WR_Reg(0X54,reg4f5054val);	//色彩矩阵系数6
    SCCB_WR_Reg(0X58,0X9E);			//MTXS
}
//亮度设置
//0:-2
//1:-1
//2,0
//3,1
//4,2
void OV7670_Brightness(u8 bright)
{
    u8 reg55val=0X00;//默认就是bright=2
    switch(bright)
    {
    case 0://-2
        reg55val=0XB0;
        break;
    case 1://-1
        reg55val=0X98;
        break;
    case 3://1
        reg55val=0X18;
        break;
    case 4://2
        reg55val=0X30;
        break;
    }
    SCCB_WR_Reg(0X55,reg55val);	//亮度调节
}
//对比度设置
//0:-2
//1:-1
//2,0
//3,1
//4,2
void OV7670_Contrast(u8 contrast)
{
    u8 reg56val=0X40;//默认就是contrast=2
    switch(contrast)
    {
    case 0://-2
        reg56val=0X30;
        break;
    case 1://-1
        reg56val=0X38;
        break;
    case 3://1
        reg56val=0X50;
        break;
    case 4://2
        reg56val=0X60;
        break;
    }
    SCCB_WR_Reg(0X56,reg56val);	//对比度调节
}
//特效设置
//0:普通模式
//1,负片
//2,黑白
//3,偏红色
//4,偏绿色
//5,偏蓝色
//6,复古
void OV7670_Special_Effects(u8 eft)
{
    u8 reg3aval=0X04;//默认为普通模式
    u8 reg67val=0XC0;
    u8 reg68val=0X80;
    switch(eft)
    {
    case 1://负片
        reg3aval=0X24;
        reg67val=0X80;
        reg68val=0X80;
        break;
    case 2://黑白
        reg3aval=0X14;
        reg67val=0X80;
        reg68val=0X80;
        break;
    case 3://偏红色
        reg3aval=0X14;
        reg67val=0Xc0;
        reg68val=0X80;
        break;
    case 4://偏绿色
        reg3aval=0X14;
        reg67val=0X40;
        reg68val=0X40;
        break;
    case 5://偏蓝色
        reg3aval=0X14;
        reg67val=0X80;
        reg68val=0XC0;
        break;
    case 6://复古
        reg3aval=0X14;
        reg67val=0XA0;
        reg68val=0X40;
        break;
    }
    SCCB_WR_Reg(0X3A,reg3aval);//TSLB设置
    SCCB_WR_Reg(0X68,reg67val);//MANU,手动U值
    SCCB_WR_Reg(0X67,reg68val);//MANV,手动V值
}
//设置图像输出窗口
//对QVGA设置。
void OV7670_Window_Set(u16 sx,u16 sy,u16 width,u16 height)
{
    u16 endx;
    u16 endy;
    u8 temp;
    endx=sx+width*2;	//V*2
    endy=sy+height*2;
    if(endy>784)endy-=784;
    temp=SCCB_RD_Reg(0X03);				//读取Vref之前的值
    temp&=0XF0;
    temp|=((endx&0X03)<<2)|(sx&0X03);
    SCCB_WR_Reg(0X03,temp);				//设置Vref的start和end的最低2位
    SCCB_WR_Reg(0X19,sx>>2);			//设置Vref的start高8位
    SCCB_WR_Reg(0X1A,endx>>2);			//设置Vref的end的高8位

    temp=SCCB_RD_Reg(0X32);				//读取Href之前的值
    temp&=0XC0;
    temp|=((endy&0X07)<<3)|(sy&0X07);
    SCCB_WR_Reg(0X17,sy>>3);			//设置Href的start高8位
    SCCB_WR_Reg(0X18,endy>>3);			//设置Href的end的高8位
}

2.1.4 The role of FIFO

OV7670 with FIFO pin definition

What is FIFO?

FIFO: First in, First out

It means that the advanced data comes out first and the last data comes out last.

Why do you need FIFO?

(1) In a typical serial port design, the send/receive buffer is only 1 byte, and each send/receive can only process 1 frame of data. This
is not a problem in a microcontroller, but it will be a problem in a complex SoC (generally with an operating system), which will lead to low efficiency because the
CPU needs to constantly switch contexts.
(2) The solution is to find a way to expand the send/receive buffer of the serial port controller. For example, set the send/receive buffer to 64
bytes, and the CPU will directly send 64 bytes of data to be sent to the send buffer. Then the transmitter slowly sends it, and after sending it, it asks
the CPU for another 64 bytes. However, the original send/receive buffer of the serial port controller has a fixed length of 1 byte, so a disguised
extension is made, which is FIFO.
(3) FIFO is first in first
out, first in first out. fifo is actually a data structure. The large buffer here is called FIF0 because this buffer works
similar to the data structure FIF0.

FIFO memory is the buffer link of the system. Without FIFO memory, the entire system cannot work normally.

The function of FIFO can be summarized as

(1) Cache continuous data streams to prevent data loss during entry and storage operations ;

(2) Data is centralized for entry and storage, which can avoid frequent bus operations and reduce the burden on the CPU;

(3) Allow the system to perform DMA operations and increase the data transmission speed . This is a crucial point. If DMA operation is not used, data transmission will not meet the transmission requirements, and the burden on the CPU will be greatly increased, and the data storage work cannot be completed at the same time.

FIFO pin function

Explain that PCLK and XCLK are not used in this module. The FIFO and OV7670 have been configured by themselves.
The two lines SIOC and SIOD are the clock lines and data lines of the SCCB communication protocol. They are basically the same as IIC communication. You can understand the communication process by yourself.
HREF horizontal synchronization signal basically does not use it.
The VSYNC frame synchronization signal is to pull this pin high every time before the camera writes a picture to tell you that I am going to start outputting.
The reset port and power mode port can be directly connected to 3v and GND. They can also be connected to the IO port for control. However, please note that if you connect the IO port, the pin configuration must be placed before the OV7670 register configuration, otherwise it will be reset directly for you. (It’s all blood and tears...)
Don’t use flash when taking photos.
The rest is the FIFO control IO.
(The recorder and everything are metaphors.)
RCK is the signal when you press the pause button of the recorder. It reads the data once and gives a rising edge.
WR is the IO that controls whether your recorder records. It records when the level is high.
OE is the power button of your recorder.
WRST is write reset, which is equivalent to rewinding the tape recorder to the beginning. When recording, record from the beginning of the tape to the back.
RRST is read reset, which is equivalent to rewinding the tape recorder and listening to it from the beginning.

Reading of an image

The reading process is extremely simple. I use the analogy of a tape recorder to say:
/>>> (image writing) recording process
1. Wait for the frame synchronization signal to be pulled high
2. FIFO resets the write pointer (the recorder rewinds to the beginning of the tape)
3. FIFO writing is allowed (the recorder presses the recording button)
4. Wait for the frame synchronization signal to be pulled high again (indicating that the second picture has arrived and that the first picture has been written)
5. FIFO writing is prohibited (stop recording)
/>>>Read Figure process (listening to the recording)
1. FIFO read pointer reset (the recorder rewinds to the beginning of the tape)
2. FIFO to RCK (press the play button of the recorder, here it is assumed that the recorder plays half a sentence when pressed, and one sentence represents one pixel)
3. Read data (listen to the first half of the first sentence)
4. FIFO to RCK
5. Read data (listen to the second half of the first sentence)
6. FIFO to RCK
7. Read data (listen to the top of the second sentence) Half a sentence)
8. FIFO to RCK
9. Read data (listen to the second half of the second sentence)
··············Read all pixels n in this loop . End
after reading the last pixel
, obtain all image pixel data.
OV7670 with FIFO entry guide_weixin_42368395's blog-CSDN blog

2.2 Hall motor module

2.2.1 Motor parameters used

JGA25-370 DC reduction motor encoder speed measuring disc high power high torque balancing car motor

Here you can see that the reduction ratio is 21.3 and the rated current is 0.5A

The no-load speed of the Hall motor refers to the speed when the motor is powered at the maximum rated voltage without bearing any load. In the absence of external load, the motor only needs to overcome its own internal friction and inertia resistance, so the highest speed it can reach is the no-load speed. No-load speed is an important indicator of motor performance, which is usually expressed in revolutions per minute (rpm) or revolutions per second (rps).

2.2.2 Reduction ratio

The reduction ratio can be obtained above as 21.3, and the resolution according to Taobao’s customer service is 234.4

Number of pulses per minute = 280 RPM * 21.3 * 234.3

2.2.3 Motor control

The core of motor control is actually to control the power supply terminal voltage.

TB6612 driver

The motor driver is actually a power amplifier, which amplifies our output power and then outputs it to the actuator---the motor to realize the control of the actuator by the output signal. The function of the driver board is actually to convert the control signal generated by the microcontroller into an electrical signal that the motor can understand, and to ensure the safe operation of the motor by increasing sufficient current and voltage, and protecting the circuit. gram

Product parameters

  • Logic part input voltage VCC : 3.3~5V
  • Drive part input voltage VM : 2.5~12V
  • Number of drive motor circuits: 2 channels
  • Maximum continuous drive current of single channel: 1.2A
  • Starting peak value: 2A/3.2A ( continuous pulse / single pulse )
  • Interface mode: 2.54mm pitch pin header

Pin description

pin mapping

label

name

Function description

1

DIR1

Direction control pin of motor M1

3

PWM2

Speed ​​control pin of motor M2

4

DIR2

Direction control pin of motor M2

5

GND

Logic section power supply negative pole

6

VCC

Logic part power supply positive pole

7

M1+

M1 motor output 1

8

M1-

M1 motor output 2

9

M2+

M2 motor output 1

10

M2-

M2 motor output 2

11

GND

Negative pole of motor power supply

12

VM(<12V)

Motor power positive pole

  • Module size: 20 × 19.5(mm)

TB6612 has two GNDs. At this time, one GND is connected to the ground of the power supply, and the other GND is connected to the ground of the microcontroller. If they are all connected to the same ground, the current will start from the positive pole, and a relatively large current will flow into the microcontroller, which may cause damage to the microcontroller. Therefore, one GND is connected to the ground of the power supply to ensure that the power can flow back, and one GND is connected to the ground of the microcontroller so that the signals can have a common reference.

Basic control block diagram

Link: https://pan.baidu.com/s/1didnZ8RCCjAaLdO4iVBPdA?pwd=6666 
Extraction code: 6666

Guess you like

Origin blog.csdn.net/qq_51519091/article/details/132502962