Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:examples:setup:linux [2010/03/31 08:41] – mikk.leini | en:examples:setup:linux [2020/07/20 09:00] (current) – created - external edit 127.0.0.1 |
---|
sudo apt-get install gcc-avr avrdude avr-libc | sudo apt-get install gcc-avr avrdude avr-libc |
| |
or graphical installation software (such as Ubuntu software center or Synaptic packetmanager). | or graphical installation software (such as Ubuntu software center or Synaptic packet manager). |
| |
**2. Homelab library** | **2. HomeLab library** |
| |
The library simplifies the writing of program code, since lower-level functions are ready-made. Visit the Homelab website and download the file named //Homeland library vX.X.run//, where XX represents the version number. Run the following command to install the library: | The library simplifies the writing of program code, since lower-level functions are ready-made. Visit the HomeLab website and download the file named //Homelab library vX.X.run//, where XX represents the version number. Run the following command to install the library: |
| |
sudo sh homelab_library_vX.X.run | sudo sh homelab_library_vX.X.run |
sudo dpkg -i kontrollerlab*.deb | sudo dpkg -i kontrollerlab*.deb |
| |
If you have problems with packet dependencies, run the command, which installs the missing packages: | If you have problems with packet dependencies, run the command which installs the missing packages: |
| |
apt-get install –f | apt-get install –f |
===== Creating a new project ===== | ===== Creating a new project ===== |
| |
AVR programmi kirjutamiseks tuleb luua uus projekt, mis tüüpiliselt sisaldab endas mitmeid erinevaid faile: programmikoodi(e), päisefaile, kompileeritud programmi jne. Selleks, et projektid oleks korrektselt eristatavad, tuleks iga projekti jaoks luua uus kataloog (seda võimalust pakub ka uue projekti loomise abimees). | To write an AVR program, a project must be created which contains all the necessary files: source codes, header files, compiled program, etc. To clearly seperate projects, a folder for each project should be made (this option is also given by the project wizard). |
| |
Uue projekti loomiseks järgi järgmisi samme: | To create a project follow the steps: |
| |
**1.** Avada KontrollerLab (//Rakendused -> Programmeerimine -> KontrollerLab//) ning valida ülevalt menüüst //File -> New -> New project//. Avaneb aken, kus tuleb määrata projekti asukoht ning //Location//-väljale kirjutada projektifaili nimi. Toodud näites on loodud eraldi kataloog //../Homelab/blinkingLED///, kus hoitakse kõik näiteprogrammi (vilkuva LED) jaoks loodavad failid eraldi. | **1.** Open KontrollerLab (//Applications -> Programming -> KontrollerLab//) and start a new project from the //File -> New -> New project// menu . A window opens where the project location must be specified. In this example the locations is //../Homelab/blinkingLED///. |
| |
{{ :kit:004_new_project_kontrollerlab.png?500 |}} | {{ :kit:004_new_project_kontrollerlab.png?500 |}} |
| |
**2.** Kuna projekt on esialgu tühi, siis tuleb sellele juurde lisada C-fail, kuhu koodi saaks kirjutada. Valida menüü //File -> New -> New//. Avaneb faili lisamise aken, kus valida //C source// ja määrata faili nimi. | **2.** The project must have at least one C file where to write the program code. Files can be added from the //File -> New -> New// menu. In the opening window, select //C source// as a file type and specify the name of the file. |
| |
{{ :kit:005_new_file_kontrollerlab.png?500 |}} | {{ :kit:005_new_file_kontrollerlab.png?500 |}} |
| |
**3.** Seadistada KontrollerLabi projekt vastavalt kodulabori riistvarale. Valida menüü //Project -> Configure Project//, mispeale kuvatakse projekti seadistamise aken avatuna //Common//-kaardil. Määrata protsessoriks (CPU) ATmega128, taktsageduseks (clock) 14745600,0 Hz ning loodavate HEX ja MAP failide nimed. Vajutades nuppu //Set as default//, määrab see hetkeseadistused KontrollerLabis ka kõikide edaspidi loodavate projektide seadistusteks. Kuna sõltumata projektist jääb kodulabori riistvara samaks, siis on mõttekas määratagi sisestatud parameetrid vaikimisi parameetriteks. Samas jäävad ka KontrollerLabi poolt loodavate väljundfailide (HEX, MAP) nimed samaks. Siinkohal on kaks võimalust: igas projektis muuta HEX faili nime või panna mingi universaalsem nimi (nt out.hex), mis sobiks kõikidele projektidele. Hetkel on võetud teine variant, nii et projekti vahetamisel ei pea väljundfailide nimesid muutma. | **3.** Next, the project must be configured for HomeLab kit. From the //Project -> Configure Project// menu open the configurations window and select //Common// tab. CPU type should be ATmega128 and the clock should be 14745600,0 Hz. Also the names of the HEX and MAP files should be specified. Pressing a //Set as default// button makes these configurations as a default for new projects. This is reasonable when working only with HomeLab AVR microcontroller. As the HEX and MAP files are also stored as a default it is recommended to use some general name for them, for example "out.hex". |
| |
NB! Kuna KontrollerLab programmis ei saa korrektselt teeki lisada // Linker // kaardil, siis tuleb Kodulabori teegi lisamine seadistada siin, kirjutades map faili nime taha // -lhomelab //. | NB! As the HomeLab library can not be added on the //Linker// configuration tab, the command "-lhomelab" must be added behind the name of the MAP file. |
| |
{{ :kit:006_project_conf_common.png?500 |}} | {{ :kit:006_project_conf_common.png?500 |}} |
| |
//Compiler// kaardil seadistada kompilaatori sätted, nagu näidatud juuresoleval pildil. Enne //OK// vajutamist määrata ka siin sisestatud parameetrid vaikimisi säteteks. | Apply settings on the //Compiler// tab as shown on the following screenshot. Before pressing //OK// set compiler configurations also as a default. |
| |
{{ :kit:007_project_conf_compiler.png?500 |}} | {{ :kit:007_project_conf_compiler.png?500 |}} |
| |
**4.** Seadistada programmaatori sätted, valides menüü //Project -> Configure Programmer//. //Choose Programmer//-kaardil valida AVRDUDE ning AVR DUDE kaardil määrata programmaatori tüübiks //jtagmkI// ja ühendusliideseks eelnevalt leitud port ///dev/ttyUSBx// (vt programmaatori peatükki). Määrata ka siin seadistatud parameetrid vaikimisi säteteks. | **4.** Configure the programmer by opening the configurations window from the //Project -> Configure Programmer// menu. Choose "AVRDUDE" as a programmer. On the "AVRDUDE" tab set the programmer type to //jtagmkI// and connection port to ///dev/ttyUSBx// (where "x" is the port index). Set these configuration settings also as a default. |
| |
{{ :kit:008_programmer_conf.png?500 |}} | {{ :kit:008_programmer_conf.png?500 |}} |
| |
**5.** Seadistada tekstiredaktori sätted nii, et tabulaatorit tõlgendataks 4 tühikuna. See on vajalik, kui juhtutakse lähtefaili avama mõne muu tekstiredaktoriga, mis tõlgendab tabulaatorit teisiti kui KontrollerLab. Sel juhul võib koodi liigendus muutuda, nii et inimese jaoks on kood raskesti jälgitav. Selleks, et seda ei juhtu, valida menüü //Settings -> Configure Editor// ja avanenud aknas vasakult Editing. Märgi linnuke kasti "Insert spaces instead of tabulators" sisse. Samuti määra tabulaatori laiuseks 4 tühikut. | **5.** At last, place the windows in the KontrollerLab as it is more convenient and get ready to write your first program. |
| |
{{ :kit:009_editor_conf.png?500 |}} | |
| |
**6.** Seadista avanenud alamaknad KontrollerLabis oma käe järgi ning kirjuta mingi lihtne programm keskkonna testimiseks. Järgnevas alampeatükis on näitena toodud vilkuva LED programm. | |
| |
{{ :kit:010_kontrollerlab.png?500 |}} | {{ :kit:010_kontrollerlab.png?500 |}} |
| |
===== Seadistuste testimine ===== | ===== Writing and testing a program ===== |
| |
Kui arenduskeskkond on esimest korda paigaldatud ja seadistatud, on mõistlik testida, kas kõik sai tehtud õigesti. Selleks on lihtsaim viis teha üks väike programm, see ära kompileerida ja laadida kontrollerisse. | After the configurations steps are done, it is time to programm. |
| |
**1.** Ühendada programmaator ATMega128 Kontrollerimooduli plaadiga. Kontrollida, et programmaator saab ühendatud õigesse pistikusse (JTAG) ja õigetpidi (kaabel on suunatud kontrolleri plaadist eemale - vaata järgmist pilti). Pärast programmaatori ühendamist ühendada kontrolleri toide (kontrolleri plaadil peab süttima väike roheline LED). | **1.** Connect the programmer with Controller module. Double-check if the programmer is correctly connected with a JTAG socket. The cable must head away from the board (look at the picture). Now connect the power supply and check if the green LED lights on the Controller board. |
| |
{{ :kit:kit_test.jpg?500 |}} | {{ :kit:kit_test.jpg?500 |}} |
| |
**2.** Sisestada lihtne C-kood ja kompileerida see (//compile//). | **2.** Write the following program in the Kontrollerlab file editor window and compile it: |
| |
<code c> | <code c> |
int main(void) | int main(void) |
{ | { |
// Viigu PB7 seadmine väljundiks | // Set pin PB7 as an output |
DDRB = 0x80; | DDRB = 0x80; |
| |
while (true) | while (true) |
{ | { |
// Viigu PB7 inverteerimine | // Inverting pin PB7 |
PORTB ^= 0x80; | PORTB ^= 0x80; |
hw_delay_ms(500); | hw_delay_ms(500); |
</code> | </code> |
| |
[{{ :kit:011_compile_ignite.png?408 |Tööriistariba}}] | [{{ :kit:011_compile_ignite.png?408 |Toolbar}}] |
| |
Veendu, et väljundaknasse tuleb teade "File compiled successfully". Kui annab teate "Error(s) occurred: ", siis kontrollida, et koodi sisestamisel ei ole tehtud mõnd kirjaviga. | Make sure that the output window shows "File compiled successfully" message. If the "Error(s) occurred: " message is shown, check the program code for mistakes. |
| |
**3.** Koodi pealelaadimiseks valida //ignite// käsk. Kui kõik õnnestub, siis väljundaknas viimase reana annab KontrollerLab teate "Project built and uploaded successfully". Kontrolli, et punane LED hakkaks perioodiliselt vilkuma (500 ms põleb, 500 ms on kustund). | **3.** To download the program into the Controller press the //Ignite// button. After the succeful download, the "Project built and uploaded successfully" message should be shown. |
| |
Kui LED vilgub, nii nagu eespool kirjeldatud, on tarkvara paigaldatud edukalt ja esimene labor läbitud. Palju õnne! | If everything was done correctly the red LED on the Controller board should blink periodically, with 1 second interval. |
| |
===== Ujukoma-arvude kasutamine ===== | ===== Using floating-point numbers ===== |
| |
Mõnikord tekib vajadus AVR programmis kasutada ujukoma-arve. Nendega arvutamiseks ja nende esitamiseks //printf//-tüüpi funktsioonidega tuleb projekti seadistustes teha järgmised muudatused: | Sometimes it is neccessary to use floating-point numbers in program. To calculate with them and use them with //printf//-typed functions, some modifications in project configuration must be done: |
| |
**1.** Avada projekti seaded menüüst //Project -> Configure Project// ning valida //Linker// kaart. Märgistada //Linker flags// sektsioonis esimene linnuke (vaata ka juuresolevat pilti). | **1.** Open the //Project Configurations// window and the //Linker// tab. Check the first line in the //Linker flags// list (look at the picture). |
| |
{{ :kit:012_linker_fprintf.png?500 |}} | {{ :kit:012_linker_fprintf.png?500 |}} |
| |
**2.** Vajutada //OK// ja sulgeda seadete aken. | **2.** Press //OK// and close the window. |
| |