欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
GPIO
一、什么是GPIO?
 
GPIO,英文全稱(chēng)為General-Purpose IO ports,也就是通用IO口。嵌入式系統中常常有數量眾多,但是結構卻比較簡(jiǎn)單的外部設備/電路,對這些設備/電路有的需要CPU為之提供控制手段,有的則需要被CPU用作輸入信號。而且,許多這樣的設備/電路只要求一位,即只要有開(kāi)/關(guān)兩種狀態(tài)就夠了,比如燈亮與滅。對這些設備/電路的控制,使用傳統的串行口或并行口都不合適。所以在微控制器芯片上一般都會(huì )提供一個(gè)通用可編程IO接口,即GPIO。
 
接口至少有兩個(gè)寄存器,即通用IO控制寄存器通用IO數據寄存器。數據寄存器的各位都直接引到芯片外部,而對這種寄存器中每一位的作用,即每一位的信號流通方向,則可以通過(guò)控制寄存器中對應位獨立的加以設置。這樣,有無(wú)GPIO接口也就成為微控制器區別于微處理器的一個(gè)特征。
 
    在實(shí)際的MCU中,GPIO是有多種形式的。比如,有的數據寄存器可以按照位尋址,有些卻不能按照位尋址,這在編程時(shí)就要區分了。比如傳統的8051系列,就區分成可位尋址和不可位尋址兩種寄存器。另外,為了使用的方便,很多mcuglue logic等集成到芯片內部,增強了系統的穩定性能,比如GPIO接口除去兩個(gè)標準寄存器必須具備外,還提供上拉寄存器,可以設置IO的輸出模式是高阻,還是帶上拉的電平輸出,或者不帶上拉的電平輸出。這在電路設計中,外圍電路就可以簡(jiǎn)化不少。
  
另外需要注意的是,對于不同的計算機體系結構,設備可能是端口映射,也可能是內存映射的。如果系統結構支持獨立的IO地址空間,并且是端口映射,就必須使用匯編語(yǔ)言完成實(shí)際對設備的控制,因為C語(yǔ)言并沒(méi)有提供真正的端口的概念。如果是內存映射,那就方便的多了。
舉個(gè)例子,比如像寄存器A(地址假定為0x48000000)寫(xiě)入數據0x01,那么就可以這樣設置了。
 #define A (*(volatile unsigned long *)0x48000000)
...
    A = 0x01;
...
    這實(shí)際上就是內存映射機制的方便性了。其中volatile關(guān)鍵字是嵌入式系統開(kāi)發(fā)的一個(gè)重要特點(diǎn)。上述表達式拆開(kāi)來(lái)分析,首先(volatile unsigned long *)0x48000000的意思是把0x48000000強制轉換成volatile unsigned long類(lèi)型的指針,暫記為p,那么就是#define A *p,即AP指針指向位置的內容了。這里就是通過(guò)內存尋址訪(fǎng)問(wèn)到寄存器A,可以讀/寫(xiě)操作。
  
二、S3C2410GPIO的特點(diǎn)
   s3c2410GPIO117pin,下面應該到9 IO ports看看詳細部分了。
The S3C2410X has 117 multi-functional input/output port pins. The ports are:
— Port A (GPA): 23-output port
— Port B (GPB): 11-input/output port
— Port C (GPC): 16-input/output port
— Port D (GPD): 16-input/output port
— Port E (GPE): 16-input/output port
— Port F (GPF): 8-input/output port
— Port G (GPG): 16-input/output port
— Port H (GPH): 11-input/output port 
    這么多的IO口,其實(shí)很多是復合功能的,既可以作為普通的IO口使用,也可以作為特殊外設接口。在程序設計時(shí),要對整體的資源有所規劃,初始化時(shí)就應該把所有資源安排合理。這樣才會(huì )避免出現問(wèn)題。 
    現在的8個(gè)端口,其寄存器是相似的。除了兩個(gè)通用寄存器GPxCON、GPxDAT外,還提供了GPxUP用于確定是否使用內部上拉電阻(其中xA-H,需要注意的是沒(méi)有GPAUP)。應用的主要步驟就是: 
    ·設置GPIO控制寄存器GPxCON
    ·設置GPIO上拉寄存器GPxUP
初始化完成后,就可以通過(guò)對GPxDAT的操作來(lái)實(shí)現相應的應用了。其中,PORT APORT B-H在功能選擇方面有所不同,GPACON的每一位對應一根引腳(共23pin有效)。當某位設為0,相應引腳為輸出引腳,此時(shí)往GPADAT中寫(xiě)0/1,可以讓引腳輸出低電平/高電平;當某位設為1,則相應引腳為地址線(xiàn),或者用于地址控制,此時(shí)GPADAT沒(méi)有用了。
一般而言,GPACON通常全設為1,以便訪(fǎng)問(wèn)外部存儲器件。PORT B-H在寄存器操作方面完全相同。
GPxCON中每?jì)晌豢刂埔桓_:00表示輸入,01表示輸出,10表示特殊功能,11保留。GPxDAT用于讀/寫(xiě)引腳:當引腳設為輸入時(shí),讀此寄存器可知相應引腳狀態(tài)是高/低;當引腳設為輸出時(shí),寫(xiě)此寄存器相應位可以使相應引腳輸出低電平或高電平。GPxUP:某位設為0,相應引腳無(wú)內部上拉;為1,相應引腳使用內部上拉。關(guān)于特殊功能,那就得結合特殊外設來(lái)進(jìn)行設置了。
 
基本實(shí)驗
實(shí)驗18段數碼管顯示,共四位
 
我的開(kāi)發(fā)板上沒(méi)有多余的GPIO插頭,只好利用液晶的顯示的插口了,對應的引腳:
VD[07] 對應 GPC[815]     VD[823] 對應 GPD[015]
   四個(gè)共陰極的數碼管,選擇信號對應GPC[811]
   8段顯示數據對應GPD[07]
這樣一來(lái)就可以利用這四個(gè)數碼管顯示數字了
1)軟件架構仿照了vivi,或者Linux Kernel。其實(shí)寫(xiě)這么小的程序用不到這么麻煩,但是可以訓練這種架構,為寫(xiě)中型大型程序打好基礎。
    2)注意C語(yǔ)言下實(shí)現寄存器讀寫(xiě)的(*(volatile unsigned long *)(addr))。其實(shí)就是要掌握volatile和指針的用法。
    3)寫(xiě)c時(shí),要注意頭文件如何處理。寫(xiě)Makefile時(shí),要注意是否采用隱含規則,如果不采用,就要自己定義明確規則,就像vivi里面的Rules.make。在這里,因為只是涉及到.s的編譯不采用隱含規則,所以沒(méi)有把Rules.make單獨拿出,事實(shí)上可以單獨寫(xiě)為Rules.make,然后在Makefile后加入include Rules.make就可以了。
    4)要調用C子程序,必須分配堆??臻g。因為子程序調用時(shí),要進(jìn)行入棧出棧處理。又因為從nand flash啟動(dòng),而nand flashS3C2410下的特點(diǎn)規定堆棧不能超過(guò)4K。
文件打包

文件:
led_c.tar.gz
大小:
10KB
下載:


 
 
Using the I2C Bus 

Judging from my emails, it is quite clear that the I2C bus can be very confusing for the newcomer. I have lots of examples on using the I2C bus on the website, but many of these are using high level controllers and do not show the detail of what is actually happening on the bus. This short article therefore tries to de-mystify the I2C bus, I hope it doesn‘t have the opposite effect!

The physical I2C bus
This is just two wires, called SCL and SDA. SCL is the clock line. It is used to synchronize all data transfers over the I2C bus. SDA is the data line. The SCL & SDA lines are connected to all devices on the I2C bus. There needs to be a third wire which is just the ground or 0 volts. There may also be a 5volt wire is power is being distributed to the devices. Both SCL and SDA lines are "open drain" drivers. What this means is that the chip can drive its output low, but it cannot drive it high. For the line to be able to go high you must provide pull-up resistors to the 5v supply. There should be a resistor from the SCL line to the 5v line and another from the SDA line to the 5v line. You only need one set of pull-up resistors for the whole I2C bus, not for each device, as illustrated below:

The value of the resistors is not critical. I have seen anything from 1k8 (1800 ohms) to 47k (47000 ohms) used. 1k8, 4k7 and 10k are common values, but anything in this range should work OK. I recommend 1k8 as this gives you the best performance. If the resistors are missing, the SCL and SDA lines will always be low - nearly 0 volts - and the I2C bus will not work.

Masters and Slaves
The devices on the I2C bus are either masters or slaves. The master is always the device that drives the SCL clock line. The slaves are the devices that respond to the master. A slave cannot initiate a transfer over the I2C bus, only a master can do that. There can be, and usually are, multiple slaves on the I2C bus, however there is normally only one master. It is possible to have multiple masters, but it is unusual and not covered here. On your robot, the master will be your controller and the slaves will be our modules such as the SRF08 or CMPS03. Slaves will never initiate a transfer. Both master and slave can transfer data over the I2C bus, but that transfer is always controlled by the master.

The I2C Physical Protocol
When the master (your controller) wishes to talk to a slave (our CMPS03 for example) it begins by issuing a start sequence on the I2C bus. A start sequence is one of two special sequences defined for the I2C bus, the other being the stop sequence. The start sequence and stop sequence are special in that these are the only places where the SDA (data line) is allowed to change while the SCL (clock line) is high. When data is being transferred, SDA must remain stable and not change whilst SCL is high. The start and stop sequences mark the beginning and end of a transaction with the slave device.

Data is transferred in sequences of 8 bits. The bits are placed on the SDA line starting with the MSB (Most Significant Bit). The SCL line is then pulsed high, then low. Remember that the chip cannot really drive the line high, it simply "lets go" of it and the resistor actually pulls it high. For every 8 bits transferred, the device receiving the data sends back an acknowledge bit, so there are actually 9 SCL clock pulses to transfer each 8 bit byte of data. If the receiving device sends back a low ACK bit, then it has received the data and is ready to accept another byte. If it sends back a high then it is indicating it cannot accept any further data and the master should terminate the transfer by sending a stop sequence. 

How fast?
The standard clock (SCL) speed for I2C up to 100KHz. Philips do define faster speeds: Fast mode, which is up to 400KHz and High Speed mode which is up to 3.4MHz. All of our modules are designed to work at up to 100KHz. We have tested our modules up to 1MHz but this needs a small delay of a few uS between each byte transferred. In practical robots, we have never had any need to use high SCL speeds. Keep SCL at or below 100KHz and then forget about it.

I2C Device Addressing
All I2C addresses are either 7 bits or 10 bits. The use of 10 bit addresses is rare and is not covered here. All of our modules and the common chips you will use will have 7 bit addresses. This means that you can have up to 128 devices on the I2C bus, since a 7bit number can be from 0 to 127. When sending out the 7 bit address, we still always send 8 bits. The extra bit is used to inform the slave if the master is  writing to it or reading from it. If the bit is zero are master is writing to the slave. If the bit is 1 the master is reading from the slave. The 7 bit address is placed in the upper 7 bits of the byte and the Read/Write (R/W) bit is in the LSB (Least Significant Bit).

The placement of the 7 bit address in the upper 7 bits of the byte is a source of confusion for the newcomer. It means that to write to address 21, you must actually send out 42 which is 21 moved over by 1 bit. It is probably easier to think of the I2C bus addresses as 8 bit addresses, with even addresses as write only, and the odd addresses as the read address for the same device. To take our CMPS03 for example, this is at address 0xC0 ($C0). You would uses 0xC0 to write to the CMPS03 and 0xC1 to read from it. So the read/write bit just makes it an odd/even address. 

The I2C Software Protocol
The first thing that will happen is that the master will send out a start sequence. This will alert all the slave devices on the bus that a transaction is starting and they should listen in incase it is for them. Next the master will send out the device address. The slave that matches this address will continue with the transaction, any others will ignore the rest of this transaction and wait for the next. Having addressed the slave device the master must now send out the internal location or register number inside the slave that it wishes to write to or read from. This number is obviously dependant on what the slave actually is and how many internal registers it has. Some very simple devices do not have any, but most do, including all of our modules. Our CMPS03 has 16 locations numbered 0-15. The SRF08 has 36. Having sent the I2C address and the internal register address  the master can now send the data byte (or bytes, it doesn‘t have to be just one). The master can continue to send data bytes to the slave and these will normally be placed in the following registers because the slave will automatically increment the internal register address after each byte. When the master has finished writing all data to the slave, it sends a stop sequence which completes the transaction. So to write to a slave device: 
1. Send a start sequence
2. Send the I2C address of the slave with the R/W bit low (even address)
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.

As an example, you have an SRF08 at the factory default address of 0xE0. To start the SRF08 ranging you would write 0x51 to the command register at 0x00 like this:
1. Send a start sequence
2. Send 0xE0 ( I2C address of the SRF08 with the R/W bit low (even address)
3. Send 0x00 (Internal address of the command register)
4. Send 0x51 (The command to start the SRF08 ranging)
5. Send the stop sequence.

Reading from the Slave
This is a little more complicated - but not too much more. Before reading data from the slave device, you must tell it which of its internal addresses you want to read. So a read of the slave actually starts off by writing to it. This is the same as when you want to write to it: You send the start sequence, the I2C address of the slave with the R/W bit low (even address) and the internal register number you want to write to. Now you send another start sequence (sometimes called a restart) and the I2C address again - this time with the read bit set. You then read as many data bytes as you wish and terminate the transaction with a stop sequence. So to read the compass bearing as a byte from the CMPS03 module:
1. Send a start sequence
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.

The bit sequence will look like this:

Wait a moment
That‘s almost it for simple I2C communications, but there is one more complication. When the master is reading from the slave, its the slave that places the data on the SDA line, but its the master that controls the clock. What if the slave is not ready to send the data! With devices such as EEPROMs this is not a problem, but when the slave device is actually a microprocessor with other things to do, it can be a problem. The microprocessor on the slave device will need to go to an interrupt routine, save its working registers, find out what address the master wants to read from, get the data and place it in its transmission register. This can take many uS to happen, meanwhile the master is blissfully sending out clock pulses on the SCL line that the slave cannot respond to. The I2C protocol provides a solution to this: the slave is allowed to hold the SCL line low! This is called clock stretching. When the slave gets the read command from the master it holds the clock line low. The microprocessor then gets the requested data, places it in the transmission register and releases the clock line allowing the pull-up resistor to finally pull it high. From the masters point of view, it will issue the first clock pulse of the read by making SCL high and then check to see if it really has gone high. If its still low then its the slave that holding it low and the master should wait until it goes high before continuing. Luckily the hardware I2C ports on most microprocessors will handle this automatically.

Sometimes however, the master I2C is just a collection of subroutines and there are a few implementations out there that completely ignore clock stretching. They work with things like EEPROM‘s but not with microprocessor slaves that use clock stretching. The result is that erroneous data is read from the slave. Beware!

Example Master Code
This example shows how to implement a software I2C master, including clock stretching. It is written in C for the PIC processor, but should be applicable to most processors with minor changes to the I/O pin definitions. It is suitable for controlling all of our I2C based robot modules. Since the SCL and SDA lines are open drain type, we use the tristate control register to control the output, keeping the output register low. The port pins still need to be read though, so they‘re defined as SCL_IN and SDA_IN. This definition and the initialization is probably all you‘ll need to change for a different processor.

#define SCL     TRISB4 // I2C bus
#define SDA     TRISB1 //
#define SCL_IN  RB4    //
#define SDA_IN  RB1    //

To initialize the ports set the output resisters to 0 and the tristate registers to 1 which disables the outputs and allows them to be pulled high by the resistors.
SDA = SCL = 1;
SCL_IN = SDA_IN = 0;

We use a small delay routine between SDA and SCL changes to give a clear sequence on the I2C bus. This is nothing more than a subroutine call and return.
void i2c_dly(void)
{
}

The following 4 functions provide the primitive start, stop, read and write sequences. All I2C transactions can be built up from these.
void i2c_start(void)
{
  SDA = 1;             // i2c start bit sequence
  i2c_dly();
  SCL = 1;
  i2c_dly();
  SDA = 0;
  i2c_dly();
  SCL = 0;
  i2c_dly();
}

void i2c_stop(void)
{
  SDA = 0;             // i2c stop bit sequence
  i2c_dly();
  SCL = 1;
  i2c_dly();
  SDA = 1;
  i2c_dly();
}

unsigned char i2c_rx(char ack)
{
char x, d=0;
  SDA = 1; 
  for(x=0; x<8; x++) {
    d <<= 1;
    do {
      SCL = 1;
    }
    while(SCL_IN==0);    // wait for any SCL clock stretching
    i2c_dly();
    if(SDA_IN) d |= 1;
    SCL = 0;
  } 
  if(ack) SDA = 0;
  else SDA = 1;
  SCL = 1;
  i2c_dly();             // send (N)ACK bit
  SCL = 0;
  SDA = 1;
  return d;
}

bit i2c_tx(unsigned char d)
{
char x;
static bit b;
  for(x=8; x; x--) {
    if(d&0x80) SDA = 1;
    else SDA = 0;
    SCL = 1;
    d <<= 1;
    SCL = 0;
  }
  SDA = 1;
  SCL = 1;
  i2c_dly();
  b = SDA_IN;          // possible ACK bit
  SCL = 0;
  return b;
}

The 4 primitive functions above can easily be put together to form complete I2C transactions. Here‘s and example to start an SRF08 ranging in cm:

i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear

i2c_tx(0x00);             // SRF08 command register address
i2c_tx(0x51);             // command to start ranging in cm
i2c_stop();               // send stop sequence

Now after waiting 65mS for the ranging to complete (I‘ve left that to you) the following example shows how to read the light sensor value from register 1 and the range result from registers 2 & 3.

i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear

i2c_tx(0x01);             // SRF08 light sensor register address
i2c_start();              // send a restart sequence
i2c_tx(0xE1);             // SRF08 I2C address with R/W bit set

lightsensor = i2c_rx(1);  // get light sensor and send acknowledge. Internal register address will increment automatically.
rangehigh = i2c_rx(1);    // get the high byte of the range and send acknowledge.
rangelow = i2c_rx(0);     // get low byte of the range - note we don‘t acknowledge the last byte.
i2c_stop();               // send stop sequence

Easy isn‘t it?

The definitive specs on the I2C bus can be found on the Philips website. It currently here but if its moved you‘ll find it easily be googleing on "i2c bus specification".
 
 
 

基于I2C總線(xiàn)的處理器聯(lián)網(wǎng)設計

上網(wǎng)時(shí)間:2008年07月24日 加入個(gè)人信息中心收藏夾 收藏 打印版 推薦給同仁 發(fā)送查詢(xún)
隨著(zhù)微控制器的價(jià)格越來(lái)越低,功能越來(lái)越強大,電氣設計人員發(fā)現在單板和多板系統中都使用多個(gè)小型控制器是一種更加經(jīng)濟高效的方法。這種輔助處理器能夠減輕主處理器在耗時(shí)任務(wù)上面的處理開(kāi)銷(xiāo),例如掃描鍵盤(pán)、顯示控制器和電機控制。這些控制器也可以配置為各種各樣的專(zhuān)用外設。

最近,我接受了一項任務(wù):開(kāi)發(fā)一種能夠方便地適用于多種應用的接口(軟/硬件),且要符合嵌入式處理器中常用的行業(yè)標準。在分析了一些典型應用之后,我們列出了一些針對該硬件接口的設計需求:常用于32位和8位處理器;能夠得到常用外設器件的支持;外設接口代碼量低于0.5kB;引腳數量少;數據帶寬可達10kBps;RAM用量少;一條總線(xiàn)上支持多種外設;方便使用API;不需要外部接口驅動(dòng)硬件。

由于要求引腳數量少,所以必須采用串行接口。目前處理器中常見(jiàn)的串行接口包括SPI、I2C、USB和RS-232。通過(guò)從不同方面權衡比較這些接口,我最終選擇了I2C,因為它接口簡(jiǎn)單,靈活性好,得到了大多數低成本控制器的支持。在不需要很高傳輸速度的情況下,較少的引腳數和流量控制功能還使得I2C接口相比SPI接口具有更大的優(yōu)勢。

I2C的工作原理

I2C是一種雙線(xiàn)雙向接口,包括一個(gè)時(shí)鐘信號和一個(gè)數據信號(SCL和SDA)。在不增加任何其他信號的情況下,一條I2C總線(xiàn)就可以支持多達12個(gè)設備。I2C接口規范包括三種工作速度:100kbps、400kbps和3.4Mbps。大多數常見(jiàn)的控制器只支持100-和400kbps兩種模式。I2C總線(xiàn)支持一個(gè)主設備多個(gè)從設備,或者多個(gè)主設備的配置結構。

I2C一個(gè)非常重要的特性就是它支持流量控制。如果某個(gè)從設備無(wú)法保持連續的字節傳輸,它可以將總線(xiàn)掛起,直到能夠跟上主設備的傳輸速度。這對于包含最小規模的I2C硬件并且必須在固件上支持部分傳輸協(xié)議的從設備來(lái)說(shuō)是非常有用的。I2C總線(xiàn)規范支持7b和10b兩種尋址協(xié)議。我發(fā)現7b尋址模式在大部分應用中的效率更高。

在開(kāi)始編寫(xiě)代碼之前,我們需要很好地了解I2C總線(xiàn)的工作原理。任何情況下I2C總線(xiàn)至少要包含一個(gè)主設備,至少要掛有一個(gè)或多個(gè)從設備。主設備總是由主到從發(fā)起數據傳輸操作。無(wú)論有多少個(gè)外設掛接在總線(xiàn)上,I2C接口只有兩個(gè)信號。

兩個(gè)信號都是集電極開(kāi)路的,通過(guò)大小為2.7k左右的上拉電阻接Vcc電源。SDA信號是雙向的,可以由主設備或從設備驅動(dòng)。SCL信號是由主設備驅動(dòng)的,但是在一個(gè)數據字節的末尾從設備必須保持SCL信號為低,以延遲總線(xiàn)直到從設備開(kāi)始處理數據。主設備在數據字節的最后一位傳輸完之后釋放SCL信號,然后檢查SCL信號是否變高。如果SCL沒(méi)有變高,那么主設備認為從設備正在請求主設備延遲,直到其開(kāi)始處理數據。

當通過(guò)I2C總線(xiàn)發(fā)送數據時(shí),只有當SCL為低電平時(shí)才能進(jìn)行數據變換。當SCL信號為高時(shí),任何方向的數據都應該是穩定的(如圖1所示)。

基于I<sup>2</sup>C總線(xiàn)的處理器聯(lián)網(wǎng)設計

當總線(xiàn)空閑時(shí),主設備和從設備都不下拉SDA和SCL信號。在發(fā)起一次數據傳輸時(shí),主設備驅動(dòng)SDA信號從高電平變成低電平,同時(shí)SCL信號為高。一般地,當SCL信號為高電平時(shí),SDA信號的狀態(tài)保持不變,但啟動(dòng)或停止條件下除外。當SCL信號為高并且SDA信號從低變高時(shí),是傳輸停止的情況(如圖2所示)。

基于I<sup>2</sup>C總線(xiàn)的處理器聯(lián)網(wǎng)設計

I2C總線(xiàn)以8b為單位傳輸數據。每傳輸一個(gè)字節時(shí),必須得到數據接收方的確認。所有的數據都是從MSB(最高有效位)開(kāi)始傳輸的。

 
 
 
 
 
 
 采樣率類(lèi)似于動(dòng)態(tài)影像的幀數,比如電影的采樣率是24赫茲,PAL制式的采樣率是25赫茲,NTSC制式的采樣率是30赫茲。當我們把采樣到的一個(gè)個(gè)靜止畫(huà)面再以采樣率同樣的速度回放時(shí),看到的就是連續的畫(huà)面。同樣的道理,把以44.1kHZ采樣率記錄的CD以同樣的速率播放時(shí),就能聽(tīng)到連續的聲音。顯然,這個(gè)采樣率越高,聽(tīng)到的聲音和看到的圖像就越連貫。當然,人的聽(tīng)覺(jué)和視覺(jué)器官能分辨的采樣率是有限的,基本上高于44.1kHZ采樣的聲音,絕大部分人已經(jīng)覺(jué)察不到其中的分別了。
而聲音的位數就相當于畫(huà)面的顏色數,表示每個(gè)取樣的數據量,當然數據量越大,回放的聲音越準確,不至于把開(kāi)水壺的叫聲和火車(chē)的鳴笛混淆。同樣的道理,對于畫(huà)面來(lái)說(shuō)就是更清晰和準確,不至于把血和西紅柿醬混淆。不過(guò)受人的器官的機能限制,16位的聲音和24位的畫(huà)面基本已經(jīng)是普通人類(lèi)的極限了,更高位數就只能靠?jì)x器才能分辨出來(lái)了。比如電話(huà)就是3kHZ取樣的7位聲音,而CD是44.1kHZ取樣的16位聲音,所以CD就比電話(huà)更清楚。
當你理解了以上這兩個(gè)概念,比特率就很容易理解了。以電話(huà)為例,每秒3000次取樣,每個(gè)取樣是7比特,那么電話(huà)的比特率是21000。而CD是每秒44100次取樣,兩個(gè)聲道,每個(gè)取樣是16比特,所以CD的比特率是44100*2*16=1411200,也就是說(shuō)CD每秒的數據量大約是172KB,而一張CD的容量是74分等于4440秒,就是763680KB=745MB。
等等,一張CD的容量應該是640MB,那就是說(shuō)前邊的44.1kHZ取樣率和16位精度這兩個(gè)數據中至少有一個(gè)不準確。 第一個(gè)得745M是正確的,變成640M是因為cd音源寫(xiě)入碟片采用了PCM預測編碼,編碼的目的就是壓縮,但是壓縮很小,失真就小,所以說(shuō)cd格式幾乎是未壓縮的。
 
 
 
什么是數據采集?
簡(jiǎn)介
 
     在計算機廣泛應用的今天,數據采集的重要性是十分顯著(zhù)的。它是計算機與外部物理世界連接的橋梁。各種類(lèi)型信號采集的難易程度差別很大。實(shí)際采集時(shí),噪聲也可能帶來(lái)一些麻煩。數據采集時(shí),有一些基本原理要注意,還有更多的實(shí)際的問(wèn)題要解決。
采樣頻率、抗混疊濾波器和樣本數
 
     假設現在對一個(gè)模擬信號 x(t) 每隔Δ t 時(shí)間采樣一次。時(shí)間間隔Δ t 被稱(chēng)為采樣間隔或者采樣周期。它的倒數 1/ Δ t 被稱(chēng)為采樣頻率,單位是采樣數 / 每秒。 t=0, Δ t ,2 Δ t ,3 Δ t …… 等等, x(t) 的數值就被稱(chēng)為采樣值。所有 x(0),x( Δ t),x(2 Δ t ) 都是采樣值。這樣信號 x(t) 可以用一組分散的采樣值來(lái)表示: 下圖顯示了一個(gè)模擬信號和它采樣后的采樣值。采樣間隔是Δ t ,注意,采樣點(diǎn)在時(shí)域上是分散的。
 
圖 1 模擬信號和采樣顯示
如果對信號 x(t) 采集 N 個(gè)采樣點(diǎn),那么 x(t) 就可以用下面這個(gè)數列表示:
這個(gè)數列被稱(chēng)為信號 x(t) 的數字化顯示或者采樣顯示。注意這個(gè)數列中僅僅用下標變量編制索引,而不含有任何關(guān)于采樣率(或Δ t )的信息。所以如果只知道該信號的采樣值,并不能知道它的采樣率,缺少了時(shí)間尺度,也不可能知道信號 x(t) 的頻率。
根據采樣定理,最低采樣頻率必須是信號頻率的兩倍。反過(guò)來(lái)說(shuō),如果給定了采樣頻率,那么能夠正確顯示信號而不發(fā)生畸變的最大頻率叫做恩奎斯特頻率,它是采樣頻率的一半。如果信號中包含頻率高于奈奎斯特頻率的成分,信號將在直流和恩奎斯特頻率之間畸變。 圖2顯示了一個(gè)信號分別用合適的采樣率和過(guò)低的采樣率進(jìn)行采樣的結果。
采樣率過(guò)低的結果是還原的信號的頻率看上去與原始信號不同。這種信號畸變叫做混疊( alias )。 出現的混頻偏差( alias frequency )是輸入信號的頻率和最靠近的采樣率整數倍的差的絕對值。
圖 2 不同采樣率的采樣結果
圖3給出了一個(gè)例子。假設采樣頻率 fs 是 100HZ, ,信號中含有 25 、 70 、 160 、和 510 Hz 的成分。
圖3 說(shuō)明混疊的例子
采樣的結果將會(huì )是低于奈奎斯特頻率( fs/2=50 Hz )的信號可以被正確采樣。而頻率高于 50HZ 的信號成分采樣時(shí)會(huì )發(fā)生畸變。分別產(chǎn)生了 30 、 40 和 10 Hz 的畸變頻率 F2 、 F3 和 F4 。計算混頻偏差的公式是:
混頻偏差= ABS (采樣頻率的最近整數倍-輸入頻率)
其中 ABS 表示“絕對值”,例如:
混頻偏差 F2 = |100 – 70| = 30 Hz
混頻偏差 F3 = |(2)100 – 160| = 40 Hz
混頻偏差 F4 = |(5)100 – 510| = 10 Hz
  為了避免這種情況的發(fā)生,通常在信號被采集( A/D )之前,經(jīng)過(guò)一個(gè)低通濾波器,將信號中高于奈奎斯特頻率的信號成分濾去。在圖3的例子中,這個(gè)濾波器的截止頻率自然是 25HZ 。這個(gè)濾波器稱(chēng)為 抗混疊濾波器
采樣頻率應當怎樣設置呢?也許你可能會(huì )首先考慮用采集卡支持的最大頻率。但是,較長(cháng)時(shí)間使用很高的采樣率可能會(huì )導致沒(méi)有足夠的內存或者硬盤(pán)存儲數據太慢。理論上設置采樣頻率為被采集信號最高頻率成分的2倍就夠了,實(shí)際上工程中選用5~10倍,有時(shí)為了較好地還原波形,甚至更高一些。
通常,信號采集后都要去做適當的信號處理,例如 FFT 等。這里對樣本數又有一個(gè)要求,一般不能只提供一個(gè)信號周期的數據樣本,希望有5~10個(gè)周期,甚至更多的樣本。并且希望所提供的樣本總數是整周期個(gè)數的。這里又發(fā)生一個(gè)困難,有時(shí)我們并不知道,或不確切知道被采信號的頻率,因此不但采樣率不一定是信號頻率的整倍數,也不能保證提供整周期數的樣本。我們所有的僅僅是一個(gè)時(shí)間序列的離散的函數 x(n) 和采樣頻率。這是我們測量與分析的唯一依據。
數據采集系統的構成
 

圖4  數據采集系統結構
上圖表示了數據采集的結構。在數據采集之前,程序將對采集板卡初始化,板卡上和內存中的 Buffer 是數據采集存儲的中間環(huán)節。需要注意的兩個(gè)問(wèn)題是:是否使用 Buffer ?是否使用外觸發(fā)啟動(dòng)、停止或同步一個(gè)操作。

 
 
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
i2c- sda掛死分析
I2C詳解
I2C總線(xiàn)傳輸協(xié)議
I2C問(wèn)題的七宗罪
GPIO模擬I2C操作調試注意事項
對I2C總線(xiàn)時(shí)序的一點(diǎn)理解以及ACK和NACK(NAK)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久