Smart car learning process

understanding

Interrupt

Interrupt: An interrupt is a single-chip running other code, the system can run continuously interrupted by interrupt, the interrupt service routine to run, open break refers to systems in continuous operation can be interrupted to run the interrupt service function, disable interrupts It refers to shut down the system interrupts, interrupt the continuous operation of the system.
Microcontroller interrupt is a very useful set. We will set up some simple operations within the interrupt routine in the preparation of the program, such as the keyboard on the scanner, the sensor returns data reading program, and so on. And most of all have a fixed interrupt trigger conditions and time, we can use these to enter the interruption of a specific time to complete a lot of specific events. For example, there 1Hz interrupt, and interrupt and so on ~ ~ 2Hz
when we all set to break open, then all this type of microcontroller interrupt will be at this time and its unique conditions, into its own in the program inside interrupt routines to perform the work. If we disable interrupts, then all types of interrupts whatever the conditions and time will not enter its own interrupt routines to perform the work. Many microcontroller interrupt can be differentiated selection switch interrupt, but also some open and some closed.
As a reminder, the stack must take the set Ay interrupt execution of the program inside, Yao timely protection of data within each common register, or a data interrupt is messed up ~ ~

/*!
 *  @brief      main函数
 *  @since      v50
  *  @note       山.外摄像头 LCD 测试实验
 */
void  main(void)
{
    DisableInterrupts;        //关闭总中断

    PLL_Init(PLL200);         //初始化PLL为200M,总线为100MHZ   决定单片机处理速度
    camera_init(imgbuff);       //摄像头初始化
    UART_Init(UART_4,115200);   //蓝牙或串口初始化


    FTM_PWM_Init(FTM3,FTM_CH1,312,250);//PTE8    //电机1-A
    GPIO_Init(PTE,8,GPO,1);
    FTM_PWM_Init(FTM3,FTM_CH5,312,250);//PTE12    //电机2-A
    GPIO_Init(PTE,12,GPO,1);

    FTM_PWM_Init(FTM0 ,FTM_CH1,62500,duty);//PTC2 50000-125HZ

    EnableInterrupts;

    while(1)
    {
        camera_get_img();                                   //摄像头获取图像
        find_line();
        SendPicture();//调试时  一定要注释这一行!!!
    }
}



void SendPicture(void)
{
  int i=0,j=0;
   UART_Put_Char(UART_4,0x01);
   UART_Put_Char(UART_4,0xFE);
    for(i=0;i<OV7725_EAGLE_H;i++)
    {
      for(j=0;j<OV7725_EAGLE_W;j++)
      {
          UART_Put_Char(UART_4,Image_data[i][j]);
      }
    }
   UART_Put_Char(UART_4,0xFE);
   UART_Put_Char(UART_4,0x01);
}

Hunt

Shanghai Jiaotong University Freescale hunt algorithm https://wenku.baidu.com/view/9d90428dd0d233d4b14e690f.html

Serial ports

Acronym serial interface port, also called a serial communication interface or a serial communication interface (COM interface generally refers), is extended serial communication interfaces. A serial interface (Serial Interface) refers to the data are sequentially transmitted one bit, which is characterized by a communication line as simple as a pair of transmission lines can be two-way communication (telephone lines can be directly used as a transmission line), thereby greatly reducing the cost, especially suitable for long-distance communication, but the transmission rate is lower.
A serial interface (Serial Interface) refers to the data are sequentially transmitted one bit, which is characterized by a communication line as simple as a pair of transmission lines can be two-way communication (telephone lines can be directly used as a transmission line), thereby greatly reducing the cost, especially suitable for long-distance communication, but the transmission rate is lower. Bit data one bit by bit information are transmitted in order of communication called serial communication. Serial communication characteristics are: transmission of data bits, a bit sequence, only a minimum of the transmission line to complete; low cost but slow transfer speed. Serial communication distance can be from a few meters to several kilometers; according to the transmission direction information, serial communication can be further divided into single, half-duplex and full-duplex three.

Bluetooth serial port

1, a wireless Bluetooth serial port:
Here Insert Picture Description
2, the Bluetooth serial port cable: each team has a Bluetooth serial rear strip, may be directly connected by a wire directly between Bluetooth.
Here Insert Picture Description
3, Bluetooth serial port hardware and program parts

UART_Init(UART_4,115200);   //蓝牙或串口初始化 

The following example is a Bluetooth serial port K66:
Here Insert Picture Description
Here Insert Picture Description
wherein RX and TX represent transmission and reception, the transmitting end and receiving end of the single-chip Bluetooth serial connection.
For example: RX (transmitting side) and on the microcontroller TX port on Bluetooth (receiving end), TX (receiving side) of the microcontroller and RX (transmitting side) on a Bluetooth serial connection. If a connection error when sub-lines, will not spread, according to the Bluetooth, not an image.

Simplex, half and full duplex

1. simplex data transfer only support data transmission in one direction; only one side can receive or transmit information at the same time, two-way communication can not be achieved, for example: television, radio.

2. Half-duplex data transmission permission data transmission in both directions, however, at a time, allows data transmission only in one direction, it is actually Simplex A handover direction; at the same time can only be one party to accept or transmit information, two-way communication can be realized. For example: walkie-talkie.
Here Insert Picture Description

3. Full-duplex data communication allows data transmission in both directions simultaneously, and therefore, full-duplex communication is a combination of two simplex communication scheme, which requires sending and receiving devices have separate receive and transmit capability; in acceptable same time and send messages simultaneously to achieve two-way communication, for example: the telephone communication.

4. Full Duplex NIC (Full Duplex) refers to simultaneously transmit data in the card can receive data, both simultaneously, as we usually call it, like, talking at the same time also be able to hear each other's voices. The current NIC general support full-duplex.

Extended Information:
simplex, half-duplex and full-duplex telecommunications computer network three communication channels. Route information communicated communication channels may be provided. The communication channel may be a physical transmission medium or via a logical multiplexing medium. Physical transmission medium refers to a material capable of propagating material energy waves, such as data communication wires. Generally refers to a logical connection and circuit switched connection or packet-mode virtual circuit connection, such as a wireless telecommunications channel. Since help communication channel, information can be transmitted without hindrance.

Simplex mode generally used in the case of data transmission in only one direction. For example, communication between the computer and the printer is a simplex mode, since the computer only transmit data to the printer, but not in the opposite direction of data transmission. There are some communication channels, such as a simplex radio transmitting and the like.

echo

So-called echo, the data transmission means are displayed at the receiving end.

Echo is displayed batch command being executed and execution results and the like. Often referred to as the result of executing the command program development, is the return of the show, you enter a command, and then give you a return value, displayed on the screen.
When executing some commands, if you do not want the return value, it is necessary to eliminate echo. For example: In the treatment with the serial communication, AT command to detect whether the Module communicates with the serial port, can receive an AT command. Command returns: OK (normal serial communication) (no return, not in communication with the serial communication). With ATE0 remove echo.

AT command

There are two explanations AT command modem command language one is, the other is scheduled tasks in Windows command line.

modem

A modem is a computer hardware, computer digital signal that can be translated into an analog signal may be transmitted along an ordinary telephone line, and the analog signals received by the other modem in turn the other end of the line, and translated into a computer-understandable language . This simple process is complete communication between two computers.

Modulator is a modem (modulator) and Demodulator (demodulator) is referred to, Chinese called modem (referred to as Hong Kong and modem), according Modem homonym, endearingly called "cat." It is modulated by the transmitting side digital signal into an analog signal, and then demodulated at the receiving end by an apparatus for converting an analog signal into a digital signal.
The so-called modulation, is to convert a digital signal into an analog transmission signal from the telephone line; demodulating, i.e., converting the analog signals into digital signals. Collectively known as the modem.

Linear CCD

CCD sensors: charge coupled device image sensor CCD (Charge Coupled Device)
CCD sensor is a new type photoelectric conversion device, which can store the signal charge generated by the light

HOW 口

Nickname: serial communications port, com port
COM port (cluster communication port) that is a serial communications port, referred to the serial port . Serial port is a 9-pin is typically a microcomputer, there are 25-pin interface, the maximum rate 115200bps. Typically used to connect a mouse (serial) and communication devices (e.g., external modem connection for data communication or some plants CNC-machine interface) and the like. Usually only one motherboard external serial port, and parallel with the rear of the chassis that abalone output terminal (trapezoid) is COM1 port, the pin leading-out port COM2 generally from the motherboard. Parallel is the longest of the trapezoidal opening.

Threshold

Mean threshold limits, so that the threshold value called the critical

Binarization

Image binarization is to set the gray value of pixel on the image is 0 or 255, that is, the entire image showing a clear black and white only visual effect. Binarization (English: Thresholding) is one of the simplest method of image segmentation.

Image data

The image data are from top to bottom, left to right store (this somewhat uncertain)

Upper and lower machine

PC refers to steering commands can be issued directly to the computer, usually PC / host computer / master computer / upper computer, various signal changes will be displayed on the screen.
It refers to lower machine directly control the device status acquisition device, generally PLC / microcontroller or the like. Command issued by host computer will next crew, the next crew interpreted according to the corresponding timing signal corresponding to the control command directly to the device. Bit state reading apparatus data chance from time to time, and then converted into digital signals to the host device.
Only the length of the lower machine format data transmission with the host computer configuration are the same can correctly identify the image format, an image is displayed correctly.

Debugging assistant camera

Here Insert Picture Description
Here Insert Picture Description

Linear CCD debugging assistant

Here Insert Picture Description

Virtual oscilloscope

Here Insert Picture Description
Here Insert Picture Description

Steering gear (motor housed therein)

Servo means control the aircraft control surface (manipulation surface) in the autopilot for performing rotatable member. Points are: ① electric steering gear, by an electric motor, the drive member and the clutch components.

Clock definition list

PDB

PDB controllable delay may be provided as an internal or external trigger source, or trigger or generate DAC provides programmable interval ADC hardware. This would think that the completion of the ADC and DAC output to provide accurate time. PDB pulse output module may also be provided, on the line CMP module as sampling window.

Elastic timer (FlexTimer, FTM)

Flexible timer module (the FTM) is a support input capture, output compare and PWM signal generator for controlling the motor 2-8 channel timer and power management applications. FTM is a time reference can be used as a signed or unsigned 16-bit counter counter.
FTM module has only one clock domain is the system clock.

1, synchronized counter

Here Insert Picture Description

2, initialize the flip-flop

If INITTRIGEN = 1, then when the counter is updated to the value FTM CNTIN register in the following case, a trigger is generated FTM. When the counter is selected as FTM mode technology, CNTIN automatically updated to the value of the register. When writing to the registers CNT. When the synchronization if (CNT = CNTIN), (CLKS [1: 0] = 0: 0) FTM counter has, and there is a non-zero value is written CLKS [1: 0] bits

Distinction 3, PIC microcontroller timer register and the timer period register

Timer registers include a control register and a cycle register, a timer control register can be set frequency dividing ratio, enabling oscillation source, interrupt enable, etc., and the period register is used to store the number counted by the timer, such as 16 the timer can count up to 65535 times.
Period register appear in TMR2, you can set a maximum of FFH (default values are all 1), how much value you set, it uses natural overflow overflow it is not after all one at that value, but depends on the period and TMR2 register comparison of the results of both the content of a match but immediately send a message overflow

4, timer

Periodic trigger timer after opening. Loading the timer start value, such as are described in LDVAL register, and to count down to zero. And then load their own start value. Each time the timer counts to zero, a trigger pulse is generated and the interrupt flag is set. All interrupts may be open or blocked (by setting the interrupt register TCTRL TIE bits). Only after the former is cleared, the new interrupt will be generated.
If desired, the timer can be read by the current value of the counter register CVAL. Turn off the timer, then a timer is started by the restart count TEN bit period.

pointer

Pointer is a special data type, not normally found in other languages. A pointer to a variable address pointer is the address of the memory cell substantially of. Depending on the type of variables referred to, may be a pointer to an integer (int *), pointer float (float *), character pointer (char *), structure pointer (struct *) and the combined pointer (union *).

void pointer type

As the name suggests, void * "No Type pointer", a pointer that is used to define a variable, it does not specify what type of data point, but it can be forced to be converted into any type of pointer. Known that if the same type of the pointer p1 and p2, it can be assigned directly to each other between p1 and p2; if p1 and p2 point to different types of data, you must use a cast operator pointer class right assignment operator
converter the type of pointer left.
【E.g】:

 float *p1; //声明 p1 为浮点型指针
int *p2; //声明 p2 为整型指针 
p1 = (float *)p2;//强制转换整型指针 p2 为浮点型指针值给 p1 赋值
 而 void *则不同,任何类型的指针都可以直接赋值给它,无需进行强制类型转

change:

void *p1; //声明 p1 无类型指针
int *p2; //声明 p2 为整型指针
p1 = p2; //用整型指针 p2 的值给 p1 直接赋值

This does not mean, void * type conversion can be assigned to other types of indicators without forcing, that p2 = p1 This statement will compile error, p1 must be cast to type "void *" type . Because "no type" can be inclusive, "typed" and "typed" is not inclusive "no type."

Structure

Structure is composed of basic data types, and the combination with an identifier of named variables. Structure can be used in different types of data.
1) defines the structure and description of the structure variables
[e.g.] defines a structure type variable named student

struct student //定义一个名为student的结构体变量类型
{ char name[8]; //成员变量“name”为字符型数组
char class[10]; //成员变量“class”为字符型数组
int age; //成员变量“age”为整型
};

Thus, if the statement s1 structure variable is a "student" type, use the following statement:
struct student s1; // declare s1 is "student" type structure variable
[], for example, define a structure variable named student type, while s1 declared as a "student" type
structure variable

struct student //定义一个名为student的结构体变量类型
{ char name[8]; //成员变量“name”为字符型数组
char class[10]; //成员变量“class”为字符型数组
int age; //成员变量“age”为整型
}s1; //声明s1为“student”类型的结构体变量

2) structure using variable
structure is a new data type, structure variable assignment operator can be like other types of variables,
except that the structure variables as a member of the basic variables.
Representation of members of the body structure:
The structure body member variable name
if. "Members of the structure variable name" as a whole, the type of data and the overall structure of the members of the
same data type, such as front as the use of talking about variables.
【E.g】:

s1.age=18; //将数据 18 赋给 s1.age(理解为学生 s1 的年龄为 18)

3) the structure pointer
structure pointer is a pointer to a pointer to a structure. Structure before it is applied to the variable name by one of the "*" operator declared.
For example, with a structure declaration structure pointer has been described above as follows:

struct student *Pstudent; //声明 Pstudent 为一个“student”类型指针

Use structure refers to access to structure members in the expression for the access structure members, and the structure variable
is different. Structure refers to a structure accessible for members expressed as:
structure pointer name - Members> structure
where "->" are two symbols "-" combination and ">", like an arrow pointing to the structure members. The above example to give a given
defined structure name and age are assigned, you can use the following statement:

strcpy(Pstudent->name,"LiuYuZhang");
Pstudent->age=18;

In fact, Pstudent-> name is (* Pstudent) .name of the short form. It is noted that a structure pointer is a pointer to a structure, i.e., the first address of the structure of the first member, and therefore should be initialized structure pointer, i.e., the assigned byte length of the spatial structure of the entire body prior to use. This function can be used to complete the following:

Pstudent=(struct student*)malloc(sizeof (struct student));
sizeof(struct student)自动求取 student 结构体的字节长度,
malloc()函数定义了一个大小为结构体长度的内存区域,然后将其地址作为结构体指针返回。

GPIO General Purpose Input Output

1, General Purpose Input

Pin data input register, the logic state can be obtained for each pin, the pin is provided digital functions corresponding port control module and a valid interrupt arranged. Asynchronous data input register pin return port control pins in the input valid and any valid after digital filter. Asynchronous input pins share the interrupt port control module and, if appropriate port for control and interrupt module asynchronously while also Failure Failure. When an input port for general-purpose function does not need, which reduces power consumption.

2, common output

Each logic state of the pin by pin data output register and output enable register control pin, the pin is configured to provide functions as a GPIO. If the PIO pin is configured as the function and the corresponding data output enable register bit is cleared, the pin is configured as an input. If the pin is configured as GPIO function and the corresponding data output enable register bit is set, then the pin is configured as an output pin and the logic state of the data output register corresponding to the same pin. In order to achieve significant bits using a general-purpose output register by writing to a single, a port in the set, clear, or trigger pin data set, the data clear pin and pin trigger data register allows one or more outputs. And a corresponding port control module does not need the interrupt status updates allow efficient pin output register and the data output pin registers (including register settings / Clear / trigger)

Universal Asynchronous Receiver / Transmitter (UART)

UART allows asynchronous serial communication with other peripheral devices and CPU.

Published 98 original articles · won praise 43 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_42352666/article/details/83317960