




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、INTRODUCTION TO MICROCONTROLLERSWhat are microc on trollers? They are what their n ame suggests. Today they can be found in almost any complex electr onic device -from portable music devices to wash ing machi nes to your car. They are programmable, cheap, small, can han dle abuse, require almost zer
2、o power, and there are so many variaties to suit every n eed. This is what makes them so useful for robotics - they are like tiny affordable computers that you can put right onto your robot.Augme nted Microc on trollers and Developme nt Boards In a pure sense, a microcontroller is just an IC (integr
3、ated circuit, or a black chip thi ng with pi ns coming out of it. However it is very com mon to add additi onal exter nal comp onen ts, such as a voltage regulator, capacitors, LEDs, motor driver, tim ing crystals, rs232, etc to the basic IC. Formally, this is called an augmented microcontroller. Bu
4、t in reality, most people just say microcontroller even if it has augmentation. Other abbreviati ons would be uncon troller and MicroCo ntroller Unit (MCU. Usually when I say microcontroller what I really mean to say is augme nted microc on troller.As a begi nner it is probably best to buy an augme
5、nted microc on troller. Why? Well because they have tons of goodies built onto them that are all assembled and debugged for you. They also ofte n come with tech support, sample code, and a com mun ity of people to help you with them. My microc on troller parts list shows the more popular types that
6、you can buy. They tend to cost from $30 to $150 depending on the features. This will give you a good in troductory to microc on troller program ming without hav ing to be concerned with all the tech ni cal stuff.In the long term however you should build your own augme nted microc on troller so that
7、you may un dersta nd them better. The adva ntage to making your own is that it will probably cost you from $10-$30.Between getting a full augmented board and doing it yourself is somethi ng called a developme nt board. These boards come pre- augme nted with just the bare basics to get you started. T
8、hey are desig ned for prototyp ing and test ing of new ideas very quickly. They typically cost between $15 and $40.What comes with the IC? There is a huge variety of microcontrollers out on the market, but I will go over a few com mon features that you will find useful for your robotics project.For
9、robots, ore importa nt tha n any other feature on a microco ntroller, is the I/O ports. In put ports are used for taking in sen sor data, while output is used for sending comma nds to exter nal hardware such as servos. There are two types of I/O ports, an alog and digital.An alog In put PortsAn alog
10、 Ports are n ecessary to connect sen sorsto your robot. Also known as an an alog to digital conv erter (ADC, they recieve analog signals and convert them to a digital number within a certain numerical range.So what is an alog? An alog is a con ti nu ous voltage range and is typically found with sen
11、sors. However computers can only operate in the digital realm with 0s and 1s. So how does a microc on troller convert an an alog sig nal to a digital sig nal?First, the analog is measured after a predefined period of time passes. At each time period, the voltage is recorded as a nu mber. This nu mbe
12、r the n defi nes a sig nal of 0s and 1s as show n:怕呻巾屮0訓010巾100|0訓1阿1D10 IDOODIO 00叫00叫5片亦申Tl:jllllllLUil III 1The adva ntage of digital over an alog is that digital is much better at elim in at ing backgro und no ise. Cell phones are all digital today, and although the digital sig nal is less repre
13、sentative than an analog signal, it is much less likely to degrade since computers can restore damaged digital sig nals. This allows for a clearer output sig nal to talk to your mom or whoever. MP3s are all digital too, usually encoded at 128 kbps. Higher bit rates obviously mean higher quality beca
14、use they better represe nt the an alog sig nal. But higher bit rates also require more memory and process ing power.Most microcontrollers today are8 bit , meaning they have arange of 256 (2A8=256. There are a few that are 10 bit, 12 bit, and eve n 32 bit, but as you in crease precisi on you also n e
15、ed a much faster processor.What does this bit stuff mean for ADC? For example, suppose a sen sor reads 0V to an 8 bit ADC. This would give you a digital ouput of 0. 5V would be 255. Now suppose a sen sor gave an output of 2.9V, what would the ADC output be?Doi ng the math:1482.9V/5V = X/255 X = 2.9*
16、255/5 =So how do you use an analog port? First make sure your sensor output does not exceed your digital logic voltage (usually 0V - 5V. Then plug that output directly to the analog port.This bit range could also be seen as a resolution. Higher resolutions mean higher accuracy, but occasionally can
17、mean slower processing and more succeptability to noise. For example, suppose you had a 3 bit con troller which has a range of 2A3=8.Then you have a distance sensor that outputed a number 0-7 (a total of 8 that represents the distance between your robot and the wall. If your sensor can see only 8 fe
18、et, then you get a resolution of 1 bit per foot (8 resolution / 8 feet = 1. But then suppose you have an 8 bit controller, you would get 256/8=32 1 bit per centimeter - way more accurate and useful! With the 3 bit controller, you could not tell the difference between 1 inch and 11 inches.Digital I/O
19、 Ports Digital ports are like analog ports, but with only 1 bit (2A1=2 hence a resolution of 2 - on and off.Digital ports obviously for that reason are rarely used for sensors, except for maybe on/off switches . . . What they are mostly used for is signal output. You can use them to control motors o
20、r leds or just about anything. Send a high 5V signal to turn something on, or a low 0V to turn something off. Or if you want to have an LED at only half brightness, or a motor at half speed, send a square wave. Square waves are like turning something on and off so fast that its almost like sending o
21、ut an analog voltage of your choice. Neat, huh?This is an example of a square wave for PWM:v+Ovv averV+OvV+OvThese squarewaves are called PWM, short for pulse width modulation. They are most often used for controlling servos or DC motor H-Bridges.Also a quick side no te, an alog ports can be used as
22、 digital ports.Serial Com mun icatio n, RS232, UART A serial conn ecti on on your microc on troller is very useful for com muni cati on. You can use it to program your con troller from a computer, use it to output data from your con troller to your computer (great for debugg in g, or eve n use it to
23、 operate other electr onics such as digital video cameras. Usually the microc on troller would require an exter nal IC to han dle everyth ing, such as an RS232.Timers A timer is the method by which the microcontroller measures the passing of time - such as for a clock, sonar, a pause/wait comma nd,
24、timer in terrupts, etc.Motor Driver To run a DC motor you need to either have an H- Bridge or a Motor Driver IC. The IC is great for small robots that do not exceed 1 or 2 amps per motor and the rated motor voltage is not higher tha n about 12V. The homemade H-Bridge would n eed to be used if you wa
25、n ted to exceed those specs.There are a few H-Bridge con trollers commercially available to buy, but usually they are way too expe nsive and are desig nedfor battlebot type robots. The IC is small, very cheap, and can usually handle two motors. I highly recommend opting for the IC. Also, do not forg
26、et to put a heatsink onto the motordriver. Motordrivers give off pretty fireworks when they explode from overheating =Another interesting note, you can stack ICs in parallel to double the allowable current and heat dissipation.Theoretically you can stack as many as you want, as long as the current i
27、s high enough to still operate the logic of the IC. This works for voltage regulators too.Output Indicators Im referring to anything that can be used for debugging by communicating information to you. LEDs, buzzers, LCD screens, anything that gives output. The better the indicator, the easier the de
28、bugging. The best indicator is to have your robot tethered and print or data log sensor and action data to your computer, but it isnt always possible to have your robot tethered.Programming Languages The lowest form of programming languages is the machine language. Microcontrollers need to be progra
29、mmed with this.These higher languages would then be compiled automatically into a machine language, which then you can upload into your robot. Probably the easiest language to learn would be BASIC, with a name true to itself. The BASIC Stamp microcontroller uses that language. But BASIC has its limi
30、tations, so if you have any programming experience at all, I recommend you program in C. This language was the precurser to C+, so if you can already program in C+, it should be really simple for you to learn. What complicates this is that there is no standard to programming microcontrollers. Each h
31、as its own features, its own language, its own compiler, and its own uploading to the controller method.This is why I do not go into too much detail because there are too many options out there to talk about. The support documents that come with the controllers should answer your specificquestions.
32、Also, if you decide to use a PIC, understand that the compiler program (at least the good ones can cost hundred of dollars. Most microcontrollers also require a special interface device between your computer and the chip for programming which could also cost from $10-$40.Costs With possibly the exce
33、ption of DC motors, the microcontroller is the most expensive part of your robot. There is just no escaping the costs, especially for the beginner. But remember, after buying all this for your first robot, you do not need to buy any of it again as you can reuse everything. So here is the breakdown o
34、f costs. The chip itself, without augmentation, would only cost dollars. But understand the chip is useless without the augmentation, so you would need to do it yourself if you do not buy it already augmented. This could potentially cost just as much with the augmentation, and could cause you many f
35、rustrations.If however you are more experienced (and for some odd reason still reading this, you can customize your own circuit to do exactly what you want. Why have a motordriver when you are only using servos anyway? If you decide to buy an augmented MCU, the cost will range from about $50-$150. T
36、o compile your program, you would need to get special compiling software. Atmel and BASIC Stamps have free compilers. PICs however have fairly expensive compilers. There are some free ones available online, but they are of poor quality in my opinion. CCSC PIC C compiler is about $125, but I think it
37、 is worth getting if you are going to use PICs.You will also need an uploader to transfer the program from your computer to the chip. This generally requires more special software and a special interface device. The Cerebellum PIC based controller has this built in which is really nice and convienen
38、t, but for any others expect to spend from $10-$40. People often opt to just make their own as the circuit isnt too complicated.,IAs a prototyper, what you probably want most is a MCU developme nt board. These augme nted microc on trollers are desig ned for the prototyper in mind. To find these augm
39、e nted MCUs, do a search for pic development board, atmel developme nt board, stamp developme nt board, etc.單片機的介紹什么是單片機?正如它們的名字所說的那樣。今天,它們可以被發(fā)現(xiàn)幾乎在任 何復(fù)雜電子設(shè)備中-比如用便攜式音樂設(shè)備來洗你車上的機械裝置。他們是可編程、便宜、微小,可以處理濫用,基本不需要消耗多少能量,現(xiàn)在已經(jīng)有如此多 的種類來適應(yīng)每一個需要。這對于機器人來說非常有益-像小的可以負擔一切任務(wù)的計算機,你可以把命令分配給你的機器人。不斷發(fā)展的微控制器及其發(fā)展格局在一個純粹意義上,
40、它是一個微控制器ICv集成電路,或者帶有引腳的黑色芯 片)。然而它很容易添加更多的外部組件,如電壓調(diào)節(jié),電容丄ED,汽車司機、時 間晶體、RS232等基本IC o形式上,這被稱作加強型微控制器。但在現(xiàn)實中,大部分人還是稱其為微控制器即使其增加了不少附件。其他簡稱將其稱為不受控制的和微控制器單元(MCU通常,我所說的微控制器,我的意思是說增強型 微控制器。作為一個初學者可能最佳的就是購買加強微控制器。為什么呢?因為他們擁有非常吸引人的設(shè)計并且可以裝配組合和調(diào)試后為你服務(wù)。他們還常常與高科技提供技術(shù)支持,樣本代碼和大量社會上的人會來協(xié)助你做好這些。我國微控制器領(lǐng)域展示了更多流行機型你都可以買到。根
41、據(jù)不同的特點,他們的費用往往 從30美元到150美元不等。這將給你一個很好的介紹,單片機編程不必與所有 技術(shù)有關(guān)的東西聯(lián)系。從長遠看來你應(yīng)該建立你自己的微控制器廠以便于你可以更好的理解它們。去 創(chuàng)造自己的優(yōu)勢,前提是它可能會花你 10-30美元。在得到一個完整的增廣板和自己不斷完善它之間我們稱其為一個發(fā)展空間。 這些增廣板在完善之前僅僅是一些后續(xù)工作的基礎(chǔ)。它們是被設(shè)計為原型的測 試并且這種新思想傳播的非常迅速。它們具有代表性的成本在15美元和40美元之間。什么是IC ?有一個巨大的多種微控制器的市場,但我要仔細檢查幾個常見的功能,這樣你會 發(fā)現(xiàn)對你的機器人有用的項目。對機器人而言,時間是比其
42、他任何都要重要的一個特征 ,是一個單片機的I / O 端口。輸入端是用來考慮在傳感器的數(shù)據(jù) ,而輸出是用來發(fā)送指令到外部硬件, 如伺服系統(tǒng)。有兩種類型的I / O 端口 ,模擬的和數(shù)字的。模擬輸入端口模擬端口需要連接傳感器和你的機器人。也被稱為一個模擬/數(shù)字轉(zhuǎn)換器(ADC,他們接收模擬信號并把它們轉(zhuǎn)化成一個數(shù)字號碼在一定數(shù)值的范圍。那么什么是模擬信號呢?模擬信號是一個在一定范圍內(nèi)連續(xù)變化的電壓 ,為 一些典型的傳感器所共有。然而計算機僅能運作的數(shù)字領(lǐng)域僅有 0和1。那么, 單片機怎么控制一種模擬信號轉(zhuǎn)換為數(shù)字信號呢 ?首先,模擬測量一段時間后傳遞的一個預(yù)定義數(shù)據(jù)。在每個時間段內(nèi),電壓記錄成一個
43、數(shù)字。這個號碼然后定義了信號的 0和1的如圖所示:MllllBIIII 111 II數(shù)字信號較模擬信號的優(yōu)勢是,數(shù)字數(shù)字在消除背景噪音方面更有優(yōu)勢。手 機逐漸數(shù)字化的今天,雖然這個數(shù)字信號是一種比模擬信號沒有多少代表性的信 號,但是也不能降低其作用因為計算機可以恢復(fù)損壞的數(shù)字信號。這允許一個清 晰的輸出信號與你的操作管理器或者其他裝置。 MP3的,通常都是數(shù)位也在128 kbps編碼。高比特率明顯意味著更高的質(zhì)量,因為他們更好地代表了模擬信號。 但更高的比特率也需要更多的內(nèi)存和處理能力。現(xiàn)在的微控制器大多數(shù)都是八位的,這意味著他們會在0256這個范圍波動(2 A 8 = 256 。有一些是10
44、位,12位,甚至是32位,但是當你需要增加精密度時你也需要一個更快的處理器。這些字節(jié)意味著ADC的什么呢?例如,假設(shè)一個傳感器讀到一個 8位ADC 0V 這將給你一個數(shù)字輸出0。5伏的將是255。現(xiàn)在,假設(shè)一個傳感器給一種輸出 2.9伏特,ADC的輸出會是什么呢?這道數(shù)學題計算如下:2.9V / 5V = X / 255255/5 X = 2.9 * = 148因此你應(yīng)該怎么使用模擬端口呢?首先確保你的傳感器輸出不超過你的數(shù)字 邏輯電壓范圍(通常0V- 5伏。然后插頭,輸出直接插入模擬端口。這個位的范圍也可以被看作是一個分辨率。更高的分辨率意味著更高的精 度,但偶爾也意味著更多的是處理緩慢和較
45、強的抗噪能力。例如,假設(shè)你有一個3位控制器,其中有一個范圍為2八3 = 8 。那么你有一個距離感應(yīng)器,輸出一個 數(shù)字0 - 7( 一共有8,代表你的機器人與墻之間的距離。如果你的傳感器只能看到8英尺,然后得到分辨率為1比特每英尺(8 / 8英尺的分辨率=1。但后來假設(shè)你有一個八位元的控制器,你將會得到256/8 = 32 1比特/厘M這種方法更加準確和有用!用一個3位的控制器,你分辨不出1英寸和11英寸。數(shù)字I / O 口就像模擬端口數(shù)字端口,但只有1比特(2 A 1 = 2分辨率為2的開關(guān)。因 為這個原因,數(shù)字端口顯然很少用于傳感器,或許除了開/關(guān)轉(zhuǎn)換他們大多數(shù)主 要用于信號的輸出。你可以用它們來控制馬達或者led或任何事。發(fā)出一個高于5V的信號,或者低于0V時關(guān)閉某些東西?;蛘撸绻阆霌碛幸粋€LED半 的亮度,或者發(fā)動機處于半速,送出一個方波。這些方波就像控制開關(guān)變換地如 此之快,它幾乎像為你的選擇發(fā)出一種模擬電壓。沒有干擾的信號,嗯?這是一種典型的方波為PWM:Bridges或直流電機。附注一點,也可以作為模擬端口和數(shù)字端口RS232、UART串行通信|_在你的單片機串行連接進行交流溝通是非常有用的!你可以用它來操縱你的控制器,使用它從電腦控制器輸出數(shù)據(jù)從你的計算機(大膽的調(diào)試,或者甚
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 舞蹈藝術(shù)價值評估-深度研究
- 2025年農(nóng)村自建住房買賣合同協(xié)議
- 倉儲物流機器人應(yīng)用-深度研究
- 物流配送節(jié)能減排技術(shù)-深度研究
- 索引策略自適應(yīng)研究-深度研究
- 2025年企業(yè)內(nèi)部承包管理合同
- 防火墻虛擬化性能評估-深度研究
- 2025年采購合同書標準版本
- 綠色農(nóng)業(yè)可行性研究報告
- 2025年云服務(wù)業(yè)務(wù)策劃合同
- 五年級數(shù)學下冊 課前預(yù)習單(人教版)
- 地方標準-黑土區(qū)侵蝕溝治理工程技術(shù)規(guī)范DB23-T 3763-2024
- 2024年事業(yè)單位考試(綜合管理類A類)綜合應(yīng)用能力試題及解答參考
- 2024年湖南省公務(wù)員考試《行測》真題及答案解析
- DB22T 5167-2024 市政橋梁結(jié)構(gòu)監(jiān)測系統(tǒng)運行維護與管理標準
- 烹飪賽項規(guī)程-高職組
- 哲學與人生第一課 時代精神1.2
- 2024天津經(jīng)濟技術(shù)開發(fā)區(qū)管委會事業(yè)單位招聘37人歷年高頻難、易錯點500題模擬試題附帶答案詳解
- 臨床常見操作-灌腸
- GB/T 44264-2024光伏組件清潔機器人通用技術(shù)條件
- 2024工程用鋼絲環(huán)形網(wǎng)
評論
0/150
提交評論